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
Using Castle Core 4.2.1, proxying the following type (or System.Security.Claims.ClaimsIdentity, if you want a more realistic example) produces a proxy class with incorrect IL:
When running PEVerify for the dynamically generated assembly, it complains about duplicate methods:
[MD]: Error: Method has a duplicate, token=0x06000004. [token:0x06000003]
[MD]: Error: Method has a duplicate, token=0x06000003. [token:0x06000004]
2 Error(s) Verifying Castle.Core\src\Castle.Core.Tests\bin\Debug\net461\CastleDynProxy2.dll
The mentioned methods belong to the generated proxy class BadSerializableProxy.
Below you'll find the two methods as ILSpy decompiles them back to C#:
The text was updated successfully, but these errors were encountered:
stakx
changed the title
Proxying incorrectly implemented [Serializable] class produces type that fails PEVerify test
Proxying certain [Serializable] classes produces proxy types that fail PEVerify test
Jun 1, 2018
I've been looking into this and there appears to be several questionable things going on here:
If the type that is to be proxied is marked [Serializable], DynamicProxy will automatically add ISerializable to the list of implemented interfaces (even if the proxied type does not implement it).
DynamicProxy will automatically create a GetObjectData method unless the type to be proxied implements ISerializable. That is, if the proxied type doesn't implement the interface but has the method, you potentially get the duplicate method problem.
When supplying its own GetObjectData, DynamicProxy uses certain default method modifiers. If there happens to be a GetObjectData method in the base type that is sealed, we get another conflict.
I also suspect that in the presence of GetObjectData in the base class, the newly auto-implemented method might not call its base. (But I haven't verified this claim yet.)
Fixing the reported issue likely implies that the whole [Serializable] code needs to be reworked. This is going to take a while so it shouldn't stop the 4.3.0 release at this time.
Using Castle Core 4.2.1, proxying the following type (or
System.Security.Claims.ClaimsIdentity
, if you want a more realistic example) produces a proxy class with incorrect IL:When running PEVerify for the dynamically generated assembly, it complains about duplicate methods:
The mentioned methods belong to the generated proxy class
BadSerializableProxy
.Below you'll find the two methods as ILSpy decompiles them back to C#:
This error does not happen if either:
[Serializable]
ISerializable
interfaceGetObjectData
is not declaredvirtual
The text was updated successfully, but these errors were encountered: