1

I have a COM interface setup between my C# class library and a native executable. The native exe makes a call into the managed module, which should return a string (which is marshalled to a BSTR c++ side). During this call, the following line is hit:

HttpResponseMessage response = await client.PostAsJsonAsync("", data).ConfigureAwait(false);

When it hits this, it bails. If I remove the line, the code continues. As the result returns a BSTR, upon inspecting the BSTR it reads:

Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

I found that this PostAsJsonAsync comes from System.Net.Http.Formatting

However the error message says Newtonsoft.Json, implying there is some kind of conflict? Yes?

Maybe related: HttpClient PostAsJsonAsync incompatible with Newtonsoft.Json

So I want to understand what I actually happening here. When the native project loads the managed library for COM, does it load the wrong assembly causing a naming conflict with PostAsJsonAsync?? My best guess. Secondly, what is the correct solution?

Thanks,

Edit: Note I am actually using Newton.Json for json serial/deserialization

Community
  • 1
  • 1
friartuck
  • 2,954
  • 4
  • 33
  • 67
  • 1
    Is Newtonsoft.Json in your build output? Is it being deployed correctly? – Brad Mar 21 '16 at 04:44
  • Well it pops up in bin/debug. Interestingly I'm not sure how my native application picks it up since when I register an assembly for COM, doesn't only that single assembly get copied into COM. How does the native application find and load the Newtonosft.Json.dll. Interestingly, I can use other methods from that assembly (e.g. Newtonsoft.Json.JsonConvert) and that works fine through the COM interface. – friartuck Mar 21 '16 at 16:10

0 Answers0