Xamarin.Auth: FindAccountsForService throws on iOS
Version
- nuget version = 1.6.0.4
- component version =
- VisualStudio.16.Preview/16.0.0-pre.3.0+28608.199
- Xamarin.iOS and Xamarin.Mac SDK 12.6.0.16 (bc9c674)
- iOS version 12.1.4
Steps to reproduce
var accountStore = AccountStore.Create();
var accounts = accountStore.FindAccountsForService("someid");
Expected behaviour
Not throw.
Actual behaviour
Exception is thrown:
Search/Find FindAccountsForServiceAsync Object reference not set to an instance of an object
at Xamarin.Auth.KeyChainAccountStore.FindAccountsForServiceAsync (System.String serviceId) [0x0007f] in <85539ee049364f3e8d64880a4a42b589>:0
at Xamarin.Auth.KeyChainAccountStore.FindAccountsForService (System.String serviceId) [0x00000] in <85539ee049364f3e8d64880a4a42b589>:0
at ShopApp.iOS.Platform.IdentityStorage.Delete () [0x00007] in D:\Projects\shopapp-mobile\src\ShopApp.iOS\Platform\IdentityStorage.cs:117
at ShopApp.iOS.AppDelegate.CheckApplicationFirstLaunch (ShopApp.App application) [0x0001a] in D:\Projects\shopapp-mobile\src\ShopApp.iOS\AppDelegate.cs:111
at ShopApp.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00034] in D:\Projects\shopapp-mobile\src\ShopApp.iOS\AppDelegate.cs:34
Inner exception:
Object reference not set to an instance of an object
at Xamarin.Auth.KeyChainAccountStore+<>c.<.cctor>b__12_2 () [0x00042] in <85539ee049364f3e8d64880a4a42b589>:0
at System.Lazy`1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) [0x00043] in <56d44aabfc8d4a488316d98c7b91b0b0>:0
at System.Lazy`1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) [0x00022] in <56d44aabfc8d4a488316d98c7b91b0b0>:0
at System.Lazy`1[T].CreateValue () [0x00074] in <56d44aabfc8d4a488316d98c7b91b0b0>:0
at System.Lazy`1[T].get_Value () [0x0000a] in <56d44aabfc8d4a488316d98c7b91b0b0>:0
at Xamarin.Auth.KeyChainAccountStore.FindAccountsForServiceAsync (System.String serviceId) [0x00030] in <85539ee049364f3e8d64880a4a42b589>:0
I’ve tracked the issue down to https://github.com/xamarin/Xamarin.Auth/blob/b4fb1bb5c409e281c6bffad74ea8caba87805ea8/source/Core/Xamarin.Auth.XamarinIOS/AccountStore/KeyChainAccountStore.Aync.cs#L63-L69 where GetField("True") returns null.
VS bug #838824
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 14
- Comments: 78 (23 by maintainers)
@someone1984 don’t need to downgrade the VS2019, just downgrade the Xamarin.IOS version to 12.2.1.16, here is the link https://dl.xamarin.com/MonoTouch/Mac/xamarin.ios-12.2.1.16.pkg
Also here’s a migration guide to switch to SecureStorage in Xamarin.Essentials: https://github.com/xamarin/Xamarin.Auth/wiki/Migrating-from-AccountStore-to-Xamarin.Essentials-SecureStorage
Folks, we’ll take a look at this one, but the correct way forward is to switch to SecureStorage from Xamarin.Essentials as we have deprecated the AccountStore in Xamarin.Auth.
For anyone waiting for the nuget packages I was able to get around this issue by compiling some of the projects manually and at least for me using (.Net Standard, native iOS and native android) it worked just fine.
I couldn’t compile the Windows Universal ones but anyone using iOS and Android can give it a shot. Please use at your own risk though. (You have to replace both the PCL and native dll for it to work)
You can download the dlls in this link: https://drive.google.com/file/d/1dUaimw39PM_w-H0leRHPl4DZ9RBAKEHG/view?usp=sharing
Hope this temporarily helps someone.
having the same issue with the latest visual studio 2019 release
+1 to this. Seems like an issue with Xamarin.iOS SDK version 12.6 (preview). Downgrading Xamarin.iOS to version 12.2 seems to work.
No problems at all. That’s the reason we are here.
I think so. But good new. I dusted Xamarin.Auth off, upgraded nugets and everything works. I was a bit afraid of this step. I’m testing right now, so patch/fix might be out soon
Dear community I beg you for a little bit patience, due to the fact that all artifacts (nugets) must be published via CI system (rules).
And of course due to our other tasks and obligations Xamarin.Auth code is a bit stale, so I need to fix Cake scripts and create Azure DevOps Pipelines. I will add support for VS2019 later on.
Thanks for understanding.
@tipa you can hotfix the issue by downgrading the IOS SDK from 12.6 to 12.2, as others wrote before. Just download and execute (install) this: https://dl.xamarin.com/MonoTouch/Mac/xamarin.ios-12.2.1.16.pkg (578 MB) (it’s not necessary to downgrade anything else, like Visual Studio 2019, i tested this.)
@moljac thanks for working on a fix! even though Xamarin.Auth is deprecated and migrating to SecureStorage is the better long term fix, fixing Auth could give some QOL for existing projects.
+1 for now downgrading the Xamarin.IOS version to 12.2.1.16 worked
@nicolasmab 1.7.0.0 released
closing this one
1.7.0-alpha01 released.
I would also appreciate a quick hotfix for this issue as it currently blocks me from releasing an app update. Would love to migrate to SecureStorage but as previously mentioned, it won’t work with the current version
I started getting the issue after Visual Studio 2019 Update. Xcode and Xamarin are all up to date.
I am able to reproduce this on the official VS 2019 release that came out earlier today (version 8.0 build 3001) with Xamarin iOS 12.6.0.25, I am using the latest Xamarin.Auth version which is 1.6.0.4.
Exception log:
System.AggregateException: One or more errors occurred. (Search/Find FindAccountsForServiceAsync Object reference not set to an instance of an object) ---> Xamarin.Auth.AccountStoreException: Search/Find FindAccountsForServiceAsync Object reference not set to an instance of an object ---> System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.Auth.KeyChainAccountStore+<>c.<.cctor>b__12_2 () [0x00042] in <85539ee049364f3e8d64880a4a42b589>:0 at System.Lazy1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) [0x0001c] in <f6fd5b6dc94346cb9547cf7dbf9aa8b2>:0 — End of stack trace from previous location where exception was thrown —at System.LazyHelper.ThrowException () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.25/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:97 at System.Lazy
1[T].CreateValue () [0x0007e] in <f6fd5b6dc94346cb9547cf7dbf9aa8b2>:0 at System.Lazy1[T].get_Value () [0x0000a] in <f6fd5b6dc94346cb9547cf7dbf9aa8b2>:0 at Xamarin.Auth.KeyChainAccountStore.FindAccountsForServiceAsync (System.String serviceId) [0x00030] in <85539ee049364f3e8d64880a4a42b589>:0 — End of inner exception stack trace — at Xamarin.Auth.KeyChainAccountStore.FindAccountsForServiceAsync (System.String serviceId) [0x0007f] in <85539ee049364f3e8d64880a4a42b589>:0 at Xamarin.Auth.KeyChainAccountStore.FindAccountsForService (System.String serviceId) [0x00000] in <85539ee049364f3e8d64880a4a42b589>:0 `@markradacz Depending on the urgency of your needs, it might be worth manually installing it. I used @JPSiller’s manually compiled binaries, which worked great for me. It got us up and running, at least until a new version of Xamarin.Auth is release.
Thanks @JPSiller!
@moljac This delay is pretty frustrating. Please consider:
In my experience, Xamarin builds are hard enough to get working consistently on all needed platforms as it is. Long-lasting bugs like this on top of the typical headaches really detract from the appeal of the Xamarin platform for me.
Hi @moljac - Is there any update for releasing this version?
Do we have an ETA on this. This is extremely important as we cannot access our info. Help!!!
Hey folks, how do you migrate to SecureStorage if AccountStore.Create().FindAccountsForService(); throws exception? I am trying to migrate but with this crash is impossible…
Same issue here with VS 2019 Preview 4.1 SVC1 and Xamarin.iOS 12.6.0.23. Is there any workaround besides downgrading?
Thank you guys! Will you update nuget package, right?
@Janglinator
Thanks a lot. I really appreciate this, but I’m afraid it might burn a lot of your time. I’m on a plane to Redmond and am rewriting Cake scripts, so I can build on CI servers. Cake API has changed and Xamarin.Auth scripts depend on some Xamarin Cake utilities (nuget) which use old APIs so builds crash. I have to remove all those dependencies by rewriting Cake script. I hope I will finish it next week, but I cannot promise, because it is quite a lot to do and I’m assigned on other projects.
@moljac Is there anything we as a community can do to help get a release out? We depend pretty heavily on this project, and need it running as soon as we can. I’ve tried manually building it with no success.
Thanks!
Thank you @JPSiller !
@softsan, I think we need someone from the team approving the pull-request and do the release.
I was facing the issue with
FindAccountsForServicein an old project, and found the suggested fix after some debugging.While we are waiting for a release of Xamarin.Auth you can build the cfboolean-truehandle branch yourself and reference this instead of the Xamarin.Auth NuGet package.
Yes the update is available and works. Thank you!
Nuget package has been updated and it’s available. Thank you guys! Both iOS & Android versions work!
https://twitter.com/lewixlabs/status/1131194227533275137
It looks like a good pull request was created almost a month ago. That’s pretty good community help.
I’m not sure how we, the community, can help with that. Taking on “tons more” – I’m the lone developer for a startup with limited financial runway whose main product is the app. Just the one-day hit this bug smacked us with is a significant setback. “Tons more” on CI/Cake isn’t something I’m in a position to help with. Fixing this project’s CI system and releasing the nuget packages seems to like the kind of thing Microsoft should take care of for plugins of this nature.
@moljac I sympathize with that. For what it’s worth, I don’t blame you personally – Microsoft has chosen to resource Xamarin such that: (1) we lack testing so new stuff doesn’t break existing stuff, and (2) when stuff like this breaks, we can’t fix and release quickly.
In my opinion, a plugin that’s been supported and promoted by Microsoft (as @lewixlabs pointed out) should be set up such that (1) this bug would have been caught by CI, and (2) the infrastructure would be in place that when the community sends a good PR, it’s released within a week.
So, no hard feelings personally - you gotta do what you’re tasked by the machine to do. There were decisions made by others that has lead in this case to many, many hours collectively lost by the pool of resources that Xamarin is trying to serve. Fwiw, it’s not just Xamarin – it’s a cultural shift of Microsoft I see in many product areas, I understand it helps them go faster in other areas, but I hope the pendulum swings back to find some balance before too long.
@lewixlabs Hi! The solution has already been implemented, this is not a Xamarin.iOS issue but rather the Xamarin.Auth library needed to be upgraded to be compatible with the latest Xamarin.iOS.
Right now, the only thing left to do is for the Xamarin.Auth nuget package to be released so you can easily install it into your projects but per the author some scripts need to be updated so it may take a little bit more to be available.
If you really need this fix you can checkout the branch and compile the library yourself and you would be able to add the dll manually.
You can see what was implemented for the fix in here: https://github.com/xamarin/Xamarin.Auth/pull/376
@jcampana, I didn’t migrate. I am actually not sure which scenario will require you to transfer the old keys to a new app. Usually, you ship a new clean app without any old info.
What i did is install the plugin and follow the api to store, retrieve, and delete the keys.
I have same issue this morning. One solution is to downgrade vs to 2017, I think you can’t downgrade only Xamarin.iOS, if someone success, please share solution. Another solution is to use SecureStorage from Xamarin.Essentials instead Xamarin.Auth account store.