You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MissingMethodException when using new C# language features (in parameters, init-only setters, etc.) with generic methods, or with members in generic types
#1148
TL;DR: Upgrade to .NET 6+ (including Preview versions) to get your code working.
We've got quite a few reports lately of MissingMethodException happening for generic methods, or methods in generic types, when those methods make use of newer C# language features, e.g. in parameters, or init-only setters. I'm going to close all of those reports and pin this issue at the top of the issue tracker to make this info easier to find.
Some more background:
The issue is caused by a bug inside System.Reflection.Emit (dotnet/runtime#25958), which causes method signatures to be reproduced incorrectly if the original method signature happens to include a modreq, and if the method is either generic or in a generic type. Lately, the IL metadata encodings for new C# language features increasingly rely on such modreqs (see e.g. here for init-only setters, or here for in parameters), that's why they're affected by this bug.
The bad news is, because the bug is in the runtime, there's nothing we can do in Moq 4 to solve this problem. A limited workaround inside Castle DynamicProxy (the library underneath Moq) would be theoretically possible (castleproject/Core#430 (comment)) but very costly and tricky to implement, so that might not happen.
The good news is, the bug has since been fixed in .NET 6 (dotnet/runtime#40587) so once you upgrade, your code should once again work correctly.
The text was updated successfully, but these errors were encountered:
TL;DR: Upgrade to .NET 6+ (including Preview versions) to get your code working.
We've got quite a few reports lately of
MissingMethodException
happening for generic methods, or methods in generic types, when those methods make use of newer C# language features, e.g.in
parameters, orinit
-only setters. I'm going to close all of those reports and pin this issue at the top of the issue tracker to make this info easier to find.Some more background:
The issue is caused by a bug inside System.Reflection.Emit (dotnet/runtime#25958), which causes method signatures to be reproduced incorrectly if the original method signature happens to include a modreq, and if the method is either generic or in a generic type. Lately, the IL metadata encodings for new C# language features increasingly rely on such modreqs (see e.g. here for
init
-only setters, or here forin
parameters), that's why they're affected by this bug.The bad news is, because the bug is in the runtime, there's nothing we can do in Moq 4 to solve this problem. A limited workaround inside Castle DynamicProxy (the library underneath Moq) would be theoretically possible (castleproject/Core#430 (comment)) but very costly and tricky to implement, so that might not happen.
The good news is, the bug has since been fixed in .NET 6 (dotnet/runtime#40587) so once you upgrade, your code should once again work correctly.
The text was updated successfully, but these errors were encountered: