Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RoamingStorage on Android/iOS gets "System.NullReferenceException: Object reference not set to an instance of an object" #57

Open
SmartmanApps opened this issue Apr 28, 2017 · 3 comments

Comments

@SmartmanApps
Copy link

Hi,

Relatively new to Xamarin. Trying PCLstorage as a quick and easy way to get text files working. Have succeeded with using LocalStorage on Android/iOS/UWP, however comes up with "System.NullReferenceException: Object reference not set to an instance of an object" if I try to use RoamingStorage on Android/iOS (it does work for UWP however). I am wanting to have user-accessible files, and I'm presuming using the RoamingStorage option is the way to do it? (LocalStorage is definitely NOT user-accessible on Android - doesn't seem to matter with UWP).

@jdillenkofer
Copy link

Hi,

i have the same problem as you.
RoamingStorage always returns null on Android and IOS.

I changed

/src/PCLStorage.FileSystem.Desktop/DesktopFileSystem.cs

public IFolder RoamingStorage
{
    get
    {
#if ANDROID || IOS
        return null;
#else
        //  SpecialFolder.ApplicationData is not app-specific, so use the Windows Forms API to get the app data path
        //var roamingAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
        var roamingAppData = System.Windows.Forms.Application.UserAppDataPath;
        return new FileSystemFolder(roamingAppData);

#endif
    }
}

to

public IFolder RoamingStorage
{
    get
    {
#if ANDROID
        var roamingAppData = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
#elif IOS
        return null;
#else
        //  SpecialFolder.ApplicationData is not app-specific, so use the Windows Forms API to get the app data path
        //var roamingAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
        var roamingAppData = System.Windows.Forms.Application.UserAppDataPath;
#endif
        return new FileSystemFolder(roamingAppData);
    }
}

and it seems to work.
Since i don't have a mac, i can't change the IOS version.
Maybe someone can come up with an IOS solution.

@SmartmanApps
Copy link
Author

Thanks, but how do I navigate to that page you have mentioned? (I haven't updated an external package before - I've been looking around, but can't see where this is, in VS2017 or in Windows) If I can find it then I can have a go at the iOS version (since I do have access to a Mac)

@xavier-rigau
Copy link

Isn't RoamingStorage the place where you put data to be stored in the 'cloud; or somewhere as part of the user profile and you expect to be restored if the user installs your app in a different machine? If so, it doesn't look to me that the https://developer.xamarin.com/api/property/Android.OS.Environment.ExternalStorageDirectory/ is the right place. Just my 2 cents,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants