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

Update Mapster.Tool to include .net6.0 as target framework #387

Closed
fredrikahs opened this issue Nov 9, 2021 · 7 comments · Fixed by #405
Closed

Update Mapster.Tool to include .net6.0 as target framework #387

fredrikahs opened this issue Nov 9, 2021 · 7 comments · Fixed by #405

Comments

@fredrikahs
Copy link

I'm using Mapster.Tool to generate mappers from interfaces. When I tried updating my project to .NET 6.0 an exception is thrown.

Updating the target framework in Mapster.Tool to include net6.0 fixes the issue.

The issue can be reproduced with a new console application running .NET 6.
Program.cs:

using Mapster;

Console.WriteLine("Hello, World!");

public class A
{
    public string Str { get; set; }
}

public class B
{
    public string Str { get; set; }
}

[Mapper]
public interface IMapper
{
    A Map(B test);
}

public class MyRegister : IRegister
{
    public void Register(TypeAdapterConfig config)
    {
        config.NewConfig<A, B>();
    }
}

Running dotnet mapster mapper -a ".\bin\Debug\net6.0\MapsterNet6Issue.dll" outputs the following error

Cannot find assembly path: System.Runtime (type=package, version=5.0.11-servicing.21473.8)
Cannot find assembly path: System.Runtime (type=package, version=5.0.11-servicing.21473.8)
Cannot find assembly path: System.Runtime (type=package, version=5.0.11-servicing.21473.8)
Cannot find assembly path: System.Runtime (type=package, version=5.0.11-servicing.21473.8)
Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 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.TypeAdapterConfig.<>c.<Scan>b__87_0(Assembly assembly) in D:\git\Mapster\src\Mapster\TypeAdapterConfig.cs:line 619
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Mapster.TypeAdapterConfig.Scan(Assembly[] assemblies) in D:\git\Mapster\src\Mapster\TypeAdapterConfig.cs:line 619
   at Mapster.Tool.Program.GenerateMappers(MapperOptions opt) in D:\git\Mapster\src\Mapster.Tool\Program.cs:line 65
   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 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
@alifeofkaizen
Copy link
Contributor

To get by, I forked the project and confirmed it works by setting Target to Net60 and installing the locally built Mapster.Tool nupkg.

Created PR #390 accordingly

@Philippe-Laval
Copy link
Contributor

You can compile Mapster tool by changing net6.0 and not net5.0
netcoreapp3.1;net6.0
Then use the executable to run your command.

@Philippe-Laval
Copy link
Contributor

Well, It was a little more complicated to have the tool working.
You can found the code here:
https://github.com/Philippe-Laval/Mapster
https://github.com/Philippe-Laval/TestMapster

All projects are compiled under net6.0 (I created a pull request).

@vladmld
Copy link

vladmld commented Feb 18, 2022

Any news on this issue? I'm experiencing the same behavior and I was wondering if any pull request is in planned to be merged to solve this.

@andrerav
Copy link
Contributor

Please try the latest version now available on NuGet and let me know how it goes. I'm on standby to resolve any issues you may encounter.

@vladmld
Copy link

vladmld commented Feb 21, 2022

Please try the latest version now available on NuGet and let me know how it goes. I'm on standby to resolve any issues you may encounter.

Seems to be working so far, had to remember to run dotnet tool update Mapster.Tool. Cheers!

@janiskulj
Copy link

Any chance to add .net7.0 target framework?

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

Successfully merging a pull request may close this issue.

6 participants