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

[6.0.2] Avoid proxying Clone methods on record types #27125

Merged
merged 1 commit into from
Jan 7, 2022

Conversation

ajcvickers
Copy link
Member

Fixes #26602

Description

The C# compiler changed the emit strategy for records in .NET 6 to take advantage of covariant returns. The Clone method now always has a return type that matches the containing type. Castle dynamic proxies throws when attempting to create a proxy for such types. This means EF Core lazy-loading and change-tracking proxies are broken for any record with a base type.

An bug has been filed on Castle proxies (castleproject/Core#601), which is the correct place to ultimately fix this issue. However, since EF Core never needs to override the Clone method for its proxies, the fix here simply excludes the Clone method from the proxies we create.

Customer impact

Proxies for records with base types cannot be used. Reported by multiple customers. No known workaround.

How found

Multiple customer reports on 6.0.

Regression

Yes, From 5.0

Testing

Added unit and functional tests for records with base types.

Risk

Very low; Clone methods are never used by EF proxies. Also added quirk to revert to previous behavior.

Fixes #26602

**Description**

The C# compiler changed the emit strategy for records in .NET 6 to take advantage of covariant returns. The Clone method now always has a return type that matches the containing type. Castle dynamic proxies throws when attempting to create a proxy for such types. This means EF Core lazy-loading and change-tracking proxies are broken for any record with a base type.

An bug has been filed on Castle proxies (castleproject/Core#601), which is the correct place to ultimately fix this issue. However, since EF Core never needs to override the Clone method for its proxies, the fix here simply excludes the Clone method from the proxies we create.

**Customer impact**

Proxies for records with base types cannot be used. Reported by multiple customers. No known workaround.

How found

Multiple customer reports on 6.0.

Regression

Yes, From 5.0

Testing

Added unit and functional tests for records with base types.

Risk

Very low; Clone methods are never used by EF proxies. Also added quirk to revert to previous behavior.
@ajcvickers ajcvickers requested a review from a team January 6, 2022 14:17
@ajcvickers ajcvickers added this to the 6.0.x milestone Jan 6, 2022
@leecow leecow modified the milestones: 6.0.x, 6.0.2 Jan 6, 2022
@ajcvickers ajcvickers merged commit bbbd2c8 into release/6.0 Jan 7, 2022
@ajcvickers ajcvickers deleted the ProxiesByProxy0106b branch January 7, 2022 08:28
@ajcvickers ajcvickers removed this from the 6.0.2 milestone Jan 7, 2022
@ajcvickers ajcvickers changed the title [release/6.0] Avoid proxying Clone methods on record types [6.0.2] Avoid proxying Clone methods on record types Jan 13, 2022
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.

3 participants