Mapster icon indicating copy to clipboard operation
Mapster copied to clipboard

Cannot find assembly path when building on Linux(Debian)

Open JoaoRuani opened this issue 4 years ago • 4 comments

Hello, I have a asp.net core 5 api using Mapster and Mapster.Tool, that's the csproj where mapster is referenced

Domain.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FluentValidation.AspNetCore" Version="10.3.0" />
    <PackageReference Include="Mapster" Version="7.2.0" />
  </ItemGroup>

  <ItemGroup>
    <Generated Include="**\*.g.cs" />
  </ItemGroup>

  <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;" />
    <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster extension -a &quot;$(TargetDir)$(ProjectName).dll&quot;" />
    <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -a &quot;$(TargetDir)$(ProjectName).dll&quot;" />
  </Target>

  <Target Name="CleanGenerated">
    <Delete Files="@(Generated)" />
  </Target>

</Project>

I'am using Mapster.Tool 8.2.

Inside Domain's project the files are organized like below

Entities Folder:

  • Users
    • User.cs -> with [AdaptTo("[name]CodeGenDto"),GenerateMapper]
    • UserValidator.cs -> FluentValidation validator

Build on windows runs as expected and the dtos are generated.

When trying to build on debian the following error occurs at the step dotnet mapster model -a &quot;$(TargetDir)$(ProjectName).dll&quot;":

Microsoft (R) Build Engine version 16.11.0+0538acc04 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored /home/joao/dpOfficer.digital.backend/dpOfficer.Api.BusinessLogic/dpOfficerApi.BusinessLogic.csproj (in 239 ms).
  Restored /home/joao/dpOfficer.digital.backend/dpOfficerApi.Infrastructure/dpOfficerApi.Infrastructure.csproj (in 239 ms).
  Restored /home/joao/dpOfficer.digital.backend/dpOfficerApi.Domain/dpOfficerApi.Domain.csproj (in 239 ms).
  Restored /home/joao/dpOfficer.digital.backend/dpOfficerApi.Api/dpOfficerApi.Api.csproj (in 247 ms).
  dpOfficerApi.Domain -> /home/joao/dpOfficer.digital.backend/dpOfficerApi.Domain/bin/Debug/net5.0/dpOfficerApi.Domain.dll
  Tool 'mapster.tool' (version '8.2.1') was restored. Available commands: dotnet-mapster

  Restore was successful.
  Cannot find assembly path: FluentValidation (type=package, version=10.3.0)
  Cannot find assembly path: FluentValidation (type=package, version=10.3.0)
  Cannot find assembly path: FluentValidation (type=package, version=10.3.0)
  Cannot find assembly path: FluentValidation (type=package, version=10.3.0)
  Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.  Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

     at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
     at System.Reflection.RuntimeModule.GetTypes()
     at System.Reflection.Assembly.GetTypes()
     at Mapster.Tool.Extensions.Scan(CodeGenerationConfig config, Assembly assembly) in D:\git\Mapster\src\Mapster.Tool\Extensions.cs:line 177
     at Mapster.Tool.Program.GenerateModels(ModelOptions opt) in D:\git\Mapster\src\Mapster.Tool\Program.cs:line 146
     at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
     at Mapster.Tool.Program.Main(String[] args) in D:\git\Mapster\src\Mapster.Tool\Program.cs:line 17
  System.IO.FileNotFoundException: Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  File name: 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'
  System.IO.FileNotFoundException: Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  File name: 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'
  System.IO.FileNotFoundException: Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  File name: 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'
  System.IO.FileNotFoundException: Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  File name: 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'
/home/joao/dpOfficer.digital.backend/dpOfficerApi.Domain/dpOfficerApi.Domain.csproj(19,5): error MSB3073: The command "dotnet mapster model -a "/home/joao/dpOfficer.digital.backend/dpOfficerApi.Domain/bin/Debug/net5.0/dpOfficerApi.Domain.dll"" exited with code 134.

Build FAILED.

/home/joao/dpOfficer.digital.backend/dpOfficerApi.Domain/dpOfficerApi.Domain.csproj(19,5): error MSB3073: The command "dotnet mapster model -a "/home/joao/dpOfficer.digital.backend/dpOfficerApi.Domain/bin/Debug/net5.0/dpOfficerApi.Domain.dll"" exited with code 134.
    0 Warning(s)
    1 Error(s)

If i remove all Validators, the project builds fine.

Any Idea of what i might be doing wrong?

Please tell me if more info is needed.

JoaoRuani avatar Aug 26 '21 01:08 JoaoRuani

@JoaoRuani Do you have an update on this issue? Did you figure it out on your end?

andrerav avatar Feb 19 '22 11:02 andrerav

@JoaoRuani Any news on this ?

Melethainiel avatar May 10 '22 13:05 Melethainiel

I believe the problem may be in the GetOutput method, in the Program class, in the Mapster.Tool

The character that separates the directory levels is informed directly in the code

        private static string GetOutput(string baseOutput, string? segment, string typeName)
        {
            var fullBasePath = Path.GetFullPath(baseOutput);
            return segment == null 
                ? Path.Combine(fullBasePath, typeName + ".g.cs") 
                : Path.Combine(fullBasePath, segment.Replace('.', '/'), typeName + ".g.cs");
        }

Replacing '/' to Path.DirectorySeparatorChar the problem should be solved and the Mapster.Tool works again for any platform

GuimoBear avatar May 24 '22 03:05 GuimoBear

I just ran into the same problem. Mapster.Tool on linux is failing.

EniacMlezi avatar Feb 14 '23 17:02 EniacMlezi