ShopifySharp
ShopifySharp copied to clipboard
System.Text.Json, Version=7.0.0.0 reference problem
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!
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.
@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!
@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
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?
I’m using .Net Framework 4.7.2. (I’ve tried an assembly redirection within my app.config file, but that hasn’t helped.)
From: Joshua Harms @.> Sent: Tuesday, February 13, 2024 2:28 PM To: nozzlegear/ShopifySharp @.> Cc: Allister Chambers @.>; Comment @.> Subject: Re: [nozzlegear/ShopifySharp] System.Text.Json, Version=7.0.0.0 reference problem (Issue #1013)
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?
— Reply to this email directly, view it on GitHubhttps://eu-west-1.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL25venpsZWdlYXIvU2hvcGlmeVNoYXJwL2lzc3Vlcy8xMDEzI2lzc3VlY29tbWVudC0xOTQxNjM3OTcy&i=NjE1NDg5YTdjN2Y4M2IwZTU5NGE4MGJk&t=L0lSK3IzS3k2UHFqV3ZQeWxxZ1dNbDRIaTllbXc4dHJtNTgxek9KMXJBUT0=&h=f9ab86eb6005434ebb12a76053b996f4&s=AVNPUEhUT0NFTkNSWVBUSVa7Z56Wl0HUa2InR2X4iZf_VhFb887oT0fj-Wj-_R9rEA, or unsubscribehttps://eu-west-1.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL25vdGlmaWNhdGlvbnMvdW5zdWJzY3JpYmUtYXV0aC9CR0Q2TDZNVjJHWlMyUkpCUEtEV0RIRFlUTjJBREFWQ05GU002QUFBQUFCQzVGTllRQ1ZISTJEU01WUVdJWDNMTVY0M09TTFRPTjJXS1EzUE5WV1dLM1RVSE1ZVFNOQlJHWVpUT09KWEdJ&i=NjE1NDg5YTdjN2Y4M2IwZTU5NGE4MGJk&t=cmZieW1JdnlHTkR2TThUOTFlODl3bW1OanlJSWc4YWwvL1VrcHVob210VT0=&h=f9ab86eb6005434ebb12a76053b996f4&s=AVNPUEhUT0NFTkNSWVBUSVa7Z56Wl0HUa2InR2X4iZf_VhFb887oT0fj-Wj-_R9rEA. You are receiving this because you commented.Message ID: @.@.>>
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
<assemblyBinding> .. 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>
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?
@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.
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.'
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!
@bobhuang1 awesome, that worked. Thank you