Get SecRecord work on macOS

Artur Bulakaiev 1 Reputation point
2021-04-02T15:03:33.137+00:00

Hi!
I'm trying to use SecRecord class with Xamarin for macOS.
When the app is running, I always get the Exception:
System.ArgumentNullException
Value cannot be null
Parameter name: obj

The callstack is:

<myMethod>
Security.SecRecord..ctor()
Foundation.NSMutableDictionary..ctor()
Foundation.NSDictionary..ctor
Foundation.NSObject..ctor
Foundation.NSObject.AllocIfNeeded()
ObjCRuntime.Class.GetHandle() Class.cs:134
ObjCRuntime.Class.GetClassHandle Class.cs : 181
ObjCRuntime.Class.GetClassHandle() Class.cs :151

My code looks like in example from site:

var queryRec = new SecRecord(SecKind.GenericPassword)
{
Service = "123",
Account = "1234",
};

but I've checked, it occures with any SecRecord construction.

This issue is not new, someone met it before: https://stackoverflow.com/questions/50936376/net-core-c-sharp-macos-keychain-api
But he did not find the answer.

What could I do to fix this?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
0 comments No comments
{count} votes