dadhi/FastExpressionCompiler

"Bad label content in ILGenerator" when creating through DynamicModule

aughey opened this issue · 1 comments

Using Expression.Call with an instance can generate this error when CreateType is called.

A similar issue was created: #300

I'm using Lokad.ILPack to save generated compilations to dll by using CompileFastToIL into an ILGenerator and then creating the type. For much of my code generation, this works fine. Some routines create a static method call without an instance parameter to Call, but the ones that do pass an instance parameter to call will fail.

A call made through:

var callmethod = Expression.Call(
               Expression.Constant(instance), typeof(ExpressionMethods).GetMethod("EmptyInstanceMethod")!);

it will always generate this error message. A call without that instance constant will work just fine.

Note: the resulting compiled delegate does work correctly. I am just unable to save the resulting code or generate it manually through CompileFastToIL using my own DynamicAssembly/Module.

I've tried using the current nuget version as well as the latest main branch on github.

I've created a test in a fork of FastExpressionCompiler that highlights this issue. The generated function performs correctly, but CreateType fails in two different ways depending on how it is called.

My repo

Some narrative, wrapping the call in a IfThen expression generates label errors and removing that IfThen expression creates an empty block.