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

System.Text.Json, Version=7.0.0.0 reference problem #1013

Open
bobhuang1 opened this issue Feb 7, 2024 · 11 comments
Open

System.Text.Json, Version=7.0.0.0 reference problem #1013

bobhuang1 opened this issue Feb 7, 2024 · 11 comments

Comments

@bobhuang1
Copy link

bobhuang1 commented Feb 7, 2024

I have an Azure server timed function that uses ShopifySharp, and it's been working fine with 6.4.0, and after upgrading to 6.6.0, I started getting these errors on the function during a read function of Stripe webhook posted message (I am using both Stripe and Shopify in the same app!):

        json = await new StreamReader(req.Body).ReadToEndAsync();

Could not load file or assembly 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

It seems 6.4.0 was using System.Text.Json 4.7.2 as a transitive package and 6.6.0 is using System.Text.Json 7.0.3.

Here's a list of all JSON related packages and versions for my working configuration with ShopifySharp 6.4.0.
Newtonsoft.Json 13.0.3
Newtonsoft.Json.Schema 3.0.15
Stubble.Extensions.JsonNet 1.2.3
Microsoft.AspNetCore.JsonPatch 2.1.0
Microsoft.AspNetCore.Mvc.Formatters.Json 2.1.0
Microsoft.Extensions.Configuration.Json 2.1.0
NewtonsoftJson.Bson 1.1.0
System.Text.Json 4.7.2

Thanks!

@nozzlegear
Copy link
Owner

Hey @bobhuang1! Sorry it took so long to get to you, I missed the email from Github. Did you manage to get this working? Assembly version mismatches are always frustrating to deal with, and I'm not great at resolving them personally. I think first I'd try to upgrade to the latest version of ShopifySharp and see if that solves the problem. We're on version 6.13.0 right now, so maybe updating to that will clear up any issues. Otherwise you might try your luck with installing the exact version that ShopifySharp uses, which is System.Text.Json 7.0.3.

@bobhuang1
Copy link
Author

@nozzlegear Thank you so much for getting back to me so quickly. Unfortunately I have tried both the latest build 6.13.0 and installing System.Text.Json 7.0.3 (and 7.0.0 which the error was asking for forcibly), neither has worked, I will wait and see if someone else sees the same issue or a future version might get this resolved. Thanks again!

@AllisterChambersP
Copy link

AllisterChambersP commented Feb 13, 2024

@nozzlegear I'm seeing the same problem. I've got System.Text.Json 7.0.3 and it worked ok on my Dev system. Failed on the customer's own system. What other libraries might have the wrong version?
Microsoft.Bcl.AsyncInterfaces - 7.0.0
Microsoft.Extensions.Configuration - 2.1.0
Microsoft.Extensions.Configuration.Abstractions - 2.1.0
Microsoft.Extensions.Configuration.Binder - 2.1.0
Microsoft.Extensions.DependencyInjection - Abstractions - 2.1.0
Microsoft.Extensions.Http - 2.1.0
Microsoft.Extensions.Logging - 2.1.0
Microsoft.Extensions.Logging.Abstractions - 2.1.0
Microsoft.Extensions.Primitives - 2.1.0
ShopifySharp - 6.13.0
System.Text.Encodings.Web - 7.0.0
System.Text.Json 7.0.3

@nozzlegear
Copy link
Owner

I think a lot of the Microsoft.Extensions packages use System.Text.Json as well. Which framework are you two using when you see this exception? .NET 4.5, 6, 7, 8, etc?

@AllisterChambersP
Copy link

AllisterChambersP commented Feb 13, 2024 via email

@AllisterChambersP
Copy link

AllisterChambersP commented Feb 13, 2024

I've managed to resolve this - it's now working OK. The steps were:

  • in Visual Studio, change all the library references to set 'Specific Version = False' (Not sure if that was necessary)
  • Copy the .. section from mydll.dll.config into myapp.exe.config
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-7.0.0.3" newVersion="7.0.0.3" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

@nozzlegear
Copy link
Owner

Awesome, glad you got it working! Binding redirects are really frustrating to deal with, hope it didn't cost you too much sanity. 😛

@bobhuang1 If you're using .NET Framework, can you give @AllisterChambersP's solution a try and see if it works for you too?

@bobhuang1
Copy link
Author

@AllisterChambersP @nozzlegear Thank you so much for the pointers, since I have the code as an Azure function (.NET 6.0), binding redirect using config file is not possible, I had tried this suggested solution:
https://codopia.wordpress.com/2017/07/21/how-to-fix-the-assembly-binding-redirect-problem-in-azure-functions/
But that failed with the same error. Looks like I need to look for another solution.

@Uffman
Copy link
Contributor

Uffman commented Feb 23, 2024

Has anyone found a solution to this? I have a problem on .net6.0 with Azure Function v4. Installed System.Text.Json 7.0.3 and it didn't help
Error:
'Could not load file or assembly 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.'

@bobhuang1
Copy link
Author

I got this working with Azure Functions. By adding these:

  <PropertyGroup>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
  </PropertyGroup>

to my csproj file after adding System.Text.Json 7.0.3 or above to the project. Reference here:
https://bryanknox.github.io/2022/07/15/functionsskipcleanoutput-and-functionspreserveddependencies.html

For those who got the same error with regular .NET projects, try the solution by @AllisterChambersP above. It should work. Thanks!

@Uffman
Copy link
Contributor

Uffman commented Feb 23, 2024

@bobhuang1 awesome, that worked. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants