FastExpressionCompiler: InvalidOperationException in the Mapster

System.InvalidProgramException: ‘Common Language Runtime detected an invalid program.’

StackTrace

   at Mapster.TypeAdapter.Adapt[TSource,TDestination](TSource source) in D:\Dev\Mapster\src\Mapster\TypeAdapter.cs:line 55
   at Benchmark.TestAdaptHelper.ConfigureMapster(Customer customerInstance, MapsterCompilerType type) in D:\Dev\Mapster\src\Benchmark\TestAdaptHelper.cs:line 114
   at Benchmark.Benchmarks.TestComplexTypes.SetupFec() in D:\Dev\Mapster\src\Benchmark\Benchmarks\TestComplexTypes.cs:line 70
   at Benchmark.Program.Main(String[] args) in D:\Dev\Mapster\src\Benchmark\Program.cs:line 22

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21 (13 by maintainers)

Commits related to this issue

Most upvoted comments

@cojocaru-dragos-alexandru

I have run the tests from the Mapster with the FEC 3.2 and everything is passing: image

So it would be hard to impossible to figure out until I have the failing sample/test.

Found the cause of Dictionary tests failing - the V3 has added the support for the ListInit expression (V2 used the fallback) but there is a bug in emitting the ElementInit for the Dictionary. Fixing now.

Hey, good to join. I created fec branch (https://github.com/MapsterMapper/Mapster/tree/fec). I tested unit tests, 10 cases failed. Most seemed to related to dictionary.

Just wondering, for default usage, Should we expect FEC to fallback to original lambda.Compile or not? In most cases, we could enjoy performance boost. In corner cases, app still working.

I checked earlier today, and the example I provided for LINQPad runs with no exception. 😄

I don’t think this problem has been fixed, even up to 3.0.4. I just tried the following short snippet in LINQPad using FastExpressionCompiler 3.0.4 and Mapster 7.1.5:

class Test
{
	public string? TestString { get; set; }
}

void Main()
{
	TypeAdapterConfig.GlobalSettings.Compiler = exp => exp.CompileFast();
	_ = TypeAdapterConfig.GlobalSettings.Default.MapToConstructor(true).PreserveReference(true);
	
	var test1 = new Test()
	{
		TestString = "Test"
	}.Dump();
	var test2 = test1.Adapt<Test>().Dump();
}

I get an InvalidProgramException with the message Common Language Runtime detected an invalid program. The stack trace is:

   at (ArrayClosure , Object )
   at Mapster.TypeAdapter.Adapt[TDestination](Object source, TypeAdapterConfig config)
   at Mapster.TypeAdapter.Adapt[TDestination](Object source)
   at UserQuery.Main()

Please reopen this and look into it. I have had to temporarily exclude using FEC in my programs using Mapster as a result of this.