Skip to content

Creating a SecRecord with SecKind.GenericPassword Throws An InvalidCastException #23070

Open
@mlancione

Description

@mlancione

Apple platform

iOS

Framework version

net9.0-*

Affected platform version

.NET 9.0.301.1 iOS: 18.5.9199

Description

Seeing this runtime InvalidCastException trace:

Unhandled exceptionSystem.InvalidCastException: Specified cast is not valid.
at Foundation.NSMutableDictionary.LowlevelFromObjectAndKey(IntPtr obj, IntPtr key) in /Users/builder/azdo/_work/1/s/macios/src/Foundation/NSMutableDictionary.cs:line 403
at Security.SecRecord..ctor(SecKind secKind) in /Users/builder/azdo/_work/1/s/macios/src/Security/Items.cs:line 953

Steps to Reproduce

Add this to AppDelegate FinishLaunching():
var rec = new Security.SecRecord( Security.SecKind.GenericPassword );

Note that a dotnet new ios project doesn't seem to experience this so it could be a combination of csproj settings that is causing this. I have tried clearing bin/obj folders with no luck.

I can email a binlog if needed.

This is new behavior in .NET 9.0.301.1 iOS: 18.5.9199. Previous .NET iOS version was working fine.

Did you find any workaround?

Removing TrimMode partial or full seems to be a workaround:
<TrimMode Condition="'$(Configuration)' == 'Debug'">partial</TrimMode>
<TrimMode Condition="'$(Configuration)' == 'Release'">full</TrimMode>

However, this isn't a usable workaround because we require Trimming for our Release builds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    need-attentionAn issue requires our attention/response

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions