question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullReferenceException in iOS only

See original GitHub issue

I am getting a runtime error: System.NullReferenceException: Object reference not set to an instance of an object When i click on Sign in button. the error is occurring at this step (PCA is null):

PCA = new PublicClientApplication(ClientID)
                {
                    RedirectUri = $"msal{App.ClientID}://auth",
                };  

Complete Error:

System.NullReferenceException: Object reference not set to an instance of an object at Microsoft.Identity.Core.TokenCacheAccessor.GetTeamId () [0x0003f] in <772466974f16475694ca93a5f7a70108>:0 at Microsoft.Identity.Core.TokenCacheAccessor..ctor () [0x0001c] in <772466974f16475694ca93a5f7a70108>:0 at Microsoft.Identity.Core.Telemetry.TelemetryTokenCacheAccessor..ctor () [0x00000] in <772466974f16475694ca93a5f7a70108>:0 at Microsoft.Identity.Client.TokenCache..ctor () [0x00000] in <772466974f16475694ca93a5f7a70108>:0 at Microsoft.Identity.Client.PublicClientApplication..ctor (System.String clientId, System.String authority) [0x00014] in <772466974f16475694ca93a5f7a70108>:0 at Microsoft.Identity.Client.PublicClientApplication..ctor (System.String clientId) [0x00000] in <772466974f16475694ca93a5f7a70108>:0 at UserDetailsClient.App..ctor () [0x00009] in Downloads/active-directory-xamarin-native-v2-master/UserDetailsClient/UserDetailsClient/App.cs:30

Only iOS is giving me this . Android Version is working fine. I am using Visual Studio for Mac

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
tipacommented, Sep 27, 2018

I was able to worked around the issue with the following hack:

var whenUnlockedAccessRecord = new SecRecord(SecKind.GenericPassword) { Service = "", Account = "teamIDHint" };
var match = SecKeyChain.QueryAsRecord(whenUnlockedAccessRecord, out SecStatusCode resultCode);
if (resultCode == SecStatusCode.Success && match.Accessible != SecAccessible.Always)
{
    SecKeyChain.Remove(whenUnlockedAccessRecord);
}

if (match?.Accessible != SecAccessible.Always)
{
    var alwaysAccessRecord = new SecRecord(SecKind.GenericPassword) { Service = "", Account = "teamIDHint", Accessible = SecAccessible.Always };
    SecKeyChain.Add(alwaysAccessRecord);
}

Speaking of hack: I must say that the GetTeamId() method looks pretty hacky too 😛

2reactions
ali-h2010commented, Oct 4, 2018

@jennyf19 I tested and it works out of the box as expected. Great work

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code causes NullReferenceException only on iOS device
This code cause a null reference exception only on a iOS device. No idea how to debug it. XCode says that the null...
Read more >
Null Reference Exception on iOS build only
Hey there! Seems like the levels I have selected for "Scenes In Build" are having issues getting stored when building for iOS.
Read more >
Null Reference when starting capture on iOS when using ...
When trying to start capture on an iOS build I get the following Null Reference: NullReferenceException: Object reference not set to an instance...
Read more >
NullReferenceException is thrown on an attempt to ...
Hi,. I've really strange issue only happening in iOS - if I add TabView to the ContentPage then it crashes when navigating back....
Read more >
Null Reference Exceptions
Null Reference Exceptions. A NullReferenceException happens when you try to access a reference variable that isn't referencing any object.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found