Вопрос

I need to create a COM wrapper for a NET API dll, to use it in MS Access. The NET API DLL I need to create COM wrapper for uses Newtonsoft.Json.dll

So I have he following DLL's

  1. my.dll (COM-enabled DLL exposing few methods to be used in COM Client - MS Access)
  2. api.dll - native NET DLL exposing an api I need to access in MS Access
  3. newtonsoft.json.dll - used by api.dll

When I call from my COM client (MS Access) a method in my.dll (which calls a method in api.dll) I get the error

Could not load file or assembly Newtonsoft.Json.dll (blah blah) or one of its dependences. The system cannot find the file specified

I tried to copy Newtonsoft.dll and api.dll in system.32, in the same folder with my Access MDB, in MS Access folder. Nothing worked.

I tried to add Newtonsoft to GAC using

gacutil /i newtonsoft.json.dll

which apparently worked, response was

Assembly successfully added to the cache

but when I tried to check if it is there with

gacutil /l newtonsoft.json.dll

I got message: Number of items = 0, so apparently it wasn't added to GAC

Anyway, any suggestion to make this work?

Thanks

Это было полезно?

Решение

I found and solved the problem. When checking the error message more carefully, I noticed it said it cannot load Newtonsoft.Json.dll version 4.5.0 However, in my project I used nuget package for NewtonSoft, which was version 6.0.2

This leaded me to check what actual version of NewtonSoft the api.dll was built against.

Luckily I had access to api dll source, and I noticed it was built against an older version of Newtonsoft, 4.5.0 for NET 3.5

Even if there was the app.config for dll that defined the version redirection, it seems it didn't worked when the COM-enabled DLL was accessed from COM client - MS Access.

But after I rebuilt the api.dll to use the actual current version of NewtonSoft dll, all started to work ok even from COM call

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top