dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.35k stars 4.74k forks source link

System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.Configuration.FileExtensions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. #52543

Closed reuvygroovy closed 2 years ago

reuvygroovy commented 3 years ago

I created a new .NET Core C# Worker template in VS2019, and the default package for Microsoft.Extensions.Hosting is not upgraded to the latest and I get an error/warning about Circular references. So I updated to version 5.0.0.

Still, when trying to debug/run the software, I get the following missing dependency error:

System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.Configuration.FileExtensions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.'

When trying to install the above package I get another error:

PM> install-package Microsoft.Extensions.Configuration.FileExtensions
Restoring packages for C:\Repos\DotNet\Areas\Automation\Hangfire\HangfireService\HangfireService.csproj...
install-package : NU1108: Cycle detected. 
  HangfireService -> Microsoft.Extensions.Configuration.UserSecrets 5.0.0 -> 
Microsoft.Extensions.Configuration.Json 5.0.0 -> Microsoft.Extensions.Configuration.UserSecrets 5.0.0 
-> Microsoft.Extensions.Configuration.Json (>= 5.0.0).
At line:1 char:1
+ install-package Microsoft.Extensions.Configuration.FileExtensions
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.I 
   nstallPackageCommand

install-package : Package restore failed. Rolling back package changes for 'HangfireService'.
At line:1 char:1
+ install-package Microsoft.Extensions.Configuration.FileExtensions
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.I 
   nstallPackageCommand

Time Elapsed: 00:00:01.9434192
PM> 
dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

reuvygroovy commented 3 years ago

area-Microsoft.Extensions I guess, since the problem is with Microsoft.Extensions.Configuration.FileExtensions

ghost commented 3 years ago

Tagging subscribers to this area: @maryamariyan, @safern See info in area-owners.md if you want to be subscribed.

Issue Details
I created a new .NET Core C# Worker template in VS2019, and the default package for Microsoft.Extensions.Hosting is not upgraded to the latest and I get an error/warning about Circular references. So I updated to version 5.0.0. Still, when trying to debug/run the software, I get the following missing dependency error: System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.Configuration.FileExtensions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.' When trying to install the above package I get another error: PM> install-package Microsoft.Extensions.Configuration.FileExtensions Restoring packages for C:\Repos\DotNet\Areas\Automation\Hangfire\HangfireService\HangfireService.csproj... install-package : NU1108: Cycle detected. HangfireService -> Microsoft.Extensions.Configuration.UserSecrets 5.0.0 -> Microsoft.Extensions.Configuration.Json 5.0.0 -> Microsoft.Extensions.Configuration.UserSecrets 5.0.0 -> Microsoft.Extensions.Configuration.Json (>= 5.0.0). At line:1 char:1 + install-package Microsoft.Extensions.Configuration.FileExtensions + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.I nstallPackageCommand install-package : Package restore failed. Rolling back package changes for 'HangfireService'. At line:1 char:1 + install-package Microsoft.Extensions.Configuration.FileExtensions + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.I nstallPackageCommand Time Elapsed: 00:00:01.9434192 PM>
Author: reuvygroovy
Assignees: -
Labels: `area-Extensions-Configuration`, `untriaged`
Milestone: -
ghost commented 3 years ago

Tagging subscribers to this area: @eerhardt, @maryamariyan See info in area-owners.md if you want to be subscribed.

