You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. I used FastExpressionCompiler version 3.3.4 and everything worked. After updating to version 4.1.0 I started getting errors. I also use Mapster 7.4.0.
I was able to find the problem using a NUnit test
using FastExpressionCompiler;
using Mapster;
using NUnit.Framework;
namespace Garda.Unit.Tests.Mapster;
[TestFixture]
[Parallelizable(ParallelScope.Default)]
public sealed class NullReferenceExceptionFastExpressionCompilerTests
{
public sealed record AgentStatusDto
{
public int ErrorCode { get; init; }
public int CompleteTaskType { get; set; }
}
public sealed record ResulAgent(ResponseAgent Common);
public sealed record ResponseAgent(int ErrorType, int TaskType, int Code);
internal class AgentStatusDtoAdaptRule : TypeAdapterRule
{
internal AgentStatusDtoAdaptRule()
{
TypeAdapterConfig<ResulAgent, AgentStatusDto>
.NewConfig()
.Map(dst => dst.ErrorCode, src => src.Common.Code)
.AfterMapping(ToDtoMap);
}
private static void ToDtoMap(ResulAgent res, AgentStatusDto dto)
{
dto.CompleteTaskType = res.Common.TaskType switch
{
2 => 3,
_ => default
};
}
}
[TestCase(CompilerFlags.Default)]
[TestCase(CompilerFlags.NoInvocationLambdaInlining)]
public void NullReferenceException(CompilerFlags compilerFlags)
{
// Arrange
var result = new ResulAgent(new ResponseAgent(1, 2, 3));
TypeAdapterConfig.RulesTemplate.Add(new AgentStatusDtoAdaptRule());
TypeAdapterConfig.GlobalSettings.Compiler = exp => exp.CompileFast(flags: compilerFlags);
TypeAdapterConfig.GlobalSettings.Compile();
// Act
if (compilerFlags == CompilerFlags.Default)
{
Assert.Throws<NullReferenceException>(() => result.Adapt<AgentStatusDto>());
}
else
{
var resultStatus = result.Adapt<AgentStatusDto>();
// Assert
Assert.NotNull(resultStatus, nameof(resultStatus));
}
}
}
If I revert to version 3.3.4 or use the NoInvocationLambdaInlining flag the NullReferenceException will no longer be thrown.
Hello. I used FastExpressionCompiler version 3.3.4 and everything worked. After updating to version 4.1.0 I started getting errors. I also use Mapster 7.4.0.
I was able to find the problem using a NUnit test
If I revert to version 3.3.4 or use the NoInvocationLambdaInlining flag the NullReferenceException will no longer be thrown.
Similar problems:
The text was updated successfully, but these errors were encountered: