I have a .NET web application that works fine at my desk but when I deploy it to the server I'm getting this error:
"Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."
My project targets the .NET 4.6.1 framework and both machines have 4.8 installed. I already had the latest Microsoft.Bcl.AsyncInterfaces NuGet package installed so I attempted to revert to version 1.1 instead of the latest 5.0 and that didn't fix it.
I'm not sure what else to check. The Microsoft.Bcl.AsyncInterfaces.dll is in the bin folder.
Related
Context
After migrating to version 3.1.420 of dotnetcore SDK (installed automatically by Windows Update) we are facing the problem, that a solution failed to build (on a build server) because nuget restore is unable to restore the package Microsoft.NETCore.App.Host.win-x64.
We have local package feeds configured in nuget.config, the source nuget.org is not and must not accessed directly!
Now I get the following output:
c:\> nuget.exe restore ***.sln -NoCache -NonInteractive -ConfigFile .nuget\NuGet.config
[...]
Errors in C:\build\_work\313\s\***.csproj
NU1101: Unable to find package Microsoft.NETCore.App.Host.win-x64. No packages exist with this id in source(s): ***, ***, ***
NuGet Config files used:
C:\build\_work\313\s\.nuget\NuGet.config
Feeds used:
https://***.com/tfs/***/_packaging/A***/nuget/v3/index.json
https://***.com/tfs/***/_packaging/B***/nuget/v3/index.json
https://***.com/tfs/***/_packaging/C***/nuget/v3/index.json
Environment:
C:\build\_work\313\s>dotnet --list-sdks
3.1.420 [C:\Program Files\dotnet\sdk]
5.0.400 [C:\Program Files\dotnet\sdk]
5.0.408 [C:\Program Files\dotnet\sdk]
Question
Why restore process tries to fetch the nuget package while the content is already part of the SDK installed?
What I've tried?
I've analyzed the behavior of the nuget.exe using Process Monitor (Sysinternals).
I found that the folder c:\Program Files\dotnet\packs\Microsoft.NETCore.App.Host.win-x64\3.1.25\ is accessed but not found, only the folder 3.1.26 exists after update of SDK.
Why restore process tries to access "3.1.25" while "3.1.26" is installed?
On my local machine the restore works as expected. The package is NOT available in my local NuGet cache. Here the folder c:\Program Files\dotnet\packs\Microsoft.NETCore.App.Host.win-x64\3.1.26\ is accessed as expected.
I also tried to reinstall the SDK version. No effect.
Firstly, I highly recommend avoiding nuget.exe restore. If you can, prefer dotnet restore, and otherwise msbuild -t:restore. It's unrelated to the problem you're having here, but you can avoid different types of problems by migrating.
Anyway, the .NET Core SDK 3.1.419 would have had the version 3.1.25 versions of the runtime host, whereas .NET Core SDK 3.1.420 has version 3.1.26 of the runtime hosts. Hence, when the SDK upgraded from 419 to 420, the old version of the runtime host was removed, and the new one installed.
However, as your dotnet --list-sdks output shows, you have the .NET 5 SDK installed. .NET 5 is now out of support, and so it did not receive any update in this month's Patch Tuesday. In May, the last month that the .NET 5 SDK was updated, the latest version of the .NET 3.1 hosting app package was 3.1.25, so when you restore/build an app targeting .NET Core 3.1 with the .NET 5 SDK, the SDK checks for the version of the runtime hosting package it knows about, sees it isn't available locally, and then tells NuGet to download it.
You can either use a global.json to pin that directory's dotnet commands to the .NET 3.1 SDK, or you can install the June 2022 .NET 6 SDK (6.0.301), and then both of them will know that the .NET 3.1 runtime hosting package is version 3.1.26, and therefore should not ask NuGet to download it. Well, unless you uninstall the .NET 3.1 SDK completely and use the .NET 6 SDK to build it.
I know it's confusing. The .NET marketing people chose names that doesn't aid in understanding the difference, but the .NET SDK are build tools that can build any version of .NET equal or lower version, and the .NET runtime is completely independent. As mentioned previously in this answer, you can build .NET Core 3.1 apps with the .NET 6 SDK, the .NET Core 3.1 SDK is not needed (but the runtime will be, unless you publish a "self-contained" app).
I have recently upgraded our .Net Core 2.2 application to .Net 5.0. I'm now trying to upgrade our TeamCity build agent, so it can build this solution.
Installed the .Net 5.0 SDK on the build agent, and restarted the machine.
Installed the latest Community edition of Visual Studio on the build agent as well.
When I try to run a build on the agent using "dotnet msbuild", it shows this error message:
[Building CodeEngineQueryBuilder4] C:\Program Files\dotnet\sdk\5.0.202\Microsoft.Common.CurrentVersion.targets(1216,5): error MSB3971: The reference assemblies for ".NETFramework,Version=v5.0" were not found. You might be using an older .NET SDK to target .NET 5.0 or higher. Update Visual Studio and/or your .NET SDK.
More info:
RDPed onto the build agent and run "dotnet --info" on the command line, which gave me ".Net SDK Version 5.0.203"
I did find directory "C:\Program Files\dotnet\sdk\5.0.203" on the build agent, so it seems .Net 5.0 is installed.
The build agent runs Windows 8.1.
The TeamCity installation is on the latest version.
What am I missing here?
In the end, I found that I had to change the system environment variable MSBuildSdksPath
to make it point at the new .net5 Sdk directory.
In my case, I repointed it at:
C:\Program Files\dotnet\sdk\5.0.203\Sdks
I have a Xamarin.Forms app. Yesterday, I updated Xamarin.Forms package to the latest version 4.8.0.1687. In Visual Studio 2019 I can build the app and run it. But build in Azure DevOps pipeline fails. For Android, the following error is reported:
C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1005: Assets file 'D:\a\1\s\My_MobileApp\My_MobileApp\obj\project.assets.json' doesn't have a target for 'netstandard2.0'. Ensure that restore has run and that you have included 'netstandard2.0' in the TargetFrameworks for your project. [D:\a\1\s\My_MobileApp\My_MobileApp\My_MobileApp.csproj]
Where My_MobileApp is the shared project.
I checked the project file, but the Target Framework there is set to .NET Standard 2.0. I checked the project.assets.json in the local obj folder, and it has
"originalTargetFrameworks": [
"netstandard2.0"
],
But no "TargetFrameworks".
What is wrong, and how this can be fixed?
Updating nuget to 5.8 worked for me
I recognized a different compiler behaviour under .net core 3.1 for windows and linux. The problem is, that under linux and windows different assembly versions of a dependency is moved to the output directory when compiling. Having the following project structure:
My.Net.App
> Reference: Sample.dll (Version 1.3.5)
> Reference: Newtonsoft.Json (Version 11.0.2)
> Reference: AnotherSample.dll (Version 4.2.1)
> Reference: Newtonsoft.Json (Version 12.0.3)
As you can see, my project is referencing Sample-package and AnotherSample-package. Both of these packages are referencing Newtonsoft.Json in different versions. When I compile my project under windows, the output directory contains Newtonsoft.Json 12.0.3. When I'm compiling the same code under linux, the output directory contains Newtonsft.Json 11.0.2 and my application stops working.
I've tried using assembly binding and referencing Newtonsoft.Json 12.0.3 directly in My.Net.App.
EDIT
I've got the same issue when compiling under a local ubuntu, in azure DevOps and under docker.
Thanks for any help.
I have a NET 4.6 Web App that uses ASP.NET Core 1.1 on Azure. This Web App has a dependency on a NET 4.6 Class Library which has a dependency on Microsoft.EntityFrameworkCore (Version=1.1.1.0).
When I deploy it from Git for the first time I get messages of packages installing, like this one:
Installing Microsoft.Extensions.Primitives 1.1.0.
In fact I get three different lines that install Microsoft.Extensions.Primitives versions: 1.1.0, 1.0.1 and 1.0.0.
But in the same deployment I get over 35 errors on the Class Library project, that say that it could not locate an assembly that it just installed. One of them is Microsoft.Extensions.Primitives:
D:\Program Files (x86)\dotnet\sdk\2.0.0-preview1-005977\Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.Extensions.Primitives, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [D:\home\site\repository\ClassLibraryNet462\ClassLibraryNet462.csproj]
I see that it is trying to use NET Core 2.0.0-preview1-005977, but I don't know why. I guess that may be part of the problem.
Does anyone have any idea of how to solve it?