Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 17, 2025

Obsolete IdentityUserContext.SchemaVersion property

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Obsolete unused SchemaVersion property in IdentityUserContext

Description

The IdentityUserContext.SchemaVersion property is not used by IdentityUserContext itself. OnModelCreating directly calls GetStoreOptions()?.SchemaVersion instead of reading this property, making it misleading.

Changes:

  • Marked SchemaVersion property as [Obsolete] with a message directing users to configure via IdentityOptions.Stores.SchemaVersion
  • Updated test code in VersionTestDbContext.cs to use the correct pattern instead of the obsolete property
// Before (obsolete pattern)
if (SchemaVersion >= new Version(3, 0))
{
    // ...
}

// After (correct pattern)
var storeOptions = this.GetService<IOptions<IdentityOptions>>()?.Value?.Stores;
var schemaVersion = storeOptions?.SchemaVersion ?? IdentitySchemaVersions.Version1;
if (schemaVersion >= new Version(3, 0))
{
    // ...
}

Fixes #59880

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.jsdelivr.net
    • Triggering command: /home/REDACTED/work/aspnetcore/aspnetcore/.dotnet/dotnet exec --depsfile /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/bin/Microsoft.AspNetCore.Identity.Test/Debug/net10.0/Microsoft.AspNetCore.Identity.Test.deps.json --runtimeconfig /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/bin/Microsoft.AspNetCore.Identity.Test/Debug/net10.0/Microsoft.AspNetCore.Identity.Test.runtimeconfig.json /home/REDACTED/.nuget/packages/xunit.REDACTED.console/2.9.2/tools/netcoreapp2.0/xunit.console.dll /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/bin/Microsoft.AspNetCore.Identity.Test/Debug/net10.0/Microsoft.AspNetCore.Identity.Test.dll -noautoreporters -xml /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/TestResults/Debug/Microsoft.AspNetCore.Identity.Test_net10.0_x64.xml -html /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/TestResults/Debug/Microsoft.AspNetCore.Identity.Test_net10.0_x64.html -notrait Quarantined=true -nocolor (dns block)
  • cdnjs.cloudflare.com
    • Triggering command: /home/REDACTED/work/aspnetcore/aspnetcore/.dotnet/dotnet exec --depsfile /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/bin/Microsoft.AspNetCore.Identity.Test/Debug/net10.0/Microsoft.AspNetCore.Identity.Test.deps.json --runtimeconfig /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/bin/Microsoft.AspNetCore.Identity.Test/Debug/net10.0/Microsoft.AspNetCore.Identity.Test.runtimeconfig.json /home/REDACTED/.nuget/packages/xunit.REDACTED.console/2.9.2/tools/netcoreapp2.0/xunit.console.dll /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/bin/Microsoft.AspNetCore.Identity.Test/Debug/net10.0/Microsoft.AspNetCore.Identity.Test.dll -noautoreporters -xml /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/TestResults/Debug/Microsoft.AspNetCore.Identity.Test_net10.0_x64.xml -html /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/TestResults/Debug/Microsoft.AspNetCore.Identity.Test_net10.0_x64.html -notrait Quarantined=true -nocolor (dns block)
  • stackpath.bootstrapcdn.com
    • Triggering command: /home/REDACTED/work/aspnetcore/aspnetcore/.dotnet/dotnet exec --depsfile /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/bin/Microsoft.AspNetCore.Identity.Test/Debug/net10.0/Microsoft.AspNetCore.Identity.Test.deps.json --runtimeconfig /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/bin/Microsoft.AspNetCore.Identity.Test/Debug/net10.0/Microsoft.AspNetCore.Identity.Test.runtimeconfig.json /home/REDACTED/.nuget/packages/xunit.REDACTED.console/2.9.2/tools/netcoreapp2.0/xunit.console.dll /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/bin/Microsoft.AspNetCore.Identity.Test/Debug/net10.0/Microsoft.AspNetCore.Identity.Test.dll -noautoreporters -xml /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/TestResults/Debug/Microsoft.AspNetCore.Identity.Test_net10.0_x64.xml -html /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/TestResults/Debug/Microsoft.AspNetCore.Identity.Test_net10.0_x64.html -notrait Quarantined=true -nocolor (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Error if I query the DbSet of IdentityDbContext.UserPasskeys</issue_title>
<issue_description>### Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

If I create a IdentityDbContext and try to read the DBSet for the UserPasskeys I get this error

System.InvalidOperationException : Cannot create a DbSet for 'IdentityUserPasskey<int>' because this type is not included in the model for the context.

  Stack Trace: 
InternalDbSet`1.get_EntityType()
InternalDbSet`1.CheckState()
InternalDbSet`1.get_EntityQueryable()
IEnumerable<TEntity>.GetEnumerator()
List`1.ctor(IEnumerable`1 collection)
Enumerable.ToList[TSource](IEnumerable`1 source)
UnitTest1.Test1() line 17
MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

All the other entities can be read

Expected Behavior

I would expect to read the query

Steps To Reproduce

I created a test project in the https://github.com/luizfbicalho/error-passkey-aspnet-identity

tried with 3 different scenarios , one test for each, and one test that works for the others dbSets

Exceptions (if any)

System.InvalidOperationException : Cannot create a DbSet for 'IdentityUserPasskey' because this type is not included in the model for the context.

Stack Trace: 
InternalDbSet1.get_EntityType() InternalDbSet1.CheckState()
InternalDbSet1.get_EntityQueryable() IEnumerable<TEntity>.GetEnumerator() List1.ctor(IEnumerable1 collection) Enumerable.ToList[TSource](IEnumerable1 source)
UnitTest1.Test1() line 17
MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

.NET Version

.NET 10

Anything else?

No response</issue_description>

<agent_instructions>Obsolete IdentityUserContext.SchemaVersion</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@MackinnonBuck Thanks for reaching out, @luizfbicalho.

The intended way to add passkeys to the model is to specify StoreOptions.SchemaVersion to IdentitySchemaVersions.Version3. See our docs for more info on how to do this.

If you want to set the schema version from within your unit tests, you'll need to call DbContextOptionsBuilder.UseApplicationServiceProvider() and pass in a service provider with an IOptions<IdentityOptions> specified with the correct schema version.

Alternatively, overriding OnModelCreating() as you described above will also work.

We should consider obsoleting the IdentityUserContext.SchemaVersion property, as it doesn't seem to be read by other methods defined in IdentityUserContext.</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@dotnet-policy-service
Copy link
Contributor

Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo!

Copilot AI changed the title [WIP] Fix error querying IdentityDbContext.UserPasskeys Obsolete IdentityUserContext.SchemaVersion property Nov 17, 2025
Copilot AI requested a review from MackinnonBuck November 17, 2025 18:56
Copilot finished work on behalf of MackinnonBuck November 17, 2025 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error if I query the DbSet of IdentityDbContext.UserPasskeys

2 participants