I am using the Microsoft.AspNet.WebApi.Client (Version 5.2.4). Also Newtonsoft.Json is referenced in my project (Version 11.0.2).
I am trying to get the results of a web-service call as follows:
...
using (var client = new HttpClient())
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var content = new StringContent($"grant_type=refresh_token&client_id=sfd34tgregge&client_secret=345534535&refresh_token={refreshToken}", Encoding.UTF8, "application/x-www-form-urlencoded");
var response = await client.PostAsync(url, content);
if (response.IsSuccessStatusCode)
{
var getAccessTokenResult = await response.Content.ReadAsAsync<GetAccessTokenResult>();
...
}
}
...
I can execute this code without any problems when I reference this DLL from a C# application.
When I call the same method via COM I get the following error:
Exception: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system could not find the specified file.
We decorated the class that is accessible via COM in the following way:
[ProgId("MyDll")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class MyDll : IMyDll
{
...
}
We have also set the following in AssemblyInfo.cs:
[assembly: ComVisible(true)]
app.config contains the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>
Why do I get this error message? Why does this try to use Version 6.0.0.0 of Newtonsoft.Json? Why does this work when calling it from a .NET application but not when calling it via COM? What else can I check?
Does the application that references it has the same version of Newtonsoft.json
AND same /compatible version of .NET
?
It's worth checking your packages.config file and your packages folder.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.