Issue Details
I created a new .NET Core C# Worker template in VS2019, and the default package for Microsoft.Extensions.Hosting is not upgraded to the latest and I get an error/warning about Circular references. So I updated to version 5.0.0. Still, when trying to debug/run the software, I get the following missing dependency error: System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.Configuration.FileExtensions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.' When trying to install the above package I get another error: PM> install-package Microsoft.Extensions.Configuration.FileExtensions Restoring packages for C:\Repos\DotNet\Areas\Automation\Hangfire\HangfireService\HangfireService.csproj... install-package : NU1108: Cycle detected. HangfireService -> Microsoft.Extensions.Configuration.UserSecrets 5.0.0 -> Microsoft.Extensions.Configuration.Json 5.0.0 -> Microsoft.Extensions.Configuration.UserSecrets 5.0.0 -> Microsoft.Extensions.Configuration.Json (>= 5.0.0). At line:1 char:1 + install-package Microsoft.Extensions.Configuration.FileExtensions + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.I nstallPackageCommand install-package : Package restore failed. Rolling back package changes for 'HangfireService'. At line:1 char:1 + install-package Microsoft.Extensions.Configuration.FileExtensions + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.I nstallPackageCommand Time Elapsed: 00:00:01.9434192 PM>
Author: reuvygroovy
Assignees: -
Labels: `area-Extensions-Hosting`, `untriaged`
Milestone: -
maryamariyan commented 3 years ago

@reuvygroovy the issue description is a bit hard to follow. Could you please help walkthrough identifying what the minimal repro for this is?

What I tried is:

> dotnet new worker

for me the TargetFramework in csproj gets generated as net6.0 since I am using the preview versions. But then when changing my csproj down to:

+    <TargetFramework>net5.0</TargetFramework>
-    <TargetFramework>net6.0</TargetFramework>

and with packages versions:

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
  </ItemGroup>

I find no circular dependency or anything. What does your csproj look like?

reuvygroovy commented 3 years ago

Sure. Using VS2019 16.9.4 to create a .NET Core 3.1 Project based on the "Worker Service" template for C#.

The project gets created and from the outset: image

Then I updated the Microsoft.Extensions.Hosting nuget package to v5.0.0 and when compiling/running I got: image

I was able to overcome this challenge in a backwards way, by downloading the nuget manually, extracting the above Microsoft.Extensions.Configuration.FileExtensions.dll assembly and adding it as a reference to the project, although I don't think that is normal/indented behavior.

SimonCropp commented 3 years ago

@reuvygroovy i tried your steps and could not reproduce. attached is my working solution WorkerService1.zip

perhaps you could share a zip of your failing solution?

reuvygroovy commented 3 years ago

When I ran your code I got the same error image

I'll attach my version, but just for comparison sakes, to differentiate, not that it matters, your code had these headers: using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks;

Mine has only these: using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting;

I rebuild the code, and all works well.

But when running the services via VS2019 I get the above error. Attached is your (original) / my (new) solution WorkerService1-new.zip

SimonCropp commented 3 years ago

does it work on a build server?

reuvygroovy commented 3 years ago

I don't have a build server, but I asked another colleague of mine to open the same solution and indeed it worked by her. Any ideas what my problem is?

safern commented 3 years ago

@reuvygroovy I was looking at your sample and tried to repro locally and I was not able to reproduce, there might be something going on with your environment or your VS cache. The reason why I believe this is because in your repro, looking at the assets.json file under obj/Debug there is no entry for Microsoft.Extensions.Configuration.FileExtensions other than the dependency the other packages have to it, but there should be an entry stating that your app depends on it. i.e, in my intent to repro I have:

