Mapster.Tool 生成映射器失败
Mapster.Tool fails generating mapper
Mapster.Tool 无法生成任何代码。
问题似乎是从 CosmosClient 派生的 class - 我从 nuget 包中得到的。
我得到这个异常:
Cannot find library: Microsoft.Azure.Cosmos.Client
Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.Azure.Cosmos.Client, Version=3.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. 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 123
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
'Microsoft.Azure.Cosmos.Client, Version=3.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
File name: 'Microsoft.Azure.Cosmos.Client, Version=3.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
当我禁用 mapster 构建目标时一切正常。
此外,Microsoft.Azure.Cosmos.Client.dll 存在于目标目录中。
太棒了..我做错了什么?
我不明白为什么 mapster 无法加载该程序集。
似乎也没有办法让 mapster 忽略 class.
这是代码。
using Mapster;
using Microsoft.Azure.Cosmos;
using System;
namespace MapsterTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
public class ApplicationDbClient : CosmosClient
{
public ApplicationDbClient() : base("ConnectinString")
{ }
}
[AdaptTo(typeof(MyModelDto)), GenerateMapper]
public class MyModel
{
public string SomeProperty { get; set; }
}
public class MyModelDto
{
public string SomeProperty { get; set; }
}
}
我的 csproj 文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mapster" Version="7.1.5" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.16.0" />
</ItemGroup>
<Target Name="Mapster" AfterTargets="AfterBuild">
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster model -a "$(TargetDir)$(ProjectName).dll"" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster extension -a "$(TargetDir)$(ProjectName).dll"" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -a "$(TargetDir)$(ProjectName).dll"" />
</Target>
<ItemGroup>
<Generated Include="**\*.g.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
<Target Name="CleanGenerated">
<Delete Files="@(Generated)" />
</Target>
</Project>
原来这是多个运行时程序集的问题。
参见 this github issue。
mapster.tool 版本 8.2.0
已修复此问题
Mapster.Tool 无法生成任何代码。
问题似乎是从 CosmosClient 派生的 class - 我从 nuget 包中得到的。
我得到这个异常:
Cannot find library: Microsoft.Azure.Cosmos.Client
Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.Azure.Cosmos.Client, Version=3.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. 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 123
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
'Microsoft.Azure.Cosmos.Client, Version=3.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
File name: 'Microsoft.Azure.Cosmos.Client, Version=3.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
当我禁用 mapster 构建目标时一切正常。
此外,Microsoft.Azure.Cosmos.Client.dll 存在于目标目录中。
太棒了..我做错了什么?
我不明白为什么 mapster 无法加载该程序集。
似乎也没有办法让 mapster 忽略 class.
这是代码。
using Mapster;
using Microsoft.Azure.Cosmos;
using System;
namespace MapsterTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
public class ApplicationDbClient : CosmosClient
{
public ApplicationDbClient() : base("ConnectinString")
{ }
}
[AdaptTo(typeof(MyModelDto)), GenerateMapper]
public class MyModel
{
public string SomeProperty { get; set; }
}
public class MyModelDto
{
public string SomeProperty { get; set; }
}
}
我的 csproj 文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mapster" Version="7.1.5" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.16.0" />
</ItemGroup>
<Target Name="Mapster" AfterTargets="AfterBuild">
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster model -a "$(TargetDir)$(ProjectName).dll"" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster extension -a "$(TargetDir)$(ProjectName).dll"" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -a "$(TargetDir)$(ProjectName).dll"" />
</Target>
<ItemGroup>
<Generated Include="**\*.g.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
<Target Name="CleanGenerated">
<Delete Files="@(Generated)" />
</Target>
</Project>
原来这是多个运行时程序集的问题。 参见 this github issue。
mapster.tool 版本 8.2.0
已修复此问题