Skip to content

Wrong version for System.Text.Json in nuget package? #78754

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

Closed
adrianm64 opened this issue Nov 23, 2022 · 8 comments
Closed

Wrong version for System.Text.Json in nuget package? #78754

adrianm64 opened this issue Nov 23, 2022 · 8 comments
Labels
area-Infrastructure-libraries needs-author-action An issue or pull request that requires more info or actions from the author.
Milestone

Comments

@adrianm64
Copy link

adrianm64 commented Nov 23, 2022

Description

The nuget package System.Text.Json 6.0.7 has these assembly versions
image

I have a NetStandard 2.0 library using System.Text.Json 6.0.7 and therefore has a dependency on assembly version 6.0.0.0

A .NetFramework 4.8 app depends on the .NetStandard 2.0 library and has an indirect dependency on System.Text.Json 6.0.7 and therefore assembly version 6.0.0.7.

When running the app, the first call into the library fails because it can't find assembly version 6.0.0.0

Reproduction Steps

Create netstandard 2.0 library
add system.text.json 6.0.7

namespace TextJsonLibrary 
{
    public class JsonDto 
    {
        [System.Text.Json.Serialization.JsonPropertyName("prop")]
        public int Prop {get; set;}
    }
}

create netframework 4.8 console app
add library and system.text.json 6.0.7 (or create nuget package from library and add)

namespace TextJsonApp 
{
    public static class Program()
    {
       public static void Main()
       { 
           var x = new TextJsonLibrary.JsonDto();
       }
    }
}

Expected behavior

No error

Actual behavior

System.TypeInitializationException: The type initializer for 'xxx' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Text.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).

Regression?

I have only used the 5.0.0 and 6.0.0 versions before and there all assembly versions are the same.

Checked some older nuget packages in 5.x and 6.x and all .NetFramework assemblies have different versions.

Known Workarounds

Downgrade the package in the .NetFramework app to 6.0.0 which contain a .NetFramework assembly with version 6.0.0.0

Configuration

No response

Other information

No response

@ghost ghost added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Nov 23, 2022
@ghost
Copy link

ghost commented Nov 23, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

The nuget package System.Text.Json 6.0.7 has these assembly versions
image

I have a NetStandard 2.0 library using System.Text.Json 6.0.7 and therefore has a dependency on assembly version 6.0.0.0

A .NetFramework 4.8 app depends on the .NetStandard 2.0 library and has an indirect dependency on System.Text.Json 6.0.7 and therefore assembly version 6.0.0.7.

When running the app, the first call into the library fails because it can't find assembly version 6.0.0.0

Reproduction Steps

Create netstandard 2.0 library
add system.text.json 6.0.7

namespace TextJsonLibrary 
{
    public class JsonDto 
    {
        [System.Text.Json.Serialization.JsonPropertyName("prop")]
        public int Prop {get; set;}
    }
}

create netframework 4.8 console app
add library and system.text.json 6.0.7 (or create nuget package from library and add)

namespace TextJsonApp 
{
    public static class Program()
    {
        var x = new TextJsonLibrary.JsonDto();
    }
}

Expected behavior

No error

Actual behavior

System.TypeInitializationException: The type initializer for 'TextJsonApp' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Text.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).

Regression?

I have only used the 5.0.0 and 6.0.0 versions before and there all assembly versions are the same.

Checked some older nuget packages in 5.x and 6.x and all .NetFramework assemblies have different versions.

Known Workarounds

Downgrade the package in the .NetFramework app to 6.0.0

Configuration

No response

Other information

No response

Author: adrianm64
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@ghost
Copy link

ghost commented Nov 23, 2022

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

The nuget package System.Text.Json 6.0.7 has these assembly versions
image

I have a NetStandard 2.0 library using System.Text.Json 6.0.7 and therefore has a dependency on assembly version 6.0.0.0

A .NetFramework 4.8 app depends on the .NetStandard 2.0 library and has an indirect dependency on System.Text.Json 6.0.7 and therefore assembly version 6.0.0.7.

When running the app, the first call into the library fails because it can't find assembly version 6.0.0.0

Reproduction Steps

Create netstandard 2.0 library
add system.text.json 6.0.7

namespace TextJsonLibrary 
{
    public class JsonDto 
    {
        [System.Text.Json.Serialization.JsonPropertyName("prop")]
        public int Prop {get; set;}
    }
}

create netframework 4.8 console app
add library and system.text.json 6.0.7 (or create nuget package from library and add)

namespace TextJsonApp 
{
    public static class Program()
    {
       public static void Main()
       { 
           var x = new TextJsonLibrary.JsonDto();
       }
    }
}

Expected behavior

No error

Actual behavior

System.TypeInitializationException: The type initializer for 'TextJsonApp' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Text.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).

Regression?

I have only used the 5.0.0 and 6.0.0 versions before and there all assembly versions are the same.

