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

Can no longer compile any project after upgrading from .NET 9.0 Preview 7 to .NET 9.0 RC1 #43339

Closed
MarkCiliaVincenti opened this issue Sep 11, 2024 · 37 comments
Assignees
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@MarkCiliaVincenti
Copy link

The steps I took:

  • Uninstall .NET 9.0 Preview 7
  • Install .NET 9.0 RC1
  • Upgrade Visual Studio 2022 to the latest version

Every project I try compiling I'm getting this error even though it's not referencing System.Text.Json, even transitively.

C:\Program Files\dotnet\sdk\9.0.100-rc.1.24452.12\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1060: Error reading assets file: Error loading lock file 'C:[....]\obj\project.assets.json' : Could not load file or assembly 'System.Text.Json, Version=8.0.0.4, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

I tried redownloading and reinstalling, repairing, deleted the NuGet package cache, manually deleted the bin and obj folders, rebooted the PC... basically everything I could think of

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Sep 11, 2024
@Youssef1313
Copy link
Member

We are encountering this in Uno Platform as well once we updated to RC1

@MarkCiliaVincenti
Copy link
Author

MarkCiliaVincenti commented Sep 11, 2024

What I find strange is the version number. Should it really be 8.0.0.4? The latest stable NuGet package version is 8.0.4

@MarkCiliaVincenti
Copy link
Author

We are encountering this in Uno Platform as well once we updated to RC1

Only in Uno Platform though? I'm having this issue in every project. I can start a new solution, add a class library with nothing in it, try to compile and I get that error.

@Youssef1313
Copy link
Member

It shouldn't be specific to Uno Platform, just mentioning that we are also unable to upgrade to RC1 due to this issue

@Youssef1313
Copy link
Member

This may be related to #40645 ?

cc @Forgind

@MarkCiliaVincenti
Copy link
Author

Quite likely, possibly this commit: 337965f

In my SDK folder I have 8 files called System.Text.Json.dll

Four are file version 9.0.24.43107
Two are file version 8.0.724.31311 with a file size of 628 KB
Two are also file version 8.0.724.31311 but have a file size of 566 KB

None of them are 8.0.0.4

@KalleOlaviNiemitalo
Copy link
Contributor

KalleOlaviNiemitalo commented Sep 11, 2024

What I find strange is the version number. Should it really be 8.0.0.4? The latest stable NuGet package version is 8.0.4

https://nuget.info/packages/System.Text.Json/8.0.4 shows lib/net8.0/System.Text.Json.dll with full name System.Text.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, not assembly version 8.0.0.4. The file version 8.0.724.31311 does not matter for the assembly load error.

https://nuget.info/packages/System.Text.Json/9.0.0-rc.1.24431.7 shows both lib/net8.0/System.Text.Json.dll and lib/net9.0/System.Text.Json.dll with full name System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 and file version 9.0.24.43107. I suppose this could be suitable for the referenced assembly version 8.0.0.4 if there were an assembly binding redirection.

@wanggangzero
Copy link

wanggangzero commented Sep 11, 2024

I meet this problem too!
to avoid this Exception, you can place a global.json in your project's root folder to specify the version of sdk 8.0.401

@MarkCiliaVincenti
Copy link
Author

I meet this problem too! to avoid this Exception, you can place a global.json to specify the version sdk 8.0.401

But then you wouldn't be able to compile .NET 9 projects, no?

@wanggangzero
Copy link

I meet this problem too! to avoid this Exception, you can place a global.json to specify the version sdk 8.0.401

But then you wouldn't be able to compile .NET 9 projects, no?

Yes! I think you can down grade it to preview7 first.

@Youssef1313
Copy link
Member

Looks like it's a known issue: https://github.com/dotnet/core/pull/9489/files

@MarkCiliaVincenti
Copy link
Author

I hoped this App.config would help but it really didn't. Maybe I am missing something.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<runtime>
		<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
			<dependentAssembly>
				<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" />
				<bindingRedirect oldVersion="8.0.0.4" newVersion="9.0.0.0" />
			</dependentAssembly>
		</assemblyBinding>
	</runtime>
</configuration>

@MarkCiliaVincenti
Copy link
Author

I confirm that this is a Visual Studio issue. I was able to dotnet pack the same project that Visual Studio 2022 couldn't.

@KalleOlaviNiemitalo
Copy link
Contributor

