Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapster Tool Mapper crashes when using MediatR (and possibly other assemblies) #513

Closed
Christoph-Wolf-Coduct opened this issue Dec 28, 2022 · 2 comments
Assignees
Labels

Comments

@Christoph-Wolf-Coduct
Copy link

PS C:\Users\Chris\source\repos\JobScrape.Backend> dotnet mapster mapper -a JobScrape.Backend\obj\Debug\net6.0\JobScrape.Backend.dll

Produces this Exception:

Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'MediatR.Contracts, Version=1.0.1.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2'. Invalid pointer (0x80004003 (E_POINTER))
Could not load file or assembly 'MediatR, Version=11.0.0.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2'. Invalid pointer (0x80004003 (E_POINTER))
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()
at Mapster.TypeAdapterConfig.<>c.b__87_0(Assembly assembly) in C:\Projects\Mapster\src\Mapster\TypeAdapterConfig.cs:line 639
at System.Linq.Enumerable.SelectArrayIterator2.MoveNext() at System.Linq.Enumerable.SelectManySingleSelectorIterator2.ToList()
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Mapster.TypeAdapterConfig.Scan(Assembly[] assemblies) in C:\Projects\Mapster\src\Mapster\TypeAdapterConfig.cs:line 639 at Mapster.Tool.Program.GenerateMappers(MapperOptions opt) in C:\Projects\Mapster\src\Mapster.Tool\Program.cs:line 65 at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult1 result, Action`1 action)
at Mapster.Tool.Program.Main(String[] args) in C:\Projects\Mapster\src\Mapster.Tool\Program.cs:line 17
System.IO.FileLoadException: Could not load file or assembly 'MediatR.Contracts, Version=1.0.1.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2'. Invalid pointer (0x80004003 (E_POINTER))
File name: 'MediatR.Contracts, Version=1.0.1.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2'
---> System.NullReferenceException: Object reference not set to an instance of an object.
at Mapster.Tool.AssemblyResolver.OnResolving(AssemblyLoadContext context, AssemblyName name) in C:\Projects\Mapster\src\Mapster.Tool\AssemblyResolver.cs:line 54
at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
System.IO.FileLoadException: Could not load file or assembly 'MediatR, Version=11.0.0.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2'. Invalid pointer (0x80004003 (E_POINTER))
File name: 'MediatR, Version=11.0.0.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2'
---> System.NullReferenceException: Object reference not set to an instance of an object.
at Mapster.Tool.AssemblyResolver.OnResolving(AssemblyLoadContext context, AssemblyName name) in C:\Projects\Mapster\src\Mapster.Tool\AssemblyResolver.cs:line 54
at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)

My Normal Setup looks like this:

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

DTOs and Extension Methods get generated on build, Mappers don't

Packages include

<PropertyGroup>
	<TargetFramework>net6.0</TargetFramework>
	<Nullable>enable</Nullable>
	<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
	<PackageReference Include="Mapster" Version="7.3.0" />
	<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
	<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
@andrerav
Copy link
Contributor

andrerav commented Jan 3, 2023

@Christoph-Wolf-Coduct Can you post some examples of the interfaces you are trying to generate mappers for?

@andrerav
Copy link
Contributor

andrerav commented Jan 7, 2023

Closing this as I assume the interface was referencing MediatoR in some way, causing Mapster attempting to load MediatoR assemblies. Let me know if this was not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants