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

Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=7.0.0.0 #2585

Closed
klaudiusz-czapla opened this issue Jan 11, 2023 · 18 comments

Comments

@klaudiusz-czapla
Copy link

klaudiusz-czapla commented Jan 11, 2023

I ran into an issue when I was trying to generate swagger.json file using swashbuckle.aspnetcore.cli in version 6.5.0 on machine with .net sdk installed in both versions (6 and 7)

Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=7.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=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

dotnet --info:

PS C:\Users\my_user_name> dotnet --info
.NET SDK:
 Version:   7.0.101
 Commit:    bb24aafa11

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.101\

Host:
  Version:      7.0.1
  Architecture: x64
  Commit:       97203d38ba

.NET SDKs installed:
  6.0.404 [C:\Program Files\dotnet\sdk]
  7.0.100 [C:\Program Files\dotnet\sdk]
  7.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

.csproj:

    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
    <PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />

After uninstalling .net 7 sdk it started working properly. Compilation succeeded. swagger.json file were properly re-built.
Putting global.json file didnt help much

@Meligy
Copy link

Meligy commented Jan 12, 2023

I got the same problem also running on a .NET 6 project, but only when running using .NET 7 SDK.

My project is a .NET 6 project that I'm looking forward to upgrading to .NET 7 later. I have .NET 6 and 7 installed on the machines. And I have a global.json file to control the .NET SDK version rollover to .NET 7. Also I wanted to take advantage of slightly improved dotnet watch command in .NET 7 SDK even before I upgrade the actual project.

When the global.json version is allowed to roll over to .NET 7, "rollForward": "latestMajor", it fails to work with the same error above.

When I set the version to only allow .NET 6 in global.json, like "version": "6.0.202", "rollForward": "latestMinor", the generation seems to work fine.

So, the failing scenario is building .NET 7 SDK while targeting .NET 6 runtime.

@Meligy
Copy link

Meligy commented Jan 12, 2023

To help testing, make sure that you run dotnet clean before every build, and also including the --no-incremental flag in the build command, like dotnet build --no-incremental.

@klaudiusz-czapla
Copy link
Author

@Meligy May I ask you where to put this global.json file you referred to ? Should it be the root project or solution directory ? For me it didn't help (placed in solution directory) but let me double check it.

@klaudiusz-czapla
Copy link
Author

klaudiusz-czapla commented Jan 12, 2023

@Meligy I can confirm that your approach helped. I did sth like this and it started build without any problems.

dotnet new globaljson --sdk-version 6.0.404 --roll-forward latestMinor

Maybe I had wrong file name and this is why it was not working for me initially, but now after using this command I made sure that this file was created properly and my project is building without any issues. Thanks for the hint..

@TobiasBreuer
Copy link

I'm currently facing the same issue - my problem is, that I have to have the .Net 7 SDK in my global.json file, as I have two APIs in the solution, one for .Net 6 and one for .Net 7. So in order to build all projects (which works fine) I have to use version 7 of the SDK, but when generating the swagger for the .Net 6 API with the .Net 7 SDK and swashbuckle cli version 6.5.0 I will get this exact exception - so it seems that I either have to separate those two APIs into individual solutions (and repositories) or align both APIs to use either Net 6 or Net 7 in both, a mixture seems to not be possible.

@klaudiusz-czapla
Copy link
Author

klaudiusz-czapla commented Jan 19, 2023

@TobiasBreuer I would advise to try out to put global.json file in the project itself which requires "downgrade"

As I found somewhere dotnet is traversing filesystem to look for that file so I assume global.json file on the level of solution will be overwritten by the file in the project itself but this is only my assumption..

The global. json file in the root of your project (or even in the root of your file system as the SDK will traverse the file system until it finds one) allows defining which version of the SDK to use.

So the question is whether dotnet looks for first global.json and then it will stop searching further or it could be overwritten by the next one found 1+ level deeper in the filesystem

But I think as you said the easiest way (if that will not work) is to split projects then..

@iam-gopi
Copy link

Im getting the same error with a .net core API project using 6.0 SDK. I'm getting this error while publishing the project to azure which was working perfectly fine before updating VS to the latest version.

@aswinfrancis91
Copy link

We are also facing same issue. We had projects targeting 5.0 but build with 7.0. Build runs fine when in release mode but in debug mode I get the same error because of post build script that tries to generate swagger json. I updated to 6.0 and still faced the problem. It only worked after adding global json as mentioned above.
I have another project that is in 6.0 and has the same setup done with post build swagger json generation. It still works fine. The difference I noticed is that when I build it uses msbuild from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe
whereas the solution I have issue with runs msbuild from C:\Program Files\dotnet\sdk\7.0.103\MSBuild.dll

@danielloganking
Copy link

I too am encountering this error. I updated to the latest version of .NET 7 SDK such that i get

> dotnet --version
7.0.201

and while I have some old SDK versions hanging around according to dotnet sdk check there is nothing that should cause this error. Downgrading to swashbuckle.aspnetcore.cli version 6.4.0 works fine though. @eslamisepehr since you wrote 3d5159c do you have any ideas what could be causing this?

@capjan
Copy link

capjan commented Apr 28, 2023

> dotnet --version
7.0.203

is also affected and downgrading to swashbuckle.aspnetcore.cli 6.4.0 is still a workaround.

53 days later since @danielloganking question. Any news on 6.5.0?

@zahalzel
Copy link

We have a scenario in Visual Studio Web Tools - configuring Power Platform on .NET Web API projects - where we install the Swashbuckle CLI as a local tool. This is a blocking issue for .NET 6 Web API projects, any word on whether this will be fixed in the next update?

@eslamisepehr
Copy link
Contributor

I too am encountering this error. I updated to the latest version of .NET 7 SDK such that i get

> dotnet --version
7.0.201

and while I have some old SDK versions hanging around according to dotnet sdk check there is nothing that should cause this error. Downgrading to swashbuckle.aspnetcore.cli version 6.4.0 works fine though. @eslamisepehr since you wrote 3d5159c do you have any ideas what could be causing this?

I have checked, and the issue is due to the use of different versions of .NET at runtime.

@danielloganking
Copy link

I have checked, and the issue is due to the use of different versions of .NET at runtime.

Does this mean that even if I have only the .NET 7 SDK installed and use it to run an app or project which targets net6.0 and not net7.0 then swashbuckle.aspnetcore.cli 6.5.0 will fail to load?

@Havunen
Copy link

Havunen commented Nov 17, 2023

This fails too, I dont have .NET 7 separately installed, but it comes from the Visual Studio 2022 installation.

dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.417
Commit: 04fde1d2e3

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.417\

Host:
Version: 8.0.0
Architecture: x64
Commit: 5535e31a71

.NET SDKs installed:
3.1.426 [C:\Program Files\dotnet\sdk]
5.0.408 [C:\Program Files\dotnet\sdk]
6.0.417 [C:\Program Files\dotnet\sdk]
8.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file is set at the repository root

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Downgrading to 6.4.0 does fix the issue

@Baertie
Copy link

Baertie commented Dec 5, 2023

+1

@aronbierbaum
Copy link

@eslamisepehr Is there a workaround besides downgrading to Swashbuckle 6.4.0?

@Havunen
Copy link

Havunen commented Jan 31, 2024

I created a fork of this repository, because I couldn't wait for the maintainer.
The fork is called DotSwashbuckle https://github.com/Havunen/DotSwashbuckle it only supports .NET 8 for now.

Change the csproj nuget reference

-<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
+<PackageReference Include="DotSwashbuckle.AspNetCore" Version="1.0.2" />

Install the dotnet tool

dotnet tool uninstall --global Swashbuckle.AspNetCore.Cli
dotnet tool install --global --version 1.0.2 DotSwashbuckle.AspNetCore.Cli

1.0.2 is the first working version.

I am planning to maintain that repository at least until this repository picks up with the development, so if you are interested using it you can post issues or open PRs there.

@martincostello
Copy link
Collaborator

I'm going to close this in favour of #2792, as going through triaging the open issues I'm spotting a common theme and it's easier to manage one issue. Please track that issue for further updates.

If this issue isn't resolved once we have added support for net8.0, please open a new issue.

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

No branches or pull requests