@MarkCiliaVincenti, which App.config file did you modify? It might need to be devenv.exe.config of Visual Studio but I'm not sure.

@MarkCiliaVincenti
Copy link
Author

@MarkCiliaVincenti, which App.config file did you modify? It might need to be devenv.exe.config of Visual Studio but I'm not sure.

Interesting, but I'm not sure what I'm supposed to do here.

I tried this but it didn't work:

        <dependentAssembly>
          <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
          <bindingRedirect oldVersion="4.0.0.0-8.0.0.3" newVersion="8.0.0.3" />
          <codeBase version="8.0.0.3" href="PublicAssemblies\System.Text.Json.dll" />
        </dependentAssembly>

to:

        <dependentAssembly>
          <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
          <bindingRedirect oldVersion="4.0.0.0-8.0.0.4" newVersion="8.0.0.3" />
          <codeBase version="8.0.0.3" href="PublicAssemblies\System.Text.Json.dll" />
        </dependentAssembly>

@leppie
Copy link

leppie commented Sep 11, 2024

Moved to #43356

@rainersigwald
Copy link
Member

This is a known issue with the combination of Visual Studio 17.11 and .NET SDK 9.0.100-rc.1. It will be addressed in a future Visual Studio 17.11.x release.

Per the .NET SDK support matrix, you must use Visual Studio 17.12-preview to target .NET 9 from within Visual Studio. That’s the best way to get things working today.

To target .NET 8 or lower, there are a couple of workaround options while you wait for the fix (dotnet/msbuild#10650) to be available:

  1. Use a global.json to continue using the 8.0 SDK even when .NET 9.0.100-rc.1 is installed.
  2. an ugly workaround I'll post in a minute after I double-check it.

@rainersigwald
Copy link
Member

@leppie please file a separate issue, that doesn't sound like this one.

@leppie
Copy link

leppie commented Sep 11, 2024

@leppie please file a separate issue, that doesn't sound like this one.

Done #43356

And funny enough, I just ran into THIS issue now (msbuild) due to not having VS preview. Was working before.

@Youssef1313
Copy link
Member

you must use Visual Studio 17.12-preview to target .NET 9 from within Visual Studio. That’s the best way to get things working today.

@rainersigwald The problem for us is mostly with CI scenarios where hosted agents don't yet contain 17.12. If there are ugly workarounds to use rc1 with 17.11.2 (e.g, messing up with System.Text.Json in the .NET installation or really anything else), we'd love to hear.

@rainersigwald
Copy link
Member

If there are ugly workarounds to use rc1 with 17.11.2 (e.g, messing up with System.Text.Json in the .NET installation or really anything else), we'd love to hear.

working on it

rainersigwald added a commit to dotnet/msbuild that referenced this issue Sep 11, 2024
This works around dotnet/sdk#43339 by preloading a copy of the assembly
that can't be located with the normal load processes. It should be
harmless (other than wasting time) in circumstances where it's not
necessary.
@rainersigwald
Copy link
Member

Workaround

This workaround can be checked into any affected repo, but should be removed as soon as possible.

Add the following to a Directory.Build.targets or another file that's imported into every project in your repo:

  <!-- BEGIN workaround for https://github.com/dotnet/sdk/issues/43339; remove after updated to VS 17.12 or a future 17.11 patch -->
  <Target Name="WorkaroundDotnetSdk43339" BeforeTargets="ResolvePackageAssets" Condition=" '$(MSBuildRuntimeType)' == 'Full' and $([MSBuild]::VersionLessThan($(MSBuildVersion), 17.12.0))">
    <PrimeSystemTextJson804 />
  </Target>
  <UsingTask
    TaskName="PrimeSystemTextJson804"
    TaskFactory="RoslynCodeTaskFactory"
    AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
    <Task>
      <Code Type="Fragment" Language="cs">
<![CDATA[
try
{
    System.Reflection.Assembly.LoadFrom(@"$(MicrosoftNETBuildTasksDirectoryRoot)\..\..\..\DotnetTools\dotnet-format\BuildHost-net472\System.Text.Json.dll");
}
catch
{
    // Best effort: if something moves in the SDK don't break the build.
}
]]>
      </Code>
    </Task>
  </UsingTask>
  <!-- END workaround for https://github.com/dotnet/sdk/issues/43339 -->

It's working for the MSBuild repo; see dotnet/msbuild#10643.

@mfeemster
Copy link

Can confirm. I was eager to try .NET 9 RC 1 but nothing will build in Visual Studio 2022 Community edition now.

@MarkCiliaVincenti
Copy link
Author

Since Visual Studio 2022 v17.11.4 is out, this problem is fixed.

@baronfel baronfel unpinned this issue Sep 30, 2024
@baronfel baronfel pinned this issue Sep 30, 2024
@baronfel baronfel unpinned this issue Sep 30, 2024
andrewlock added a commit to DataDog/dd-trace-dotnet that referenced this issue Oct 25, 2024
andrewlock added a commit to DataDog/dd-trace-dotnet that referenced this issue Oct 28, 2024
andrewlock added a commit to DataDog/dd-trace-dotnet that referenced this issue Oct 28, 2024
andrewlock added a commit to DataDog/dd-trace-dotnet that referenced this issue Oct 28, 2024
andrewlock added a commit to DataDog/dd-trace-dotnet that referenced this issue Oct 29, 2024
andrewlock added a commit to DataDog/dd-trace-dotnet that referenced this issue Oct 30, 2024
andrewlock added a commit to DataDog/dd-trace-dotnet that referenced this issue Oct 31, 2024
andrewlock added a commit to DataDog/dd-trace-dotnet that referenced this issue Nov 1, 2024
andrewlock added a commit to DataDog/dd-trace-dotnet that referenced this issue Nov 1, 2024
@skyslide22
Copy link

Still occours on azure using a .net8 web app which used msbuild .net9 for compiling on AZURE
Deleted obj & bin folders, global.json, env DOTNET_VERSION 8.0, nuget cache clearing - nothing helped.

Solution

Deleting the dev slot on the azure portal and deploying on a brand new slot solved the issue.

For the ones who might end up here having the same issue ^^

@codethisio
Copy link

Still occours on azure using a .net8 web app which used msbuild .net9 for compiling on AZURE Deleted obj & bin folders, global.json, env DOTNET_VERSION 8.0, nuget cache clearing - nothing helped.

Solution

Deleting the dev slot on the azure portal and deploying on a brand new slot solved the issue.

For the ones who might end up here having the same issue ^^

Unfortunately, we still got the same error on a brand new slot. I'm hoping the Azure/.NET folks eventually get this sorted. We normally stay on LTS versions but wanted to observe the performance improvements of .NET 9 in a test environment.

@mdgibbons
Copy link

Also getting the same error on a .net6 MVC azure webapp. Yesterday, I added some minor code and pushed it to my Devops repository which is linked via Pipeline to a staging slot on my Webapp (via Deployment Center section). This has all been working fine for many months but yesterday, it started failing.

C:\Program Files (x86)\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1060: Error reading assets file: 
Error loading lock file 'C:\home\site\repository\obj\project.assets.json' : 
Could not load file or assembly 'System.Text.Json, Version=8.0.0.4, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. 
The system cannot find the file specified. [C:\home\site\repository\[MyApp].csproj]
    Done Building Project "C:\home\site\repository\[MyApp].csproj" (default targets) -- FAILED.

I was able to deploy directly from local to a brand new slot on azure like skyslide recommended

@skyslide22
Copy link

skyslide22 commented Nov 25, 2024

Either deploying directly from my machine or making a brand new slot with a new different name than before worked for me on azure

@vedantpatel1997
Copy link

@mdgibbons assuming this is a Windows Web App, the error message indicates that your application is using SDK version 9.0.100. You can specify an earlier SDK version for the web app manually.

To do this, follow these steps:

  1. Create a file named global.json and include the following content:
    { "sdk": { "version": "8.0.400" } }
  2. Add this file to your web app's site folder.

By doing this, the Azure Web App will use the specified .NET SDK version (8.0.400).
This might help you resolved the issue.

@han-so1omon
Copy link

I am getting this same issue when deploying to an Azure Function App. We are upgrading from net6.0 to net8.0 with the isolated worker model. The function app is configured to use .NET 8 Isolated. dotnet list package --outdated shows no outdated packages. When I try to add global.json with { "sdk": { "version": "8.0.400" } } at project root, I get an error stating A compatible .NET SDK was not found.

Anyone else with this issue in an Azure Function App?

@alkampfergit
Copy link

alkampfergit commented Nov 28, 2024

After I compiled the first project with .NET 9 in our build servers (Azure DevOps Pipeline) the code starts failing with that error. Using a global.json fixed everything that still uses .NET 8, but we are unable to compile anything that target .NET 9. Everything runs fine locally to all developers of the team. I've tried putting the workaround in the Directory.Build.targets, but it does not work.

The only thing that seemed to work was installing vs preview on build servers.

C:\fast\_work\_tool\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1060: Error reading assets file: Error loading lock file 'C:\fast\_work\517\s\src\Common\Jarvis.DocumentStore2.Host.FullFw\obj\project.assets.json' : Could not load file or assembly 'System.Text.Json, Version=8.0.0.4, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. [C:\fast\_work\517\s\src\Common\Jarvis.DocumentStore2.Host.FullFw\Jarvis.DocumentStore2.Host.FullFw.csproj]
Unable to build solution Jarvis.DocumentStore2.Host.FullFw.cspro

@scottfavre
Copy link

Just updated to latest VS (v17.12.3) and am now seeing this error for any project targeting .NET 8:

error NETSDK1060: Error reading assets file: Error loading lock file 'C:\path\to\project\obj\project.assets.json' : Could not load file or assembly 'System.Text.Json, Version=8.0.0.4, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

JanKrivanek pushed a commit to dotnet/msbuild that referenced this issue Dec 10, 2024
* Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 10000931 (#10267)

* Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 9752299
* Increase VersionPrefix version

---------

Co-authored-by: Jenny Bai <[email protected]>

* [17.11] Fix component governance alerts (#10520)

* Resolves CG alerts
---------

Co-authored-by: Rainer Sigwald <[email protected]>

* Assembly redirect fix (#10624)

* Fixing the assembly redirect

* [vs17.11] Update dependencies from dotnet/arcade (#10654)

* Update dependencies from https://github.com/dotnet/arcade build 20240910.4

Microsoft.SourceBuild.Intermediate.arcade , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.24311.3 -> To Version 8.0.0-beta.24460.4

* version bump

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Mariana Garces Dematte <[email protected]>

* Upgrade system.text.json to 8.0.4 (#10650)

Will address dotnet/sdk#43339 when deployed in VS.

---------

Co-authored-by: Rainer Sigwald <[email protected]>

* disable loc (#10693)

Part of: #10665

Disabling localization for 17.11.

* [vs17.11] Update dependencies from dotnet/arcade (#10691)

* [vs17.11] Update dependencies from dotnet/arcade (#10793)

* Update dependencies from https://github.com/dotnet/arcade build 20241008.1

Microsoft.SourceBuild.Intermediate.arcade , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.24475.3 -> To Version 8.0.0-beta.24508.1

* bump the version

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: YuliiaKovalova <[email protected]>

* CG alert cleaning on VS17.11 (#10723)

* Bump Microsoft.IO.Redist to 6.0.1
* Bump version prefix to 17.11.11

* [vs17.11] Update dependencies from dotnet/arcade (#10832)

* [vs17.11] Update dependencies from dotnet/arcade (#10895)

* [vs17.11] Update dependencies from dotnet/arcade (#10990)

* Update dependencies from https://github.com/dotnet/arcade build 20241112.12

Microsoft.SourceBuild.Intermediate.arcade , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.24525.2 -> To Version 8.0.0-beta.24562.12

* Update VersionPrefix to 17.11.16

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Gang Wang <[email protected]>

* Update dependencies from https://github.com/dotnet/arcade build 20241120.5

Microsoft.SourceBuild.Intermediate.arcade , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.24562.12 -> To Version 8.0.0-beta.24570.5

* Update VersionPrefix to 17.11.17

* [vs17.11] Run tests even if version is not bumped (#11060)

Backport of #11042 to vs17.11

* [vs17.11] Backport VS insertion pipeline YMLs (#11064)

Co-authored-by: Jan Provaznik <[email protected]>

* Eliminate the unnecessary change from vs17.11

* Remove duplicate version setting for System.Formats.Asn1

* Bump up version prefix to 17.12.18

---------

Co-authored-by: dotnet bot <[email protected]>
Co-authored-by: Jenny Bai <[email protected]>
Co-authored-by: MichalPavlik <[email protected]>
Co-authored-by: Rainer Sigwald <[email protected]>
Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Mariana Garces Dematte <[email protected]>
Co-authored-by: YuliiaKovalova <[email protected]>
Co-authored-by: Gang Wang <[email protected]>
Co-authored-by: Surayya Huseyn Zada <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jan Provaznik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests