问题
I have a native client talking to a managed class library via a COM interface.
I am using a project (AutoRest - OS project from MSFT), which appears to take a dependency on NetwtonSoft.JSON. I am calling into this AutoRest project (I'm taking a dependency on AutoRest.Core) with a class library wrapper I've written. This class library wrapper defines a COM interface, which is called from a native application. I built a test client for my client library in C# (.NET), which works fine. However, when I use my COM interface, when it calls some methods from AutoRest.Core I get the exception:
Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
I take this to mean it's trying to find Newtonsoft.JSON.dll (or a dependency of this). My gut tells me it can't find a particular version of Newtonsoft.JSON and/or is getting confused with other versions. I'm guessing this is because my client library has a dependency on Newtonsoft.JSON AND AutoRest (which in turn has a dependency on Newtonsoft.JSON, but a different version). This sound like where this issue is originating from? I've found that I can use Newtonsoft.JSON directly from my class library, but (presumably) any calls to Newtonsoft.JSON from within AutoRest (which my client library wraps), uses a different version of Newtonsoft.JSON, and hence causes this error.
So. how do I correctly deal with this?
I'm not sure what useful information I can give here. Please tell my what is useful in diagnosing this issue. If it helps, under my solution packages folder I have "Newtonsoft.Json.8.0.3". Error messages says it wants version 7. My class library Newtonsoft.JSON dependency is v4.0.30319. I'm not sure what version AutoRest uses, nor
In case it helps: for class library COM project I have "register for COM interop" checked in the project settings. I then generate the IDL from the register COM object, then convert the IDL to a header file which I include in my native project. I create an inproc server COM in the native client (CLSCTX_INPROC_SERVER).
来源:https://stackoverflow.com/questions/36256694/dependency-newtonsoft-json-not-being-loaded-when-exercised-through-my-com-inte