DEV Community

Wallism
Wallism

Posted on

dotnet swagger tofile : Could not load file or assembly System.Runtime

When running this command:
dotnet swagger tofile --output "valid-path" "valid-dll" v1

I was getting this error:

Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

The target dll was .net 5.0 but because I have .net 6.0 installed, my system was using that sdk by default. To use the correct sdk when running dotnet cli, this SO answer has a clear explanation. Basically you add a new global.json file at a folder level that makes sense (e.g. project or solution root folder).

Top comments (0)