"Microsoft.Extensions.Configuration.FileExtensions/5.0.0": {
        "type": "package",
        "dependencies": {
          "Microsoft.Extensions.Configuration": "5.0.0",
          "Microsoft.Extensions.Configuration.Abstractions": "5.0.0",
          "Microsoft.Extensions.FileProviders.Abstractions": "5.0.0",
          "Microsoft.Extensions.FileProviders.Physical": "5.0.0",
          "Microsoft.Extensions.Primitives": "5.0.0"
        },
        "compile": {
          "lib/netstandard2.0/Microsoft.Extensions.Configuration.FileExtensions.dll": {}
        },
        "runtime": {
          "lib/netstandard2.0/Microsoft.Extensions.Configuration.FileExtensions.dll": {}
        }

Also, the deps.json file under bin/Debug should have an entry for it, for the assembly loader to be able to resolve the runtime assembly (which is what is missing to resolve). I.e in mine I have:

"Microsoft.Extensions.Configuration.FileExtensions/5.0.0": {
        "dependencies": {
          "Microsoft.Extensions.Configuration": "5.0.0",
          "Microsoft.Extensions.Configuration.Abstractions": "5.0.0",
          "Microsoft.Extensions.FileProviders.Abstractions": "5.0.0",
          "Microsoft.Extensions.FileProviders.Physical": "5.0.0",
          "Microsoft.Extensions.Primitives": "5.0.0"
        },
        "runtime": {
          "lib/netstandard2.0/Microsoft.Extensions.Configuration.FileExtensions.dll": {
            "assemblyVersion": "5.0.0.0",
            "fileVersion": "5.0.20.51904"
          }
        }

But yours don't contain any of these entries, hence why you are experiencing such issue. It would be helpful if you could share a binlog of the build on your environment to see what's going on.

Here are some instructions on how to get the binlog: https://github.com/dotnet/project-system/blob/main/docs/design-time-builds.md#diagnosing-design-time-builds

Also, does this repro if you run it outside of VS?

reuvygroovy commented 3 years ago

When running the service as a cmd I get the same error:

C:\WINDOWS\system32>\WorkerService1\WorkerService1\bin\Debug\netcoreapp3.1\WorkerService1.exe" Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Configuration.FileExtensions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. File name: 'Microsoft.Extensions.Configuration.FileExtensions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' at Microsoft.Extensions.Hosting.HostBuilder.BuildAppConfiguration() at Microsoft.Extensions.Hosting.HostBuilder.Build()

Let me know if there is a secure mail which I can forward the build logs to you.

safern commented 3 years ago

Good that you get the repro with the cmd line as well. Does this repro if you run dotnet build on the cmd line and then run it? If it does repro please get the binlog produced by running dotnet build /bl. It should produce an msbuild.binlog file.

Can you use a minimal repro and just share the binlog here so that it doesn't contain any sensitive information?

Make sure to remove any environment variables that might be sensitive before running the command to gather the binlog as env vars are preserved in there.

reuvygroovy commented 3 years ago

dotnet build ran ok from the cmdline. The subsequent dotnet run returned the same error.

Is this what you are looking for: C:\Program Files\dotnet\sdk\5.0.300\MSBuild.dll -consoleloggerparameters:Summary -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\Program Files\dotnet\sdk\5.0.300\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,C:\Program Files\dotnet\sdk\5.0.300\dotnet.dll -maxcpucount -restore -verbosity:m /bl .\WorkerService1.csproj Determining projects to restore... All projects are up-to-date for restore. WorkerService1 -> C:\Downloads\WorkerService1\WorkerService1\bin\Debug\netcoreapp3.1\WorkerService1.dll

safern commented 3 years ago

What I'm looking for is, after running dotnet build /bl there should be a file msbuild.binlog in the directory where you ran the command from. That file is the one I'm looking for.

reuvygroovy commented 3 years ago

attached. msbuild.zip

eerhardt commented 2 years ago

@reuvygroovy - are you still having this issue? It sounds to me that your NuGet cache may be corrupted, or some other machine specific problem.

I looked at your binlog, but unfortunately it was an incremental build, so there isn't much information in it. If you are still having problems, can you dotnet clean and then run dotnet build /bl?

The reason I think it is a NuGet cache issue is becuase this doesn't make sense:

install-package : NU1108: Cycle detected. 
  HangfireService -> Microsoft.Extensions.Configuration.UserSecrets 5.0.0 -> 
Microsoft.Extensions.Configuration.Json 5.0.0 -> Microsoft.Extensions.Configuration.UserSecrets 5.0.0 
-> Microsoft.Extensions.Configuration.Json (>= 5.0.0).

Microsoft.Extensions.Configuration.Json 5.0.0 -> Microsoft.Extensions.Configuration.UserSecrets 5.0.0 Configuration.Json doesn't depend on Configuration.UserSecrets.

ghost commented 2 years ago

This issue has been marked needs more info since it may be missing important information. Please refer to our contribution guidelines for tips on how to report issues effectively.

reuvygroovy commented 2 years ago

I guess you're right