Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICSharpCode.ILSpy.AssertionFailedException #2458

Closed
greenozon opened this issue Jul 24, 2021 · 8 comments
Closed

ICSharpCode.ILSpy.AssertionFailedException #2458

greenozon opened this issue Jul 24, 2021 · 8 comments
Labels

Comments

@greenozon
Copy link

greenozon commented Jul 24, 2021

Steps to reproduce

  1. Save project
    https://www.sendspace.com/file/5zf6aw

Error message shown

Error decompiling @06001498 ---.get_Heads
in assembly "C:\IL_errs\err111.dll"
 ---> 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.StLoc.CheckInvariant(ILPhase phase) in StLoc.cs:line 44
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.Block.CheckInvariant(ILPhase phase) in Block.cs:line 108
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.BlockContainer.CheckInvariant(ILPhase phase) in BlockContainer.cs:line 196
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.Block.CheckInvariant(ILPhase phase) in Block.cs:line 108
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.BlockContainer.CheckInvariant(ILPhase phase) in BlockContainer.cs:line 196
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.ILFunction.CheckInvariant(ILPhase phase) in ILFunction.cs:line 255
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1509
-- continuing with outer exception (ICSharpCode.Decompiler.DecompilerException) --
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1545
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(IMethod method, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1444
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.Decompile(IEnumerable`1 definitions) in CSharpDecompiler.cs:line 993
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.Decompile(EntityHandle[] definitions) in CSharpDecompiler.cs:line 950
   at ICSharpCode.ILSpy.CSharpLanguage.DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) in offset 246
   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 143
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.<>c__DisplayClass51_0.<DecompileAsync>b__0() in offset 38


Expected result:

public double[] get_Heads()
{
	double[] array = new double[this.m_heads.Count];
	for (int i = 0; i < this.m_heads.Count; i++)
	{
		array[i] = (double)(this.m_heads[i] as double);
	}
	return array;
}

Details

  • Product in use: e.g. ILSpy / ICSharpCode.Decompiler nuget package / VS extension
    ILSpy version 7.1.0.6580
    .NET version 4.8.3928.0
@siegfriedpammer
Copy link
Member

Cannot reproduce this. The current output seems correct, the isinst + unbox sequence found in the original code produces a NullReferenceException iff obj is not a double, just like (double)((obj is double) ? obj : null).

public double[] Heads
{
	get
	{
		double[] array = null;
		array = new double[m_heads.Count];
		for (int i = 0; i < m_heads.Count; i++)
		{
			ref double reference = ref array[i];
			object obj = m_heads[i];
			reference = (double)((obj is double) ? obj : null);
		}
		return array;
	}
}

@greenozon can you confirm?

@greenozon
Copy link
Author

Grabbed latest debug ILSpy, still see it
lets sync our settings?

ILSpy version 7.2.0.6660-preview1
.NET version 4.8.3928.0

C#7.3

save code:

in assembly "C:\IL_errs\err111.dll"
 ---> 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.BlockContainer.CheckInvariant(ILPhase phase) in BlockContainer.cs:line 212
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.Block.CheckInvariant(ILPhase phase) in Block.cs:line 108
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.BlockContainer.CheckInvariant(ILPhase phase) in BlockContainer.cs:line 196
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.Block.CheckInvariant(ILPhase phase) in Block.cs:line 108
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.BlockContainer.CheckInvariant(ILPhase phase) in BlockContainer.cs:line 196
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.ILFunction.CheckInvariant(ILPhase phase) in ILFunction.cs:line 255
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1550
-- continuing with outer exception (ICSharpCode.Decompiler.DecompilerException) --
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1586
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(IMethod method, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1470
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(ITypeDefinition typeDef, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1308
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompileTypes(IEnumerable`1 types, DecompileRun decompileRun, ITypeResolveContext decompilationContext, SyntaxTree syntaxTree) in CSharpDecompiler.cs:line 574
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileTypes(IEnumerable`1 types) in CSharpDecompiler.cs:line 894
   at ICSharpCode.Decompiler.CSharp.ProjectDecompiler.WholeProjectDecompiler.<>c__DisplayClass45_0.<WriteCodeFilesInProject>b__2(IGrouping`2 file) in WholeProjectDecompiler.cs:line 239
   at System.Threading.Tasks.Parallel.<>c__DisplayClass42_0`2.<PartitionerForEachWorker>b__1() in offset 713
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask) in offset 6
   at System.Threading.Tasks.Task.<>c__DisplayClass176_0.<ExecuteSelfReplicating>b__0(Object <p0>) in offset 134

err111.zip

@siegfriedpammer
Copy link
Member

Still cannot reproduce this... maybe its because I am missing the other references? The assembly you sent has many references, which I do not have access to. Maybe you can send the whole package via email? Thanks!

@greenozon
Copy link
Author

You are right!
I'm also not able to reproduce the issue on the same build after I did the View -> Options -> Reset to defaults
mystery!

but there is another element which throws exception if you search for it and then click on it
Search for AddFlushingEvent
see this output on click:

in assembly "C:\IL_errs\err111.dll"
 ---> 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.BlockContainer.CheckInvariant(ILPhase phase) in BlockContainer.cs:line 212
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.Block.CheckInvariant(ILPhase phase) in Block.cs:line 108
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.BlockContainer.CheckInvariant(ILPhase phase) in BlockContainer.cs:line 196
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.Block.CheckInvariant(ILPhase phase) in Block.cs:line 108
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.BlockContainer.CheckInvariant(ILPhase phase) in BlockContainer.cs:line 196
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.ILFunction.CheckInvariant(ILPhase phase) in ILFunction.cs:line 255
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1550
-- continuing with outer exception (ICSharpCode.Decompiler.DecompilerException) --
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1586
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(IMethod method, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1470
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.Decompile(IEnumerable`1 definitions) in CSharpDecompiler.cs:line 995
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.Decompile(EntityHandle[] definitions) in CSharpDecompiler.cs:line 952
   at ICSharpCode.ILSpy.CSharpLanguage.DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) in offset 246
   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 143
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.<>c__DisplayClass51_0.<DecompileAsync>b__0() in offset 38

