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
When run with NullGuard, the code below throws a System.AccessViolationException. This is caused by invalid IL weaved by Fody, as it does not box the argument (which can be a struct) before checking it for null. The argument is only not boxed when a generic type constraint is present.
I've tested this on:
OS: Windows 10 1903 (10.0.18362)
.NET Core 3.1 and .NET Framework 4.7.2
x86 and x64
Fody 6.2.0
NullGuard.Fody 2.2.0 and 3.0.0-beta1
Other information
Exception thrown:
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Class.Generic[[Implementation, Repro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](Implementation)
at Program.Main()
IL after weaving by Fody (note the lack of boxing before btrue.s):
.methodpublic hidebysig staticvoidGeneric<(IInterface)T>(!!T implementation
) cil managed
{// Method begins at RVA 0x2074// Code size 20 (0x14).maxstack 2
IL_0000: ldarg.0
IL_0001: brtrue.s IL_0013
IL_0003: ldstr "implementation"
IL_0008: ldstr "[NullGuard] implementation is null."
IL_000d:newobj instance void [System.Runtime]System.ArgumentNullException::.ctor(string,string)IL_0012:throwIL_0013:ret}// end of method Class::Generic
If the type constraint is removed, the argument is boxed correctly:
When run with NullGuard, the code below throws a
System.AccessViolationException
. This is caused by invalid IL weaved by Fody, as it does not box the argument (which can be a struct) before checking it for null. The argument is only not boxed when a generic type constraint is present.Install
Fody
andNullGuard.Fody
, then rundotnet run --framework netcoreapp3.1
.Full solution
Configuration
I've tested this on:
OS: Windows 10 1903 (10.0.18362)
.NET Core 3.1 and .NET Framework 4.7.2
x86 and x64
Fody 6.2.0
NullGuard.Fody 2.2.0 and 3.0.0-beta1
Other information
Exception thrown:
IL after weaving by Fody (note the lack of boxing before
btrue.s
):If the type constraint is removed, the argument is boxed correctly:
The text was updated successfully, but these errors were encountered: