RefactorForce / StandardStorage

A direct reimplementation of PCLStorage in .NET Standard.
Microsoft Public License
9 stars 3 forks source link

Android Xamarin Forms project #1

Open RobbiewOnline opened 4 years ago

RobbiewOnline commented 4 years ago

This all works fine on iOS, but on Android when I try to access Current.LocalStorage I get an error about GetModuleFileName, this is what I invoked...

IFolder rootFolder = FileSystem.Current.LocalStorage;

But this raises an exception on Android...

UNABLE TO INITIALISE LOGS - System.EntryPointNotFoundException: GetModuleFileName assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) StandardStorage.StorageUtilities.GetModuleFileName(System.Runtime.InteropServices.HandleRef,System.Text.StringBuilder,int)
  at StandardStorage.StorageUtilities.GetModuleFileNameLongPath (System.Runtime.InteropServices.HandleRef hModule) [0x00042] in <492e9128255c4fa2885761586862f4f3>:0 
  at StandardStorage.StorageUtilities.get_ExecutablePath () [0x00021] in <492e9128255c4fa2885761586862f4f3>:0 
  at StandardStorage.StorageUtilities.GetAppFileVersionInfo () [0x00046] in <492e9128255c4fa2885761586862f4f3>:0 
  at StandardStorage.StorageUtilities.get_CompanyName () [0x00042] in <492e9128255c4fa2885761586862f4f3>:0 
  at StandardStorage.StorageUtilities.GetAppSpecificStoragePathFromBasePath (System.String basePath) [0x00000] in <492e9128255c4fa2885761586862f4f3>:0 
  at StandardStorage.FileSystem.get_LocalStorage () [0x00007] in <492e9128255c4fa2885761586862f4f3>:0 
  at MyApp.Services.Logger+<>c.<CheckInitialised>b__3_0 () [0x00024] in /Users/rob/GitHub/my-app-folder/MyApp/MyApp/Services/Logger.cs:29 

The full method for context is...

private static void CheckInitialised()
{
    if (file == null)
    {
        Task.Run(async () =>
        {
            try
            {
                IFolder rootFolder = FileSystem.Current.LocalStorage;
                IFolder folder = await rootFolder.CreateFolderAsync("logs", CreationCollisionOption.OpenIfExists);
                file = await folder.CreateFileAsync("logs.txt", CreationCollisionOption.OpenIfExists);
            } catch (Exception e)
            {
                Console.WriteLine($"UNABLE TO INITIALISE LOGS - {e}");
            }
        }).Wait();
    }
}
Other dependencies
TheFanatr commented 4 years ago

This issue occurs because it's trying to execute a function from an assembly which would only be present on Windows. I'll try to fix this soon.

DenisBalan commented 3 years ago

Same error Although new File(..) works well.

  at (wrapper managed-to-native) StandardStorage.StorageUtilities.GetModuleFileName(System.Runtime.InteropServices.HandleRef,System.Text.StringBuilder,int)
  at StandardStorage.StorageUtilities.GetModuleFileNameLongPath (System.Runtime.InteropServices.HandleRef hModule) [0x00042] in <492e9128255c4fa2885761586862f4f3>:0 
  at StandardStorage.StorageUtilities.get_ExecutablePath () [0x00021] in <492e9128255c4fa2885761586862f4f3>:0 
  at StandardStorage.StorageUtilities.GetAppFileVersionInfo () [0x00046] in <492e9128255c4fa2885761586862f4f3>:0 
  at StandardStorage.StorageUtilities.get_CompanyName () [0x00042] in <492e9128255c4fa2885761586862f4f3>:0 
  at StandardStorage.StorageUtilities.GetAppSpecificStoragePathFromBasePath (System.String basePath) [0x00000] in <492e9128255c4fa2885761586862f4f3>:0 
  at StandardStorage.FileSystem.get_LocalStorage () [0x00007] in <492e9128255c4fa2885761586862f4f3>:0 
DenisBalan commented 3 years ago

As a fix for now worth using

new Folder(Environment.GetFolderPath(Environment.SpecialFolder.Personal))