NullReferenceException with V4.X when using long?[]
KolyaNET opened this issue · 2 comments
KolyaNET commented
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)]
internal sealed class NullItemArrayFastExpressionCompilerTests
{
private sealed record ExportInfoDto(long[] Locations);
private sealed record ExportInfoModel(long?[] Locations);
private class ReportAdaptRule : TypeAdapterRule
{
internal ReportAdaptRule()
{
TypeAdapterConfig<ExportInfoModel, ExportInfoDto>
.NewConfig();
}
}
[TestCase(CompilerFlags.Default)]
[TestCase(CompilerFlags.NoInvocationLambdaInlining)]
[TestCase(CompilerFlags.EnableDelegateDebugInfo)]
[TestCase(CompilerFlags.ThrowOnNotSupportedExpression)]
public void NullItemArray(CompilerFlags compilerFlags)
{
// Arrange
var report = new ExportInfoModel(new long?[] { 1 });
TypeAdapterConfig.RulesTemplate.Add(new ReportAdaptRule());
TypeAdapterConfig.GlobalSettings.Compiler = exp => exp.CompileFast(flags: compilerFlags);
TypeAdapterConfig.GlobalSettings.Compile();
// Act
Assert.Throws<NullReferenceException>(() => report.Adapt<ExportInfoDto>());
}
}
If I change long?[] to long[] or return version 3.3.4 then the NullReferenceException will no longer occur
Similar problems: