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
Prior to version 4.2.1408.619, proxies generated for a class had the same exact methods with the exact same signature as the class being proxied. This is the expected behaviour.
Starting in 4.2.1408.619, under some circumstances, some proxies might have their methods marked as virtual non-final (i.e., overridable), whereas the method of the object being proxied is in fact virtual final (i.e., sealed).
This seems like a bug to me - I'd like to get the maintainers and owners' opinions on this please.
Test Case
publicinterfaceISomeInterface{voidMethod();}publicclassConcreteClass:ISomeInterface{publicvoidMethod(){}}publicclassTest{[Fact]publicvoidSomeTest(){//print the SUT's methods
Console.WriteLine("----- Printing the ConcreteClass's methods -----");
PrintMethod(typeof(ConcreteClass));//print the proxy's methods
Console.WriteLine("----- Printing the proxy's methods -----");varmock=newMock<ConcreteClass>();
PrintMethod(mock.Object.GetType());}publicvoidPrintMethod(Typetype){varmethod= type.GetMethod("Method");
Console.WriteLine("Declaring Type: "+ method.DeclaringType);
Console.WriteLine("IsVirtual: "+ method.IsVirtual);
Console.WriteLine("IsFinal: "+ method.IsFinal);}}
Output using Moq 4.2.1402.2112 (correct and works as expected):
Output using Moq 4.2.1408.619 (unexpected output):
----- Printing the ConcreteClass's methods -----
Declaring Type: Ploeh.AutoFixture.AutoMoq.UnitTest.ConcreteClass
IsVirtual: True
IsFinal: True
----- Printing the proxy's methods -----
Declaring Type: Castle.Proxies.ConcreteClassProxy <------------- I have no idea why this isn't ConcreteClass
IsVirtual: True
IsFinal: False <------------- should be True
If this bug was introduced by Castle's Dynamic Proxy and not Moq, let me know and I'll report this on their page.
If this is not a bug and is actually by design, it seems like a breaking change to me - the signature of a public method of a public type was changed.
PS: FYI, the same does not happen when ISomeInterface is a class instead of an interface, and Method is marked as virtual in the base class and sealed override in the derived class.
The text was updated successfully, but these errors were encountered:
Sorry about the tagging. This sounds like a DynamicProxy-related problem, however it seems that both Moq versions that you mentioned used the same DynamicProxy version (3.2.0).
Prior to version 4.2.1408.619, proxies generated for a class had the same exact methods with the exact same signature as the class being proxied. This is the expected behaviour.
Starting in 4.2.1408.619, under some circumstances, some proxies might have their methods marked as virtual non-final (i.e., overridable), whereas the method of the object being proxied is in fact virtual final (i.e., sealed).
This seems like a bug to me - I'd like to get the maintainers and owners' opinions on this please.
Test Case
Output using Moq 4.2.1402.2112 (correct and works as expected):
Output using Moq 4.2.1408.619 (unexpected output):
If this bug was introduced by Castle's Dynamic Proxy and not Moq, let me know and I'll report this on their page.
If this is not a bug and is actually by design, it seems like a breaking change to me - the signature of a public method of a public type was changed.
For a bit more context, see this issue on AutoFixture GitHub page.
PS: FYI, the same does not happen when
ISomeInterface
is a class instead of an interface, andMethod
is marked asvirtual
in the base class andsealed override
in the derived class.The text was updated successfully, but these errors were encountered: