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

System.IO.FileLoadException: Could not load file or assembly NuGet.Frameworks, Version=6.2.0.146 #170

Closed
craigktreasure opened this issue May 25, 2022 · 8 comments

Comments

@craigktreasure
Copy link

MSBuild.ProjectCreation: 8.0.0

Hello. I came across this library at the MSBuildSdks and started using it in an experimental project. Everything was working great until recently when my tests began to fail to build my generated projects when executing tests for the .NET 5 and .NET 6 target platforms (the test project targets those platforms). As far as I can tell, the issue comes up as soon as I install the more recent .NET 6 6.0.300 SDK on the machine. Seeing it on Windows, Linux, and MacOS. I currently target .NET Core 3.1, .NET 5, and .NET 6 in my test projects. The tests behave as expected for .NET Core 3.1, but fail with the following for .NET 5 and .NET 6 with the following output:

Target "ResolvePackageAssets" in file "C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets" from project "C:\Users\craig\AppData\Local\Temp\CentralBuildOutputTests\ct0vn00m.bwj\src\MyClassLibrary\MyClassLibrary.csproj" (target "ResolveLockFileReferences" depends on it):
Using "ResolvePackageAssets" task from assembly "C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.Sdk\targets\..\tools\net6.0\Microsoft.NET.Build.Tasks.dll".
Task "ResolvePackageAssets"
Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.
The "ResolvePackageAssets" task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.2.0.146, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)
File name: 'NuGet.Frameworks, Version=6.2.0.146, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
 ---> System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.2.0.146, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at Microsoft.Build.Shared.MSBuildLoadContext.Load(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.CanResolveApphostFromFrameworkReference()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteApphostsForShimRuntimeIdentifiers()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteItemGroup(Action writeItems)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteItemGroups()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.Write()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.WriteToMemoryStream()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromMemory(ResolvePackageAssets task, Byte[] settingsHash)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
Done executing task "ResolvePackageAssets" -- FAILED.
Done building target "ResolvePackageAssets" in project "MyClassLibrary.csproj" -- FAILED.

full output.txt

I don't think my tests are doing anything overly complicated, but I've been wrong before. I haven't been able to workaround it on my dev machine. Even forcing it to use the 6.0.2xx version using the global.json didn't work. But, I was able to specifically install the 6.0.2xx SDKs on the build agents as a workaround for now and that did work, so i'm fairly certain it is the newer SDK.

Have you seen anything similar on your end? Any suggestions?

craigktreasure added a commit to craigktreasure/CentralBuildOutput that referenced this issue Jun 16, 2022
#29)

  - I seem to be encountering an issue with newer .NET 6 SDKs (likely the runtime actually) related to the use of MSBuild.ProjectCreation (jeffkl/MSBuildProjectCreator#170) which is preventing me from being able to build. This serves as a workaround for now.
  - This change removes .NET 5 from the test platforms since it is now [End of Support](https://dotnet.microsoft.com/download/dotnet) as of May 10, 2022.
craigktreasure added a commit to craigktreasure/CentralBuildOutput that referenced this issue Jun 17, 2022
  - Applying a transitive update for NuGet.Frameworks to workaround jeffkl/MSBuildProjectCreator#170.
@craigktreasure
Copy link
Author

A workaround appears to be to apply a transitive update for NuGet.Frameworks to update to the latest version.

craigktreasure added a commit to craigktreasure/CentralBuildOutput that referenced this issue Jun 17, 2022
* Update dependencies

* Apply transitive update for NuGet.Frameworks

  - Applying a transitive update for NuGet.Frameworks to workaround jeffkl/MSBuildProjectCreator#170.

* Re-enable latest .NET 6.x SDK for builds
@jeffkl
Copy link
Owner

jeffkl commented Jun 20, 2022

Yes you've discovered the problem with NuGet.Frameworks being referenced by Microsoft.NET.Test.Sdk:

This causes your unit test to need that particular version in the output directory and causes collisions. Specifically, the error includes Could not find or load a specific file. This is because MSBuild is loading NuGet assemblies that ship with .NET SDK/Visual Studio which can be different than the version than are in the package dependency graph of your app. I try to keep MSBuild.ProjectCreation updated to match the latest version that is out there but have fallen behind. Do you want to send a PR to update the version used by MSBuild.ProjectCreation?

@craigktreasure
Copy link
Author

Well, for the record, it looks like you already have a more recent update (6.2.0) to that dependency checked in, but haven't shipped an updated release. 8.0.0 currently depends on 6.1.0. The latest is 6.2.1. I'm happy to submit a PR to update to 6.2.1. We'd just need an updated release following that update.

@craigktreasure
Copy link
Author

To be honest, i'm surprised Dependabot isn't helping out here.

@jeffkl
Copy link
Owner

jeffkl commented Jun 21, 2022

I was getting bombarded with emails from dependabot every single day so I changed the frequency to monthly 😄 My curse for having so many repos. I can try changing it to weekly so you don't have to send a PR.

4755c0d

@craigktreasure
Copy link
Author

Haha, i completely understand. I think i can manage the one character PR 😉.

@craigktreasure
Copy link
Author

Looks like Dependabot beat me to it.

@jeffkl
Copy link
Owner

jeffkl commented Jun 21, 2022

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

2 participants