question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mappings cant be generated if one of mapped entity have external dependency.

See original GitHub issue

Hello, I am facing issue that mapper cant be generated when at least one of the mapped entities have any using, so any external dependency. We are corrently using Mapster:7.4.0-pre06 with MapsterTools:8.4.0-pre.6 due to .NET7 need. We have all the project in .NET7. Corrently we found one workaround and that is that we need to manually copy all the required dependencies to bin folder. Then it works.

We have following error for each dependency: (replace <myDependency> with any dependency you can imagine)

  Tool 'mapster.tool' (version '8.4.0-pre06') was restored. Available commands: dotnet-mapster
  
  Restore was successful.
  Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly '<myDependency>, Version=2.0.1.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
  
  File name: '<myDependency>, Version=2.0.1.0, Culture=neutral, PublicKeyToken=null'
     at System.ModuleHandle.ResolveType(QCallModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
     at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
     at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
     at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctorWithParameters, Boolean& isVarArg)
     at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
     at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
     at System.Attribute.GetCustomAttributes(MemberInfo element, Type attributeType, Boolean inherit)
     at System.Attribute.GetCustomAttribute(MemberInfo element, Type attributeType, Boolean inherit)
     at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](MemberInfo element)
     at Mapster.Tool.Program.GenerateMappers(MapperOptions opt) in C:\Projects\Mapster\src\Mapster.Tool\Program.cs:line 71
     at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
     at Mapster.Tool.Program.Main(String[] args) in C:\Projects\Mapster\src\Mapster.Tool\Program.cs:line 18

Issue Analytics

  • State:closed
  • Created 3 months ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
jvmletcommented, Jun 15, 2023

Something like this I think :

 <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet build -p:CopyLocalLockFileAssemblies=true" />
0reactions
Fennixxcommented, Jun 15, 2023

So how should this config looks like? We are using it now with this configuration:

<Target Name="Mapster">
    <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet build" />
    <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>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Entities not mapped after moving them into external jar ...
The EntityManagerFactory is built for scanning entities only from the jar that has a /META-INF/persistence.xml file into.
Read more >
One-Stop Guide to Mapping with MapStruct
We will notice in the generated implementation that MapStruct has automatically created an extra mapping method to convert between the entities ...
Read more >
Chapter 2. Mapping Entities
This class, which needs to be Serializable , is declared on the entity via the @IdClass annotation.
Read more >
Mapping JPA Entities into DTOs in Spring Boot Using ...
Let's see how to integrate MapStruct into a Spring Boot and Java project to map JPA entities into DTOs with no extra effort....
Read more >
Advanced table mapping - EF Core
The dependent entity type cannot use TPC mapping as the derived types wouldn't be able to map to the same table. The dependent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found