Android Pie - System.Reflection.TargetInvocationException

ArselanArselan ✭✭Member ✭✭
edited August 8 in Xamarin.Forms

Hello everyone,
I got an exception when trying to compile my Xamarin Forms app on Nexus 5X emulator (android Pie),
So the exception appears on this line below

public partial class App : Application { public static ILogger logger = DependencyService.Get<ILogManager>().GetLog();

I'm using DependencyService to get the Logging Functionality from IOS/ANDROID projects... I'm facing this problem only with android 9.0 (Pie) !!
this is the exception:

System.Reflection.TargetInvocationException Message=Exception has been thrown by the target of an invocation.

Any suggestions plz? thnx

Best Answers

Answers

  • LeonLuLeonLu Xamurai Member, Xamarin Team Xamurai

    Firstly, Update your IDE and Xamarin forms nuget to the latest.

    Please add a breakpoint in your DependencyService‘s code, to narrow down which line make the exception.

  • ArselanArselan ✭✭ Member ✭✭
    edited August 11

    @LeonLu thanks for ur answer,
    I found where the exception is coming from...

    string pathToNewFolder = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "Folder Name"); Directory.CreateDirectory(pathToNewFolder);

    Exactly when trying to create the directory !
    In my device (android 5.1) it works fine... even on android 8 !

    I already have the permissions to read/write on external storage !

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    This is the exception message:
    "Access to the path '/storage/emulated/0/Folder Name' is denied."

    thanks :)

  • ArselanArselan ✭✭ Member ✭✭

    Hey @LeonLu thanks I can now create a directory for my log files...
    But one more thing plz... Why I should enable storage permission manually (from app settings) every time I install the app... is there another solution to automatically create the folder or at least ask permisssion from the user ?

  • ArselanArselan ✭✭ Member ✭✭
    edited August 20

    @AlbertK that's what I need thanks :)

Sign In or Register to comment.