MapsterMapper / Mapster

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

Mapster.Tool crashes when using WPF #467

Open Irme opened 2 years ago

Irme commented 2 years ago

I am trying to generate a mapper using Mapster.Tool but it crashes as soon as WPF is added as a dependency.

Creating a simple console app for .NET6.0-windows works fine, I can generate DTOs and Mappers as I need. Whenever I use essentially the same code, but add it to a WPF project the mapster build targets cause an error, and no code is generated.

I've uploade a MWE to github, and the error is pasted below


Build started...
1>------ Build started: Project: MappingTestWPFApp, Configuration: Debug Any CPU ------
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
1>MappingTestWPFApp -> C:\Users\irme\source\repos\MappingTesting\MappingTestWPFApp\bin\Debug\net6.0-windows\MappingTestWPFApp.dll
1>Tool 'mapster.tool' (version '8.3.0') was restored. Available commands: dotnet-mapster
1>
1>Restore was successful.
1>Cannot find library: PresentationFramework
1>Cannot find library: PresentationFramework
1>Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
1>Could not load file or assembly 'PresentationFramework, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
1>Could not load file or assembly 'PresentationFramework, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
1>   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
1>   at System.Reflection.Assembly.GetTypes()
1>   at Mapster.Tool.Extensions.Scan(CodeGenerationConfig config, Assembly assembly) in C:\Projects\Mapster\src\Mapster.Tool\Extensions.cs:line 177
1>   at Mapster.Tool.Program.GenerateModels(ModelOptions opt) in C:\Projects\Mapster\src\Mapster.Tool\Program.cs:line 146
1>   at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
1>   at Mapster.Tool.Program.Main(String[] args) in C:\Projects\Mapster\src\Mapster.Tool\Program.cs:line 17
1>System.IO.FileNotFoundException: Could not load file or assembly 'PresentationFramework, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
1>File name: 'PresentationFramework, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
1>System.IO.FileNotFoundException: Could not load file or assembly 'PresentationFramework, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
1>File name: 'PresentationFramework, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
1>C:\Users\irme\source\repos\MappingTesting\MappingTestWPFApp\MappingTestWPFApp.csproj(11,3): error MSB3073: The command "dotnet mapster model -a C:\Users\irme\source\repos\MappingTesting\MappingTestWPFApp\bin\Debug\net6.0-windows\MappingTestWPFApp.dll -n MappingTest2.src -o Models" exited with code -532462766.
1>Done building project "MappingTestWPFApp.csproj" -- FAILED. ```