West Wind .NET Tools and Demos
Newtonsoft.Json.dll reference can not be resolved
Gravatar is a globally recognized avatar based on your email address. Newtonsoft.Json.dll reference can not be resolved
  Naomi
  All
  Sep 17, 2018 @ 05:12am

I am using wwDotNetBridge. I created a simple .NET dll that sends a request to web page and receives a response. It uses Newtonsoft.Json.dll library.

I'm able to run the test for my project from my solution. However, when I try to use this dll from VFP I'm getting this error: One or more errors occurred. Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

I ran a search online and found several similar threads in Stackoverflow. I tried deleting dlls, tried playing with the config files, etc. - the error persists 😦

What should I do to resolve it? Also, my project uses the latest version which is 11.02. I'm not sure from where this reference is coming from.

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  FoxInCloud Support - Thierry N.
  Naomi
  Sep 17, 2018 @ 05:54am

unless you have a typo, the message references Newtonsoft.Json, not Newtonsoft.dll

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  FoxInCloud Support - Thierry N.
  Sep 17, 2018 @ 08:10am

Thanks, fixed the typo in the title.

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  FoxInCloud Support - Thierry N.
  Sep 17, 2018 @ 09:23am

Actually, now I'm getting the same error from the test (inside the solution) as well:

Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

😦

I was trying to solve the issue and deleted lots of dlls from various locations and then I brought it over from another place.

What should I do to resolve it?

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Rick Strahl
  Naomi
  Sep 17, 2018 @ 10:16am

You need to make sure you have the right version of Newtonsoft.Json. wwDotnetBridge binds to a specific version of this library and if you're accessing a different one it's not going to work unless you set a few configuration settings in the yourApp.exe.config and vfp9.exe.config.

More info here:

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 17, 2018 @ 10:40am

Hi Rick,

Where should I add the reference to my project for this library? I don't see it anywhere 😦 I probably have a bunch in various places, but I don't see it in the Assemblies at all.

What should I do? 😦((((((

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Rick Strahl
  Naomi
  Sep 17, 2018 @ 12:09pm

You shouldn't have to set a reference to that library at all, if your .NET assembly has a reference to it. You need to make sure when you copy (or build) your project to the folder you are consuming the DLL from that it also includes newtonsoft.json.dll as that's a dependency.

If you're using one of the West Wind versions (not the open source one) then you'll need to use the config settings described in the post. Otherwise it should probably just work once your FoxPro code can find the dependency dll(s).

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 17, 2018 @ 01:14pm

Hi Rick,

With the help of my colleague and after using a different laptop I eventually was able to fix my own project (by fixing it on the other laptop, renaming the bad directory on my old laptop, getting from TFS fixed solution) and the test from the project now works fine on both laptops.

However, test from VFP is still failing (and I haven't installed VFP on my new laptop at all). I'm using a test program in VFP development environment and I placed my dll and the newtonsoft.json.dll (latest version 11.0.0.2) into the folder where I'm executing my test program from. I'm still getting that same error which makes no sense at all. In my own solution I have this app.config:

<?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>
</configuration>
Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Naomi
  Sep 17, 2018 @ 01:54pm

Just to be sure, I added loading newtonsoft.json assembly file using LoadAssemly before loading my dll. Both LoadAssembly worked fine, but the method from my class is still failing with the exact same error 😦

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 17, 2018 @ 02:27pm

I'm trying to test from a prg directly from VFP. In my test program I instantiate my class and then from that class I'm running a method which in turn tries to call a method from my .NET class which sends json request and receives back json response. All the dlls are in the same folder from where I'm running this test VFP program. Yet I'm still getting that exact error.

I can only conclude that something is seriously wrong with my local development environment as I was getting that error even from .NET solution itself and had to fix it on the other laptop first.

For now I'm asking my colleague to test if he can get this working. I need to switch to other tasks...

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Rick Strahl
  Naomi
  Sep 17, 2018 @ 02:51pm

Does your code run from .NET? Create a unit test or a console app to make sure that your code actually runs without wwDotnetBridge in the mix.

The issue here is that something is referencing a very old version of Newtonsoft.Json. If it's your code, it shouldn't be referencing this old version but whatever is current (ie. v11.x or so). If there is another dependency that relies on an old version then the redirects are required to ensure that the old versions are forwarding 'pretend' to be of the newer version. But you have to make sure that hte config file is set and that the version you specify there exactly matches the newtonsoft.json.dll that's on disk.

There's nothing wrong with the dev environment - this is a versioning issue with DLLs but these things can be difficult to track down. Also make very sure you have the right version of wwDotnetBridge that you think you are using. If you're using an old version of a West Wind Client Tools/Web Connection those versions a long time ago referenced v6.0 which makes me think maybe there is an old version involved somewhere.

If the code is self-contained maybe create a short sample along with the dependencies and zip it up and post a link (or email if not suitable for public access) and I can take a look.

This defintely should work even with mismatched versions of the json dll (I do it all the time with various Credit Card processing providers that often use old versions of the json dlls).

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 17, 2018 @ 07:20pm

Hi Rick,

When I first read your message, I thought the problem may be coming from the other dll which did have a reference to west wind client tools. So I fixed that project, removed that reference, etc., but the problem persisted. I since then got rid of that dll, but the problem still remains. I created a zip file with my .net dll solution and a simple VFP test program. I'm ready to share it but don't know your email to share with you only.

Thanks a lot in advance.

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Rick Strahl
  Naomi
  Sep 17, 2018 @ 08:55pm

If it's small just send me an email (look at https://west-wind.com/contact/)... probably best if you share it on DropBox or OneDrive if it's sizable.

I may not get to it tomorrow as I'm travelling all day...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 18, 2018 @ 08:55am

Hi Rick,

Once I added the VFP9.exe.config as described in the link you sent me earlier it worked from VFP. I suppose I would need this config for my VFP dll named DllName.dll.config, right?

Thanks again.

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Rick Strahl
  Naomi
  Sep 18, 2018 @ 09:14pm

All this time you didn't add this??? 😱

You need to do this for vfp9.exe.config and for yourApp.exe.config for the deployed compiled application. Not the dlls - that won't work with FoxPro loaded assemblies - all settings have to be in the .exe.config file.

I'm not sure what you mean by your .dll. Are you invoking via COM? If so it'll be the root EXE that has to have it or if running in IIS/ASP.NET in web.config.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 19, 2018 @ 06:51pm

Hi Rick,

We have C++ application that sends invoke strings to VFP dll (this is the one I was talking about which invokes .NET dlls).

So, where I am supposed to add the config file?

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Rick Strahl
  Naomi
  Sep 19, 2018 @ 07:56pm

With the C++ EXE file. IOW, myCppexe.exe.config...

Note that there can be complications with this though because you're basically doing:

c++ -> COM -> FoxPro -> COM -> .NET

FWIW there are relatively easy to use interface for C++ to interact with .NET directly. Maybe that's a cleaner solution than sticking FoxPro into the middle of all this.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 20, 2018 @ 04:17am

Hi Rick,

We have been re-writing VFP dll into C# dll. But most of our clients are still using the VFP dll, so we have to incorporate that .NET into VFP dll for now.

The question I have, though - I sent the link to Boris and he also got that same error. In that link I only had your wwDotNetBridge libraries from the distribution folder which I downloaded very recently + my dll which uses latest Newtonsoft.Json.dll + VFP test program. I sent that link to you too.

So, VFP itself uses older library (is it possible?)? The wwDotNetBridge solution doesn't seem to reference this library at all.

Thanks in advance.

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Rick Strahl
  Naomi
  Sep 20, 2018 @ 05:49pm

Anything loaded from a Zip file and downloaded over the internet has to be unblocked in order to be able to run. Otherwise you'll get security exceptions from Windows. I suspect that's what you're actually seeing. .NET DLLs have to be either copied as part of a proper install (ie. admin rights installed) or you need to unblock.

Other than that if your code runs on one box it should run on another assuming you have the same binaries on both. There's nothing that should be different there assuming you are running the same code. If you're not running the same code, then there's likely something else going on.

Your scenario you are doing is pretty complex and involves several layers of indirection. It can certainly work but you're basically dealing with 4 different environments that are interacting with each other: C++, COM, FoxPro and .NET with COM in between two separate layers. I wouldn't be surprised if there are problems along that path due to various context switches that have to occur.

All that said, if you get this to work on one machine, you should be able to make it work on another but you have to ensure the same configurations are used.

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 20, 2018 @ 06:03pm

Hi Rick,

I think we're going in circles. I downloaded the files, I unblocked them. Then I added my dll into that distribution folder and ran the test VFP program from that folder.

Before I added the vfp.exe.config I was getting that error.

I zipped all of this up and sent you a link as well as I sent this link to Boris and he got that same error message.

My dll uses latest version of newtonsoft. So, forgetting for a moment the complex scenario we're going to use it from, why I and Boris are getting this error in the first place. My colleague also got that exact same error from that test I prepared.

Are you getting this error too if you don't have that VFP exe config with the link I shared?

Thanks.

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Rick Strahl
  Naomi
  Sep 20, 2018 @ 10:37pm

Are you getting this error too if you don't have that VFP exe config with the link I shared?

Yes. As well as it should.

The DLLs you are calling are referencing Newtonsoft.Json.dll version 11.0.0.0. You're using 11.0.2.11.0.2.21924. Those versions are not the same hence the error loading and you need the assembly redirect.

If you want to run without a config file you have to use the same version those DLLs are using which is difficult because they are not available on NuGet. So yes, you have to use a config file with the assembly redirect.

I don't understand your concern here - what's the big deal with adding the config file?

Otherwise get the vendor to actually use a supported version of JSON.NET or use the one that they are most likely providing.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Rick Strahl
  Naomi
  Sep 21, 2018 @ 01:04am

FWIW I simplified your code down to this:

DO wwDotnetBridge
loBridge = CreateObject("wwDotNetBridge","V4")
? loBridge.loadassembly("C:\Temp\projects\NaomiDll\Siriusware.IKON.dll")
oIKONPASS = loBridge.CreateInstance("Siriusware.IKON.IKONPass")
? oIKONPass

And this works running out of the folder and with no vfp9.exe.config present.

I did recompile the wwDotnetBridge.DLL with .NET 4.5.2 - the older version was v4.5. That shouldn't make a difference but it definitely works with this setup.

You might want to pull down the latest ClrHost.dll and wwDotnetBridge.dll files from the Github repo.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 21, 2018 @ 04:29am

Hi Rick,

But why the error is about version 6?

Anyway, I think it is not a big deal to add the config file as long as I understand which config file we would need to distribute. Say, our C++ application is called Sales32.exe and I'm not developing this application. Do I need to make sure that we're using that config file with the Sales32 (which, BTW, is run from different directory from where my VFP dll resides)?

Also, I don't need the VFP9.exe.config to distribute, right?

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 21, 2018 @ 04:32am

I'll get the latest. BTW. I didn't get the error with the createInstance, only when I was trying to run the validate method, I think. This is the method using JSON.

Thanks a lot again.

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Rick Strahl
  Naomi
  Sep 21, 2018 @ 01:58pm

Ah - yeah that makes sense. The Newtonsoft.Json.dll isn't loaded until you access functionaltiy in it, so you won't see the error until you call a method that references it. I just ran your code and I assumed that code would reference the code.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 26, 2018 @ 11:10am

Hi Rick,

My colleague tried to test this dll using a special scanner device. He got the exact same error about Newtonsoft.Json.dll I was getting too.

I'll try to coordinate with my other colleague who probably writes the code for the scanner and see if we would be able to get it resolved.

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Naomi
  Sep 26, 2018 @ 02:20pm

I'm not sure why one dll works and the other doesn't 😦

The one that doesn't work uses static properties and one private static method:

private static async Task GetIkonValidationResultAsync

The working dll doesn't use the static properties (they are private variables) and doesn't use static methods. That's the only difference I can see. I originally coded not working dll exactly as the one which is working, but it didn't work for some reason, so I used the code which is used in many online samples for sending request and receiving a response. Do you think that difference may contribute to this weird issue? 😦( I may try re-writing dll back to be the same as "working" one.

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Naomi
  Sep 26, 2018 @ 02:33pm

I decided to re-run the tests again. I also removed app.config files (as my other dll didn't have them). I got that error again directly by running my tests from the solution itself:

One or more errors occurred. Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Where is this manifest and where does it try to load this version from?????? My reference file is indeed the latest version. I'm trying to figure out what am I missing in my solution? May be I should try to zip my directory in case I could not figure this out?

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Rick Strahl
  Naomi
  Sep 26, 2018 @ 05:00pm

Uh... I told you this exact thing a while back given that you have a non-Nuget version of Newtonsoft.json and the fact that you didn't use the exact version number.

The version numbers have to match exactly to what is installed in the assembly redirection list.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 26, 2018 @ 06:37pm

Rick,

What do you mean by having not nuget version? I uninstall that library using Nuget package manager and then re-installed it again using the manager. So, where the version 6 is coming from?

I just re-tested that version I built today again after removing the vfp9.exe.config and the error is back 😦

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Rick Strahl
  Naomi
  Sep 27, 2018 @ 02:34am

Sorry, I have no idea what you are doing... you keep telling me the same thing over and over it works and then it doesn't. I have no freaking idea what you are doing.

I don't understand your issue. You need to use .config file. Lack of it is the problem.

You likely have some other dependency that pulls in an old version of the JSON dll. Or maybe an old version of wwDotnetBridge? But none of this should matter matter. Just create the .config file for VFP and your app, set the version to whatever the actual dll version is and it will work.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 27, 2018 @ 04:38am

We have the config for our Sales application (even two of them). Still it doesn't work. I don't understand - should I also add VFP9.exe.config into the same directory where we're running our Sales application from? Or in the directory where we have wwDotNetBridge.dll and our .NET dll and our VFP dll calling .NET dll by the means of the wwDotNetBridge?

When I uninstall Newtonsoft.Json.dll from my .NET project using nuget package manager and then install back, the following file is being added into the solution (in both Test and main project even though I only install it into main project):

<?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>
</configuration>

In the packages for the main project I am seeing:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net451" />
  <package id="System.Net.Http" version="4.3.3" targetFramework="net451" />
  <package id="System.Net.Http.Formatting.Extension" version="5.2.3.0" targetFramework="net451" />
</packages>

Packages for the Test project which is also part of my .NET dll solution has the following:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" />
</packages>

even though I'm certain I didn't install Newtonsoft.Json.dll into the Test project.

From the Test menu in VS I just ran both of my tests and they both succeeded.

At this point I want my dll to also work from VFP as is. If I need to distribute config files with our VFP dll which is using this .NET dll I need to know exactly which files they should be and where do I need them placed. We have several applications that interface with these VFP dlls. Most of them are written in C++. The C++ application is installed in its own directory (not the same where we install VFP dlls and other supporting dlls).

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Rick Strahl
  Naomi
  Sep 27, 2018 @ 12:44pm

The version number has to exactly match the version number of the dll. I doubt the version you're running is 11.0.0.0. Look at the properties for the file and look at the version number - that's what has to go into the .config file. Or use Reflector to look at the actual dll resource data.

The .config goes into the same folder as the EXE. They are a matched pair. VFP9.exe.config goes whereever Vfp9.exe lives (in Program Files). You only need this for development when you actually run vfp.exe as your launching exe. Same goes for your EXE - the .config goes into the same folder as the EXE and that's used only when you run the EXE. It's really pretty simple (and outlined in the help topic).

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.dll reference can not be resolved
  Naomi
  Rick Strahl
  Sep 27, 2018 @ 02:43pm

Rick,

This is exactly the point! When I add the dll into the .NET project using nuget package manager, it automatically adds the app.config into the project which I specified. When I look at the Newtonsoft.json.dll in the references using the properties info in VS I see 11.0.0.0 as the version too (even though when I add it using the manager it does say latest stable 11.0.0.2).

So, assuming I'm doing this right question 1:

  1. Do I need to make any adjustments in my .NET dll itself (may be fix its app.config - if yes, what does it need to say)?

  2. From VFP itself it works now OK when I test my code from VFP and have the config VFP9.exe.config in VFP home directory.

  3. It still returns that same stupid error when I ran it using my VFP.dll from our Sales (C++) application. I added config files for RunExe (this is an interface that written in C++ that calls the Sales.exe), I added 2 configs for Sales exe in the directory for the Sales. So far nothing helped. Do I need to add VFP9.exe.config into the directory where we distribute the VFP dlls?

I'm really at my wits end as what am I missing here and why almost the same .NET dll called that exact same way still works (as far as I can tell the difference is only in the actual code and using static methods in new dll vs. no static in old).

I'm including the picture of what I'm seeing in VS:

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.Json.dll reference can not be resolved
  Naomi
  Naomi
  Sep 27, 2018 @ 06:41pm

FINALLY! I did get it to work now. I was adding config files to all our executables and finally during kickboxing class it hit me 😃

I needed to add it to the poolservice.exe (this is the interface for running the dll and displaying a monitor). Once I added it there it finally worked for me.

I'm hoping it will work tomorrow for my colleague using this configuration.

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.Json.dll reference can not be resolved
  Dmitry Litvak
  Naomi
  Dec 28, 2018 @ 10:30am

I read the entire thread and I still don't understand it. I am having the same problem you had: Unable to load wwDotNetBridge: unable to load Clr Instance: 0x80131515

And I don't use the Newtonsoft.Json.dll in my app. I simply use the WW Client Tools for emailing. What do you think would be solution?

TIA

Gravatar is a globally recognized avatar based on your email address. re: Newtonsoft.Json.dll reference can not be resolved
  Naomi
  Dmitry Litvak
  Dec 28, 2018 @ 10:38am

Are you sure you unblocked the dll after you downloaded it?

© 1996-2024