Hi,
From your description, changing package versions in both solutions only “works” temporarily because you’re manually shuffling assemblies instead of letting the build system resolve them properly. Manual copying of compiled framework/BCL DLLs causes your net472 libraries to embed a reference the .NET 9 runtime cannot satisfy. Modern .NET does not apply binding redirects to core assemblies as exact assembly version must match.
Key distinction:
NuGet package version 9.0.11 ≠ assembly version 9.0.0.11. Official builds keep the assembly version at 9.0.0.0. So a request for 9.0.0.11 indicates a nonstandard or stale copy was used when compiling.
Verify this first: Inspect a failing library from Solution 1 (replace path):
dotnet tool install --global dotnet-ildasm # once
dotnet ildasm -t .\Assemblies\YourLibrary.dll | grep System.Text.Json
- If you see .ver 9:0:0:11 you must rebuild that library (no fix solely in Solution 2).
- If you see .ver 9:0:0:0 then the runtime error is due to a copied/extra System.Text.Json DLL in Solution 2—remove the copy.
Search for stray copies:
find . -name System.Text.Json.dll
Remove any you manually placed in Solution 2.
I suggest this approach:
Multi‑target the libraries in Solution 1 so Solution 2 consumes a native net9.0 build (or netstandard2.0 if you prefer)—not the legacy net472 binary. Only add the System.Text.Json package for targets where it is not inbox (net472 / netstandard2.0). Let .NET 9 use the runtime’s built‑in assembly. Stop copying any System.* / Microsoft.* DLLs between solutions.
This should achieve:
- Eliminates the dependency on
System.Text.Json, Version=9.0.0.11. - Lets Solution 2 reference a build compiled directly against the .NET 9 reference pack (
System.Text.Jsonassembly version 9.0.0.0). - Removes the need for “version juggling.”
- Prevents future NuGet updates from breaking runtime loading.
<Project Sdk="Microsoft.NET.Sdk">
<TargetFrameworks>net472;netstandard2.0;net9.0</TargetFrameworks>
<!-- System.Text.Json only where not inbox -->
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="9.0.11"
Condition="'$(TargetFramework)' != 'net9.0'"
PrivateAssets="all" />
</ItemGroup>
</Project>
Notes:
-
netstandard2.0gives broad reuse; keepnet472for existing consumers. -
net9.0build will NOT pull the package; it uses the runtime copy. -
PrivateAssets="all"prevents the package from flowing transitively upward unnecessarily.
Web App (Solution 2) Project File
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\\Solution1\\YourSharedLibrary.csproj" />
</ItemGroup>
</Project>
Migration Steps
- Update each Solution 1 library to multi‑target as shown.
- Remove the “Assemblies” folder copies of
System.*,Microsoft.*,System.Text.Json.dllfrom Solution 2 (keep only proprietary company DLLs until they’re also multi‑targeted). - Replace file
<Reference>entries in Solution 2 with<ProjectReference>. - Delete all
binandobjfolders (both solutions). - Rebuild.