Search code examples
xamarin.formsxamarin.iosprismremote-debugging

Prism Navigation error while performing remote build for iOS Xamarin forms


I have paired my visual studio to a virtual MAC machine, created the required keychain, and added to my project. I keep getting this error:

Prism.Navigation.NavigationException: An error occurred while resolving the page. This is most likely the result of invalid XAML or other type initialization exception --->
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: 
Exception has been thrown by the target of an invocation. ---> Microsoft.Identity.Client.MsalClientException: The application cannot access the iOS keychain for the application publisher (the TeamId is null). This is needed to enable Single Sign-On between applications of the same publisher.

I've also tried disabling the keychain in Entitlements.plist - doesn't work. Somehow it seems like a Prism navigation issue because when I eliminate that and simply navigate to a sample page, it works.

I also tried running my project on a Physical Mac, I get this:

2020-06-01 01:45:29.879475-0700 NatWest.KeepSafe.MobileApp.iOS[6277:128192] SecTaskLoadEntitlements failed error=22 cs_flags=200, pid=6277
2020-06-01 01:45:29.880109-0700 NatWest.KeepSafe.MobileApp.iOS[6277:128192] SecTaskCopyDebugDescription: NatWest.KeepSafe[6277]/0#-1 LF=0
2020-06-01 01:45:29.897634-0700 NatWest.KeepSafe.MobileApp.iOS[6277:128192] SecTaskLoadEntitlements failed error=22 cs_flags=200, pid=6277
2020-06-01 01:45:29.897992-0700 NatWest.KeepSafe.MobileApp.iOS[6277:128192] SecTaskCopyDebugDescription: NatWest.KeepSafe[6277]/0#-1 LF=0

P.S: The code runs perfectly on a physical iPhone but gives problems while running on Simulator.


Solution

  • This has nothing to do with Prism at all.. MSAL actually works just fine with Prism you can see the AP.AzureADAuth Module sample.

    The error you've posted actually tells you exactly what the issue is. You have an issue with your Entitlements that's keeping it from running on the iOS Simulator.

    For more information you'll want to check out the docs here:

    var builder = PublicClientApplicationBuilder
         .Create(ClientId)
         .WithIosKeychainSecurityGroup("com.microsoft.adalcache")
         .Build();
    

    and in your Entitlements.plist you'll want to update to something like:

    <dict>
      <key>keychain-access-groups</key>
      <array>
        <string>$(AppIdentifierPrefix)com.microsoft.adalcache</string>
      </array>
    </dict>