-
Notifications
You must be signed in to change notification settings - Fork 392
Description
Since upgrading Mapster.Tool from 8.4.0-pre06 to 8.4.1, any mapping that references a type from a nuget package will throw an exception:
E.g. Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Google.Protobuf, Version=3.24.3.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604'. The system cannot find the file specified.
I am using the latest version of Mapster (7.4.1-pre01). I have tested and got the exception in .Net 7 and .Net 8 projects.
I am using Google.Protobuf as an example of a nuget package and using the example type of ByteString
In the project file i have
<Target Name="Mapster" AfterTargets="AfterBuild"> <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -a "$(TargetDir)$(ProjectName).dll"" /> </Target>
My mapping configuration is:
using Mapster;
namespace MapsterToolsException;
public class MapsterConfiguration : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.ForType<ByteString, byte[]>().MapWith(d => d.ToArray());
}
}
You do not need to have any mappers defined to get the exception.
There is a workaround. Manually copying the Google.Protobuf.dll to the build folder (e.g. bin/Debug/net7.0) will eliminate the exception.