icsharpcode / ILSpy

.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
21.49k stars 3.35k forks source link

Assertion Failed in StObj.CheckInvariant #1169

Closed greenozon closed 6 years ago

greenozon commented 6 years ago

version used: ILSpy version 3.2.0.3746-alpha (from appveyor builds)

Yet another assert seen After pressing "Throw" button have got this error text:

 ---> ICSharpCode.ILSpy.AssertionFailedException: 
   at ICSharpCode.ILSpy.ILSpyTraceListener.Fail(String message, String detailMessage) in offset 380
   at ICSharpCode.ILSpy.ILSpyTraceListener.Fail(String message) in offset 9
   at System.Diagnostics.TraceInternal.Fail(String message) in offset 55
   at System.Diagnostics.Debug.Assert(Boolean condition) in offset 6
   at ICSharpCode.Decompiler.IL.StObj.CheckInvariant(ILPhase phase) in offset 75
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in offset 126
   at ICSharpCode.Decompiler.IL.StLoc.CheckInvariant(ILPhase phase) in offset 8
   at ICSharpCode.Decompiler.IL.Transforms.StatementTransform.Run(Block block, BlockTransformContext context) in offset 255
   at ICSharpCode.Decompiler.IL.Block.RunTransforms(IEnumerable`1 transforms, BlockTransformContext context) in offset 69
   at ICSharpCode.Decompiler.IL.Transforms.BlockILTransform.VisitBlock(ControlFlowNode cfgNode, BlockTransformContext context) in offset 146
   at ICSharpCode.Decompiler.IL.Transforms.BlockILTransform.VisitBlock(ControlFlowNode cfgNode, BlockTransformContext context) in offset 89
   at ICSharpCode.Decompiler.IL.Transforms.BlockILTransform.Run(ILFunction function, ILTransformContext context) in offset 146
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(MethodDefinition methodDefinition, IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 365
-- continuing with outer exception (ICSharpCode.Decompiler.DecompilerException) --
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(MethodDefinition methodDefinition, IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 914
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(MethodDefinition methodDefinition, IMethod method, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 126
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.Decompile(IList`1 definitions) in offset 383
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.Decompile(IMemberDefinition[] definitions) in offset 1
   at ICSharpCode.ILSpy.CSharpLanguage.DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options) in offset 179
   at ICSharpCode.ILSpy.TreeNodes.MethodTreeNode.Decompile(Language language, ITextOutput output, DecompilationOptions options) in offset 15
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.DecompileNodes(DecompilationContext context, ITextOutput textOutput) in offset 69
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.<>c__DisplayClass33_0.<DecompileAsync>b__0() in offset 38

IL bytes:


.method public hidebysig newslot virtual 
    instance class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.Exception> ErrorReportingExceptions (
        int32 maxExceptionsToFetch
    ) cil managed 
{
    // Method begins at RVA 0xfd486
    // Code size 282 (0x11a)
    .maxstack 5
    .locals (
        [0] int32,
        [1] valuetype EBase.SE_Exception*,
        [2] int32,
        [3] valuetype EBase.SE_Exception*,
        [4] valuetype EBase.SE_Exception*,
        [5] uint64,
        [6] int32,
        [7] class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.Exception>,
        [8] class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.Exception>,
        [9] valuetype EBase.SE_Exception*,
        [10] uint32,
        [11] uint64,
        [12] uint64,
        [13] class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.Exception>,
        [14] void*,
        [15] valuetype EBase.SE_Exception*,
        [16] valuetype EBase.SE_Exception*,
        [17] valuetype EBase.SE_Exception*
    )

    .try
    {
        IL_0000: ldarg.1
        IL_0001: ldc.i4.0
        IL_0002: bgt.s IL_000c

        IL_0004: ldnull
        IL_0005: stloc.s 7
        IL_0007: leave IL_0117

        IL_000c: call int32 modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl)  '<Module>'::EBase.SE_Exception.GetLastUnhandledExceptionCount()
        IL_0011: stloc.0
        IL_0012: ldloc.0
        IL_0013: ldc.i4.0
        IL_0014: bgt.s IL_001e

        IL_0016: ldnull
        IL_0017: stloc.s 7
        IL_0019: leave IL_0117

        IL_001e: ldarg.1
        IL_001f: ldloc.0
        IL_0020: blt.s IL_0025

        IL_0022: ldloc.0
        IL_0023: br.s IL_0026

        IL_0025: ldarg.1

        IL_0026: stloc.s 6
        IL_0028: ldloc.s 6
        IL_002a: stloc.0
        IL_002b: ldloc.s 6
        IL_002d: conv.i8
        IL_002e: stloc.s 5
        IL_0030: ldloc.s 5
        IL_0032: ldc.i8 768614336404564650
        IL_003b: bgt.un.s IL_005b

        IL_003d: ldloc.s 5
        IL_003f: ldc.i4.s 24
        IL_0041: conv.i8
        IL_0042: mul
        IL_0043: stloc.s 12
        IL_0045: ldloc.s 12
        IL_0047: ldc.i8 -9
        IL_0050: bgt.un.s IL_005b

        IL_0052: ldloc.s 12
        IL_0054: ldc.i4.8
        IL_0055: conv.i8
        IL_0056: add
        IL_0057: stloc.s 11
        IL_0059: br.s IL_0066

        IL_005b: ldc.i8 -1
        IL_0064: stloc.s 11

        IL_0066: ldloc.s 11
        IL_0068: call void* modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl)  '<Module>'::'new[]'(uint64)
        IL_006d: stloc.s 4
        .try
        {
            IL_006f: ldloc.s 4
            IL_0071: brfalse.s IL_00a1

            IL_0073: ldloc.s 5
            IL_0075: conv.u4
            IL_0076: stloc.s 10
            IL_0078: ldloc.s 4
            IL_007a: ldloc.s 10
            IL_007c: stind.i4
            IL_007d: ldloc.s 4
            IL_007f: ldc.i4.8
            IL_0080: conv.i8
            IL_0081: add
            IL_0082: stloc.s 9
            IL_0084: ldloc.s 9
            IL_0086: ldc.i4.s 24
            IL_0088: conv.i8
            IL_0089: ldloc.s 10
            IL_008b: ldftn valuetype EBase.SE_Exception* modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl)  '<Module>'::'EBase.SE_Exception.{ctor}'(valuetype EBase.SE_Exception* modopt([mscorlib]System.Runtime.CompilerServices.IsConst)  modopt([mscorlib]System.Runtime.CompilerServices.IsConst) )
            IL_0091: ldftn void modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl)  '<Module>'::'EBase.SE_Exception.{dtor}'(valuetype EBase.SE_Exception* modopt([mscorlib]System.Runtime.CompilerServices.IsConst)  modopt([mscorlib]System.Runtime.CompilerServices.IsConst) )
            IL_0097: call void '<Module>'::__ehvec_ctor(void*, uint64, int32, method void *(void*), method void *(void*))
            IL_009c: ldloc.s 9
            IL_009e: stloc.3
            IL_009f: br.s IL_00a4

            IL_00a1: ldc.i4.0
            IL_00a2: conv.i8
            IL_00a3: stloc.3

            IL_00a4: ldloc.3
            IL_00a5: stloc.s 17
            IL_00a7: leave.s IL_00b1
        } // end .try
        fault
        {
            IL_00a9: ldloc.s 4
            IL_00ab: call void modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl)  '<Module>'::'delete[]'(void*)
            IL_00b0: endfinally
        } // end handler

        IL_00b1: ldloc.3
        IL_00b2: stloc.1
        IL_00b3: ldloc.3
        IL_00b4: ldloc.s 6
        IL_00b6: ldc.i4.1
        IL_00b7: call int32 modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl)  '<Module>'::EBase.SE_Exception.GetLastUnhandledExceptionsFromAUserThread(valuetype EBase.SE_Exception*, int32, bool)
        IL_00bc: stloc.0
        IL_00bd: ldloc.0
        IL_00be: newobj instance void class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.Exception>::.ctor(int32)
        IL_00c3: stloc.s 8
        IL_00c5: ldc.i4.0
        IL_00c6: stloc.2
        // loop start (head: IL_00c7)
            IL_00c7: ldloc.2
            IL_00c8: ldloc.0
            IL_00c9: bge.s IL_00f0
            .try
            {
                IL_00cb: ldloc.s 8
                IL_00cd: ldloc.2
                IL_00ce: conv.i8
                IL_00cf: ldc.i4.s 24
                IL_00d1: conv.i8
                IL_00d2: mul
                IL_00d3: ldloc.1
                IL_00d4: add
                IL_00d5: ldc.i4.0
                IL_00d6: ldstr "ErrorReportingExceptions"
                IL_00db: newobj instance void [EBaseDotNet]EBaseDotNet.SE_ExceptionDotNet::.ctor(valuetype [EBaseDotNet]EBase.SE_Exception*, bool, string)
                IL_00e0: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.Exception>::Add(!0)
                IL_00e5: leave.s IL_00ea
            } // end .try
            catch [mscorlib]System.Exception
            {
                IL_00e7: pop
                IL_00e8: leave.s IL_00ea
            } // end handler

            IL_00ea: ldloc.2
            IL_00eb: ldc.i4.1
            IL_00ec: add
            IL_00ed: stloc.2
            IL_00ee: br.s IL_00c7
        // end loop

        IL_00f0: ldloc.1
        IL_00f1: stloc.s 16
        IL_00f3: ldloc.1
        IL_00f4: stloc.s 15
        IL_00f6: ldloc.1
        IL_00f7: brfalse.s IL_0104

        IL_00f9: ldloc.1
        IL_00fa: ldc.i4.3
        IL_00fb: call void* modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl)  '<Module>'::EBase.SE_Exception.__vecDelDtor(valuetype EBase.SE_Exception* modopt([mscorlib]System.Runtime.CompilerServices.IsConst)  modopt([mscorlib]System.Runtime.CompilerServices.IsConst) , uint32)
        IL_0100: stloc.s 14
        IL_0102: br.s IL_0108

        IL_0104: ldc.i4.0
        IL_0105: conv.i8
        IL_0106: stloc.s 14

        IL_0108: ldloc.s 8
        IL_010a: stloc.s 7
        IL_010c: leave.s IL_0117
    } // end .try
    catch [mscorlib]System.Exception
    {
        IL_010e: pop
        IL_010f: ldnull
        IL_0110: stloc.s 13
        IL_0112: leave.s IL_0114
    } // end handler

    IL_0114: ldloc.s 13
    IL_0116: ret

    IL_0117: ldloc.s 7
    IL_0119: ret
} // end of method 

visual error:

assert1

siegfriedpammer commented 6 years ago

Thank you for the report! I fear this method is difficult to reassemble without additional information. Could you please do one of the following to help us:

1) Provide the full assembly + references as zip file for us to investigate 2) Provide an IL file that can be reassembled with ilasm without warnings

And one tip: If you want to include multiple lines of code in a GitHub issue, please use three backticks followed by a newline at the start of the block and three backticks (on their own line) at the end, thank you!

greenozon commented 6 years ago

It's inside the archive from #1173 BTW, it has dozen of other asserts...

Thanks for GH tip, it is very cool! appreciating your time & educational light :)

siegfriedpammer commented 6 years ago

There is no method called "ErrorReportingExceptions" in any of the assemblies you posted... at least I cannot find any...

greenozon commented 6 years ago

Here is another assembly having same assert case - ICSharpCode.Decompiler.IL.StObj.CheckInvariant(ILPhase phase)

I guess this assert is present on some mixed mode items

Error decompiling System.Void scoped_refptr<CefBrowser>::<MarshalCopy>(scoped_refptr<CefBrowser>*,scoped_refptr<CefBrowser>*)
 ---> ICSharpCode.ILSpy.AssertionFailedException: 
   at ICSharpCode.ILSpy.ILSpyTraceListener.Fail(String message, String detailMessage) in offset 380
   at ICSharpCode.ILSpy.ILSpyTraceListener.Fail(String message) in offset 9
   at System.Diagnostics.TraceInternal.Fail(String message) in offset 55
   at System.Diagnostics.Debug.Assert(Boolean condition) in offset 6
   at ICSharpCode.Decompiler.IL.StObj.CheckInvariant(ILPhase phase) in offset 75
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in offset 126
   at ICSharpCode.Decompiler.IL.StLoc.CheckInvariant(ILPhase phase) in offset 8
   at ICSharpCode.Decompiler.IL.Transforms.StatementTransform.Run(Block block, BlockTransformContext context) in offset 255
   at ICSharpCode.Decompiler.IL.Block.RunTransforms(IEnumerable`1 transforms, BlockTransformContext context) in offset 69
   at ICSharpCode.Decompiler.IL.Transforms.BlockILTransform.VisitBlock(ControlFlowNode cfgNode, BlockTransformContext context) in offset 146
   at ICSharpCode.Decompiler.IL.Transforms.BlockILTransform.Run(ILFunction function, ILTransformContext context) in offset 146
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(MethodDefinition methodDefinition, IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 420
-- continuing with outer exception (ICSharpCode.Decompiler.DecompilerException) --
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(MethodDefinition methodDefinition, IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 954
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(MethodDefinition methodDefinition, IMethod method, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 126
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(ITypeDefinition typeDef, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 696
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompileTypes(IEnumerable`1 types, DecompileRun decompileRun, ITypeResolveContext decompilationContext, SyntaxTree syntaxTree) in offset 205
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileTypes(IEnumerable`1 types) in offset 106
   at ICSharpCode.Decompiler.CSharp.WholeProjectDecompiler.<>c__DisplayClass22_0.<WriteCodeFilesInProject>b__1(IGrouping`2 file) in offset 68
   at System.Threading.Tasks.Parallel.<>c__DisplayClass17_0`1.<ForWorker>b__1() in offset 589
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask) in offset 6
   at System.Threading.Tasks.Task.<>c__DisplayClass176_0.<ExecuteSelfReplicating>b__0(Object) in offset 134

target: https://www.sendspace.com/file/ymdhfm

greenozon commented 6 years ago

Validated on version ILSpy version 4.0.0.4254-beta1

issue still present

dgrunwald commented 6 years ago

I can't reproduce this anymore; I think one of the fixes on #1195 also solved this issue.