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

Use of delegate* throws a NRE #2196

Closed
albahari opened this issue Oct 22, 2020 · 1 comment
Closed

Use of delegate* throws a NRE #2196

albahari opened this issue Oct 22, 2020 · 1 comment
Labels

Comments

@albahari
Copy link

I appreciate that C# 9 support is still work in progress, but given that function pointers work in other contexts, I figure that this bug report might be helpful.

Steps to reproduce

  1. Decompile the following program
using System;
using System.Runtime.InteropServices;

unsafe
{
	EnumWindows(&PrintWindow, IntPtr.Zero);

	[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
	static extern int EnumWindows(delegate*<IntPtr, IntPtr, bool> hWnd, IntPtr lParam);

	static bool PrintWindow(IntPtr hWnd, IntPtr lParam) => true;
}

Error message shown

Error decompiling @06000001 <Program>$.<Main>$
in assembly "C:\Users\mail\source\repos\ConsoleApp34\ConsoleApp34\bin\Debug\net5.0\ConsoleApp34.dll"
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at ICSharpCode.Decompiler.IL.Transforms.LocalFunctionDecompiler.ReplaceReferencesToDisplayClassThis(ValueCollection localFunctions) in offset 20
   at ICSharpCode.Decompiler.IL.Transforms.LocalFunctionDecompiler.Run(ILFunction function, ILTransformContext context) in offset 113
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 542
-- continuing with outer exception (ICSharpCode.Decompiler.DecompilerException) --
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 833
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(IMethod method, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 195
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(ITypeDefinition typeDef, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 648
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.Decompile(IEnumerable`1 definitions) in offset 276
   at ICSharpCode.ILSpy.CSharpLanguage.DecompileType(ITypeDefinition type, ITextOutput output, DecompilationOptions options) in offset 37
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.DecompileNodes(DecompilationContext context, ITextOutput textOutput) in offset 124
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.<>c__DisplayClass48_0.<DecompileAsync>b__0() in offset 36

Details

  • Product in use: ILSpy version 6.2.1.6137
@albahari albahari added the Bug label Oct 22, 2020
@siegfriedpammer
Copy link
Member

Thanks for reporting this! This is actually not related to function pointers at all, but rather C# 9.0 supports "extern" local functions, the decompiler did not. This should be fixed now.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 23, 2021
ElektroKill added a commit to dnSpyEx/ILSpy that referenced this issue Aug 10, 2021
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

2 participants