Checked some older nuget packages in 5.x and 6.x and all .NetFramework assemblies have different versions.

Known Workarounds

Downgrade the package in the .NetFramework app to 6.0.0

Configuration

No response

Other information

No response

Author: adrianm64
Assignees: -
Labels:

area-System.Text.Json, area-Infrastructure, untriaged

Milestone: -

@svick
Copy link
Contributor

svick commented Nov 23, 2022

This should not happen thanks to assembly binding redirects, which should be generated automatically.

Indeed, I can't reproduce this after a fresh build, even after forcing the loading of System.Text.Json by changing the code of the app to _ = typeof(TextJsonLibrary.JsonDto).GetProperty("Prop").CustomAttributes;.

Though I can reproduce it if I delete the .exe.config file, which contains the following section:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.7" newVersion="6.0.0.7" />
  </dependentAssembly>
</assemblyBinding>

Is the "Auto-generate binding redirects" option enabled in your project? What is the contents of your exe.config file?

@adrianm64
Copy link
Author

Thank you for your reply and you are correct of course that binding redirect can solve many assembly versioning problems.

Didn't think about that and should have given more context than the minimal reproduction.

In my environment I don't have access to app.config so binding redirect is not available, i.e. plugins. This of course create various dependency problems which we solve by forcing all our projects to use the same version of dependencies and update them together.

This is the first time we ran into a problem where all assemblies use the same version of all dependencies.

Now I understand why it isn't a more general problem and probably shouldn't be a bug. The workaround of forcing version 6.0.0 works fine for us.

May I ask why only the .NetFramework assemblies have different version numbers?

@ViktorHofer
Copy link
Member

ViktorHofer commented Nov 29, 2022

On .NET Framework, the loader requires exact version matches. If an assembly binds against 6.0.0.0 but at runtime, only 6.0.0.1 is present, the loader fails without binding redirects. This isn't the case on modern .NET (or Core, if you want to call it that), as the loader automatically rolls forward on patch versions.

May I ask why only the .NetFramework assemblies have different version numbers?

.NET Framework assemblies are part of the GAC (Global Assembly Cache). Without updating the package's assembly version, the assembly inside the GAC would win over what's coming via the package. That's basically a caching mechanism.

On the other side, we don't want to rev the version of net6.0 System.Text.Json assembly, as it also ships inside the shared framework. If we would change its version, then newer patched shared framework installation (that ships as part of the .NET SDK) would never win over the package asset.

@ghost
Copy link

ghost commented Nov 29, 2022

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

The nuget package System.Text.Json 6.0.7 has these assembly versions
image

I have a NetStandard 2.0 library using System.Text.Json 6.0.7 and therefore has a dependency on assembly version 6.0.0.0

A .NetFramework 4.8 app depends on the .NetStandard 2.0 library and has an indirect dependency on System.Text.Json 6.0.7 and therefore assembly version 6.0.0.7.

When running the app, the first call into the library fails because it can't find assembly version 6.0.0.0

Reproduction Steps

Create netstandard 2.0 library
add system.text.json 6.0.7

namespace TextJsonLibrary 
{
    public class JsonDto 
    {
        [System.Text.Json.Serialization.JsonPropertyName("prop")]
        public int Prop {get; set;}
    }
}

create netframework 4.8 console app
add library and system.text.json 6.0.7 (or create nuget package from library and add)

namespace TextJsonApp 
{
    public static class Program()
    {
       public static void Main()
       { 
           var x = new TextJsonLibrary.JsonDto();
       }
    }
}

Expected behavior

No error

Actual behavior

System.TypeInitializationException: The type initializer for 'xxx' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Text.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).

Regression?

I have only used the 5.0.0 and 6.0.0 versions before and there all assembly versions are the same.

Checked some older nuget packages in 5.x and 6.x and all .NetFramework assemblies have different versions.

Known Workarounds

Downgrade the package in the .NetFramework app to 6.0.0 which contain a .NetFramework assembly with version 6.0.0.0

Configuration

No response

Other information

No response

Author: adrianm64
Assignees: -
Labels:

area-Infrastructure-libraries, untriaged

Milestone: -

@ViktorHofer ViktorHofer added the needs-author-action An issue or pull request that requires more info or actions from the author. label Nov 29, 2022
@ghost
Copy link

ghost commented Nov 29, 2022

This issue has been marked needs-author-action and may be missing some important information.

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Nov 29, 2022
@adrianm64
Copy link
Author

Thank you for your reply.

I know the background now and will close the issue.
(don't understand how a dll from a nuget package can end up in the GAC but that is an unimportant detail)

@ghost ghost locked as resolved and limited conversation to collaborators Jan 4, 2023
@ericstj ericstj added this to the 6.0.x milestone Jul 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Infrastructure-libraries needs-author-action An issue or pull request that requires more info or actions from the author.
Projects
None yet
Development

No branches or pull requests

5 participants