MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.3k stars 328 forks source link

System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=7.0.0.0 using code generator #543

Closed xaberue closed 1 year ago

xaberue commented 1 year ago

Hi Amazing Mapster team,

I wanted to expose you the case that I have, with which I am currently stuck and I do not quite understand the reason.

I'm trying to implement Mapster using the benefits of the code generation.

Following the documentation provided, I created the dotnet-tools file, installed mapster.tool added the required code in csproj file, I've tried with and without AfterBuild but the final result is the same. (Below code using AfterBuild )

        <ItemGroup>
                <Generated Include="**\*.g.cs" />
    </ItemGroup>
    <Target Name="CleanGenerated">
        <Delete Files="@(Generated)" />
    </Target>

    <Target Name="Mapster" AfterTargets="AfterBuild">
        <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" />
        <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster model -a &quot;$(TargetDir)$(ProjectName).dll&quot; -n Xelit3.Benchmarks.Generated" />
        <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster extension -a &quot;$(TargetDir)$(ProjectName).dll&quot; -n Xelit3.Benchmarks.Generated" />
        <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -a &quot;$(TargetDir)$(ProjectName).dll&quot; -n Xelit3.Benchmarks.Generated" />
    </Target>   

At the end, I end up always with the same issue:

File name: 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. El sistema no puede encontrar el archivo especificado.

I'm using .NET7 console project, I tried using Mapster 7.3.0 and 7.4.0-pre05, both with similar result.

I also tried specifying namespace in the model, extension and maper exec commands, same result

I'm trying to use Fluent API flavour since the POC has the models in a different assembly, similar scenario of our real world projects.

I'm sure that I'm missing something, but with the information that I can extract from the output and the similar issues reported I'm not able to progress on it.

Issues checked:

The entire code is available here to check it

Many thanks in advance for your support

stormaref commented 1 year ago

I'm facing the same issue when I'm using dotnet 7

stagep commented 1 year ago

Was the Mapster.Tool installed using the pre-release version?

dotnet tool install Mapster.Tool --version 8.4.0-pre05

I am successfully using .Net 7 with Mapster 7.4.0-pre05 and Mapster.Tool 8.4.0-pre05.

andrerav commented 1 year ago

That's correct @stagep. @Xelit3 I cloned your repo and verified that upgrading to Mapster.Tool version 8.4.0-pre06 fixes the problem.

xaberue commented 1 year ago

Sorry for the delay replying it, I left it on hold for a couple of weeks.

Yes it worked once the Mapster.Tool was installed with the pre-release version (I tried with 8.4.0-pre05 at leastand it worked perfectly fine)

Many thanks for the support!