@greenozon
Copy link
Author

Another elements leading to exception when navigating to it:

  • GetShouldLoadControlOverrides
  • GetShouldLoadFireDemands
  • GetShouldLoadPipeBreaks
  • GetShouldLoadPipeShutDowns
  • GetShouldLoadPowerOutages
  • GetShouldLoadSCADANormalDemandAdjustments
  • GetShouldLoadSCADAUnitDemandAdjustments
  • get_PressureEngineSuctionSideVSPControlNodeMustBeTankMessageKey
  • GetShouldLoadEPSTimeOptions

@siegfriedpammer
Copy link
Member

I think that these are all different problems, might be better to split this into multiple issues.

@siegfriedpammer
Copy link
Member

  • GetShouldLoadControlOverrides: This is a problem with our FixLoneIsInst transform: If the instruction extracted by FixLoneIsInst is part of a "special" block (container) the extraction violates our assumptions, e.g., that the switch instruction is the first instruction of the entry-point.
  • GetShouldLoadFireDemands: see above
  • GetShouldLoadPipeBreaks: see above
  • GetShouldLoadPipeShutDowns: see above
  • SCADADomainEngineAdapterImpl.GetShouldLoadSCADANormalDemandAdjustments: see above
  • SCADADomainEngineAdapterImpl.GetShouldLoadSCADAUnitDemandAdjustments: see above
  • get_PressureEngineSuctionSideVSPControlNodeMustBeTankMessageKey: same as ICSharpCode.ILSpy.AssertionFailedException #2459
  • AlabamaDomainEngineAdapterImpl.GetShouldLoadEPSTimeOptions: see above

@dgrunwald
Copy link
Member

Then that's a bug in Extract, it needs to find a valid place to extract to, or it should do nothing and return null.
It already checks for BlockKind.ControlFlow to ensure we don't extract into blocks with special semantics; but it will also need to check the BlockContainerKind.
In case we're dealing with the first instruction of the first block in a switch container, we could extract further into the switch's parent block,

ElektroKill added a commit to dnSpyEx/ILSpy that referenced this issue Nov 6, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants