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

NullReferenceException with FastExpressionCompiler #676

Open
christophwille opened this issue Feb 12, 2024 · 1 comment
Open

NullReferenceException with FastExpressionCompiler #676

christophwille opened this issue Feb 12, 2024 · 1 comment

Comments

@christophwille
Copy link

Sample with FastExpressionCompiler usage commented out, working as expected:

using FastExpressionCompiler;
using Mapster;

// TypeAdapterConfig.GlobalSettings.Compiler = exp => exp.CompileFast();

TypeAdapterConfig<TestClass, TestEnum>
    .NewConfig()
    .Map(dest => dest, src => src.Type == (int)TestEnum.A
       ? TestEnum.A
       : src.Type == (int)TestEnum.B
           ? TestEnum.B
           : src.Type == (int)TestEnum.C
               ? TestEnum.C
               : TestEnum.D);

var testClass = new TestClass { Type = 1 };
Console.WriteLine(testClass.Type);

var testEnum = testClass.Adapt<TestEnum>();
Console.WriteLine(testEnum);

class TestClass
{
    public int Type { get; set; }
}

enum TestEnum
{
    A = 1,
    B,
    C,
    D
}

With the line uncommented though, I get (on line var testEnum = testClass.Adapt<TestEnum>();)

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

Is this a known limitation, a problem in Mapster, a problem in FastExpressionCompiler, ...? If this is a low-level bug, do you know of a workaround? Thanks.

@dadhi
Copy link

dadhi commented Apr 22, 2024

@christophwille The issue is fixed on the FEC side and will be released with the next v4.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants