Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in EFCore under .NET 6 when using records with inheritance and lazy loading #26714

Closed
richardpawson opened this issue Nov 16, 2021 · 1 comment

Comments

@richardpawson
Copy link

richardpawson commented Nov 16, 2021

This bug appeared when we were upgrading a substantial existing system that uses EF Core, to .NET 6.0. The error appears as this exception:

System.TypeLoadException: 'Return type in method 'Castle.Proxies.SubRecordProxy.<Clone>$()' on type 'Castle.Proxies.SubRecordProxy' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not compatible with base type method 'EFCoreBugDemo.SubRecord.<Clone>$()'.'

We have created two separate minimal reproducible examples of the problem here: https://github.com/NakedObjectsGroup/NakedObjectsFramework/tree/master/BugDemo

Start with the EFCoreBugDemoNet6 project. Running this under VS2022 will generate the exception shown above.

Note these three specific things in the example code, all of which appear to be necessary to reproduce the bug (and all of which are necessary for our own system):

  • Use of record as an entity type
  • Use of inheritance between record types
  • Use of LazyLoadingProxies

Then try the EFCoreBugDemoNet5 example. Note that the C# code is identical to the .NET 6 example. Surprisingly:

  • If you run this .NET 5 example under VS2019 it runs OK.
  • If you run this .NET 5 example project from VS2022 you get the same error as in the .NET 6 example.

This suggests to us that the source of the problem might be in the compilation process rather than the libraries per se. It looks to us as though Roslyn is creating the hidden Clone method on a record type differently in the latest version, such that it no longer works with EF Core.

As it stands it is impossible for us to use EF Core with .NET 6 (given the three requirements above).

@roji
Copy link
Member

roji commented Nov 16, 2021

Duplicate of #26602

@roji roji marked this as a duplicate of #26602 Nov 16, 2021
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants