locked
Problem with casting back an array object?

    Question

  • Hi,

    I want writing some localsettings with an Platform::Array<String^>^ Like:

    Platform::Array<String^>^ settings = ref new Platform::Array<String^>(3);
    settings[0] = "123";
    settings[1] = "1234";
    settings[2] = "12345";
    ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
    auto values = localSettings->Values;
    values->Insert("Settings", settings);


    And then i read the localSettings and cast it back to Platform::Array<String^>^ Like:

    ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
    auto values = localSettings->Values;
    
    Platform::Array<String^>^ settings = safe_cast<Platform::Array<String^>^>(localSettings->Values->Lookup("Settings"));

    There occours an violation reading exception in the "vccorlib.h" 's inline function 

    template <typename __TArg>
    inline __TArg* WriteOnlyArray<__TArg, 1>::AllocateAndCopyElements(const __TArg* __srcArg, unsigned int __countArg)
    {
    __TArg* __dest = AllocateAndZeroInitialize(__countArg);
    for (unsigned int __i = 0; __i < __countArg; ++__i)
    {
    __dest[__i] = __srcArg[__i];
    }
    return __dest;
    }

    the __countArg perimeters passed with some garbage data

    Any ideas of what's wrong with my code?

    Thanks


    • Edited by ReiFukai Friday, January 25, 2013 2:46 PM
    Friday, January 25, 2013 2:42 PM

Answers

All replies