Please, observe:
C:\work\Autofac> dir
Directory: C:\work\Autofac
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 1/23/2025 11:42 PM 31 .gitignore
C:\work\Autofac> dotnet new sln -n Autofac
The template "Solution File" was created successfully.
C:\work\Autofac> dotnet new console -n Autofac -o .
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring C:\work\Autofac\Autofac.csproj:
Restore succeeded.
C:\work\Autofac> dotnet add package Autofac
Build succeeded in 0.7s
info : X.509 certificate chain validation will use the default trust store selected by .NET for code signing.
info : X.509 certificate chain validation will use the default trust store selected by .NET for timestamping.
info : Adding PackageReference for package 'Autofac' into project 'C:\work\Autofac\Autofac.csproj'.
info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/autofac/index.json
info : Restoring packages for C:\work\Autofac\Autofac.csproj...
info : CACHE https://api.nuget.org/v3/vulnerabilities/index.json
info : CACHE https://api.nuget.org/v3-vulnerabilities/2025.01.23.05.36.26/vulnerability.base.json
info : CACHE https://api.nuget.org/v3-vulnerabilities/2025.01.23.05.36.26/2025.01.23.17.36.28/vulnerability.update.json
error: The given key '(Autofac, 8.2.0)' was not present in the dictionary.
C:\work\Autofac>
Something must be wrong with the Autofac NuGet package, because I am able to add Newtonsoft.Json, for example:
C:\work\Autofac> dotnet add package Newtonsoft.Json
Build succeeded in 0.7s
info : X.509 certificate chain validation will use the default trust store selected by .NET for code signing.
info : X.509 certificate chain validation will use the default trust store selected by .NET for timestamping.
info : Adding PackageReference for package 'Newtonsoft.Json' into project 'C:\work\Autofac\Autofac.csproj'.
info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/newtonsoft.json/index.json
info : Restoring packages for C:\work\Autofac\Autofac.csproj...
info : CACHE https://api.nuget.org/v3/vulnerabilities/index.json
info : CACHE https://api.nuget.org/v3-vulnerabilities/2025.01.23.05.36.26/vulnerability.base.json
info : CACHE https://api.nuget.org/v3-vulnerabilities/2025.01.23.05.36.26/2025.01.23.17.36.28/vulnerability.update.json
info : Package 'Newtonsoft.Json' is compatible with all the specified frameworks in project 'C:\work\Autofac\Autofac.csproj'.
info : PackageReference for package 'Newtonsoft.Json' version '13.0.3' added to file 'C:\work\Autofac\Autofac.csproj'.
info : Writing assets file to disk. Path: C:\work\Autofac\obj\project.assets.json
log : Restored C:\work\Autofac\Autofac.csproj (in 181 ms).
C:\work\Autofac>
I have the following SDKs installed:
C:\work\Autofac> dotnet --list-sdks
3.0.103 [C:\Program Files\dotnet\sdk]
5.0.408 [C:\Program Files\dotnet\sdk]
6.0.428 [C:\Program Files\dotnet\sdk]
8.0.206 [C:\Program Files\dotnet\sdk]
8.0.300 [C:\Program Files\dotnet\sdk]
8.0.403 [C:\Program Files\dotnet\sdk]
9.0.102 [C:\Program Files\dotnet\sdk]
C:\work\Autofac>
And the generated project is:
C:\work\Autofac> cat .\Autofac.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>
C:\work\Autofac>
Now, I can change net9.0 to net8.0, but the result will be the same:
C:\work\Autofac> del -r .\Autofac.csproj
C:\work\Autofac> dotnet new console -n Autofac -o . -f net8.0 --force
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring C:\work\Autofac\Autofac.csproj:
Restore succeeded.
C:\work\Autofac [master +0 ~2 -1 !]> cat .\Autofac.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
C:\work\Autofac> dotnet add package Autofac
Build succeeded in 0.7s
info : X.509 certificate chain validation will use the default trust store selected by .NET for code signing.
info : X.509 certificate chain validation will use the default trust store selected by .NET for timestamping.
info : Adding PackageReference for package 'Autofac' into project 'C:\work\Autofac\Autofac.csproj'.
info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/autofac/index.json
info : Restoring packages for C:\work\Autofac\Autofac.csproj...
info : GET https://api.nuget.org/v3/vulnerabilities/index.json
info : OK https://api.nuget.org/v3/vulnerabilities/index.json 105ms
info : GET https://api.nuget.org/v3-vulnerabilities/2025.01.23.05.36.26/vulnerability.base.json
info : GET https://api.nuget.org/v3-vulnerabilities/2025.01.23.05.36.26/2025.01.23.17.36.28/vulnerability.update.json
info : OK https://api.nuget.org/v3-vulnerabilities/2025.01.23.05.36.26/vulnerability.base.json 42ms
info : OK https://api.nuget.org/v3-vulnerabilities/2025.01.23.05.36.26/2025.01.23.17.36.28/vulnerability.update.json 82ms
error: The given key '(Autofac, 8.2.0)' was not present in the dictionary.
C:\work\Autofac>
What is going on?
EDIT 1
Clearing the cache does not help:
C:\work\Autofac> dotnet nuget locals all --clear
Clearing NuGet HTTP cache: C:\Users\p11f70f\AppData\Local\NuGet\v3-cache
Clearing NuGet global packages folder: C:\Users\p11f70f\.nuget\packages\
Clearing NuGet Temp cache: C:\Users\p11f70f\AppData\Local\Temp\NuGetScratch
Clearing NuGet plugins cache: C:\Users\p11f70f\AppData\Local\NuGet\plugins-cache
Local resources cleared.
C:\work\Autofac> dotnet add package Autofac
Build succeeded in 0.9s
info : X.509 certificate chain validation will use the default trust store selected by .NET for code signing.
info : X.509 certificate chain validation will use the default trust store selected by .NET for timestamping.
info : Adding PackageReference for package 'Autofac' into project 'C:\work\Autofac\Autofac.csproj'.
info : GET https://api.nuget.org/v3/registration5-gz-semver2/autofac/index.json
info : OK https://api.nuget.org/v3/registration5-gz-semver2/autofac/index.json 65ms
info : Restoring packages for C:\work\Autofac\Autofac.csproj...
info : GET https://api.nuget.org/v3-flatcontainer/autofac/index.json
info : OK https://api.nuget.org/v3-flatcontainer/autofac/index.json 34ms
info : GET https://api.nuget.org/v3-flatcontainer/autofac/8.2.0/autofac.8.2.0.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/autofac/8.2.0/autofac.8.2.0.nupkg 40ms
info : GET https://api.nuget.org/v3-flatcontainer/system.diagnostics.diagnosticsource/index.json
info : OK https://api.nuget.org/v3-flatcontainer/system.diagnostics.diagnosticsource/index.json 31ms
info : GET https://api.nuget.org/v3-flatcontainer/system.diagnostics.diagnosticsource/8.0.1/system.diagnostics.diagnosticsource.8.0.1.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/system.diagnostics.diagnosticsource/8.0.1/system.diagnostics.diagnosticsource.8.0.1.nupkg 16ms
info : Installed Autofac 8.2.0 from https://api.nuget.org/v3/index.json to C:\Users\p11f70f\.nuget\packages\autofac\8.2.0 with content hash T+4+W4byzyUOarCbIcFRbxpYKC+cndfQm/+VeWpB60P2MCN0JMsewUhZqvH5Ooe936HQjn5uHvEY9tq6BfbiIw==.
info : Installed System.Diagnostics.DiagnosticSource 8.0.1 from https://api.nuget.org/v3/index.json to C:\Users\p11f70f\.nuget\packages\system.diagnostics.diagnosticsource\8.0.1 with content hash vaoWjvkG1aenR2XdjaVivlCV9fADfgyhW5bZtXT23qaEea0lWiUljdQuze4E31vKM7ZWJaSUsbYIKE3rnzfZUg==.
info : GET https://api.nuget.org/v3/vulnerabilities/index.json
info : OK https://api.nuget.org/v3/vulnerabilities/index.json 38ms
info : GET https://api.nuget.org/v3-vulnerabilities/2025.01.24.05.38.39/vulnerability.base.json
info : GET https://api.nuget.org/v3-vulnerabilities/2025.01.24.05.38.39/2025.01.24.05.38.39/vulnerability.update.json
info : OK https://api.nuget.org/v3-vulnerabilities/2025.01.24.05.38.39/vulnerability.base.json 48ms
info : OK https://api.nuget.org/v3-vulnerabilities/2025.01.24.05.38.39/2025.01.24.05.38.39/vulnerability.update.json 88ms
error: The given key '(Autofac, 8.2.0)' was not present in the dictionary.
C:\work\Autofac>
EDIT 2
So I added the global.json file to force SDK version 8 and lo and behold - a different error is encountered:
C:\work\Autofac> cat .\Global.json
{
"sdk": {
"version": "8.0.403",
"rollForward": "latestFeature"
}
}
C:\work\Autofac> dotnet add package Autofac
Determining projects to restore...
Writing C:\Users\p11f70f\AppData\Local\Temp\tmpnmx32r.tmp
info : X.509 certificate chain validation will use the default trust store selected by .NET for code signing.
info : X.509 certificate chain validation will use the default trust store selected by .NET for timestamping.
info : Adding PackageReference for package 'Autofac' into project 'C:\work\Autofac\Autofac.csproj'.
info : GET https://api.nuget.org/v3/registration5-gz-semver2/autofac/index.json
info : OK https://api.nuget.org/v3/registration5-gz-semver2/autofac/index.json 228ms
info : Restoring packages for C:\work\Autofac\Autofac.csproj...
error: NU1108: Cycle detected.
error: Autofac -> Autofac (>= 8.2.0).
info : Package 'Autofac' is compatible with all the specified frameworks in project 'C:\work\Autofac\Autofac.csproj'.
error: Value cannot be null. (Parameter 'path1')
C:\work\Autofac>
This is weird. I checked the Autofac nuspec file and did not find anything suspicious.
This appears to be related to the name of the project. My guess is that because the project has the same name as the NuGet package, it's getting confused about which "Autofac" library you're talking about.
If you use a different name for the project, it works just fine.
PS C:\Source\Autofac> dotnet new console -n Autofac2 -o .
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring C:\Source\Autofac\Autofac2.csproj:
Restore succeeded.
PS C:\Source\Autofac> dotnet add package Autofac
Build succeeded in 0.4s
info : X.509 certificate chain validation will use the default trust store selected by .NET for code signing.
info : X.509 certificate chain validation will use the default trust store selected by .NET for timestamping.
info : Adding PackageReference for package 'Autofac' into project 'C:\Source\Autofac\Autofac2.csproj'.
info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/autofac/index.json
info : Restoring packages for C:\Source\Autofac\Autofac2.csproj...
info : CACHE https://api.nuget.org/v3/vulnerabilities/index.json
info : CACHE https://api.nuget.org/v3-vulnerabilities/2025.01.24.05.38.39/vulnerability.base.json
info : CACHE https://api.nuget.org/v3-vulnerabilities/2025.01.24.05.38.39/2025.01.24.17.38.40/vulnerability.update.json
info : Package 'Autofac' is compatible with all the specified frameworks in project 'C:\Source\Autofac\Autofac2.csproj'.
info : PackageReference for package 'Autofac' version '8.2.0' added to file 'C:\Source\Autofac\Autofac2.csproj'.
info : Writing assets file to disk. Path: C:\Source\Autofac\obj\project.assets.json
log : Restored C:\Source\Autofac\Autofac2.csproj (in 117 ms).