West Wind Internet and Client Tools
Type not loaded Error trying to use wwJsonSerializer
Gravatar is a globally recognized avatar based on your email address. Type not loaded Error trying to use wwJsonSerializer
  David Stevenson
  All
  May 14, 2024 @ 10:39am

Hey Rick... long time no see!

I'm trying to use wwJsonSerializer from your version 7.33 tools to deserialize a block of JSON text I'm querying from a Dynamics Business Central api through a .NET DLL that handles tokens.

I'm getting good JSON text with an @odata.context and a "value" section, but when I call the deserialize function I'm getting "Type not loaded. Please call LoadAssembly first."

The .NET DLL is built for .NET version 8, so I'm using wwDotNetCoreBridge to call it.

The VFP folder I'm running this in has your wwIPStuff.dll, wwClient.app, wwDotNetBridge.dll, fxp, prg and xml, ClrHost.dll, and Newtonsoft.Json.dll (v13.0.3.27908).

Here is the VFP code:

DO wwclient
DO wwDotNetBridge
LOCAL o AS wwDotNetBridge
o = Getwwdotnetcorebridge()
? o.Getdotnetversion() && .NET Code Version: 8.0.3, wwDotnetBridge Version 7.33.0.0
? o.LoadAssembly("Onicon_Universal_Query_Engine.dll")
oUQE=o.createinstance("Onicon_Universal_Query_Engine.UniversalQueryEngine")
lcResult=oUQE.SendJsonQuery("https://api.businesscentral.dynamics.com/v2.0/etc etc etc")
loSer = CREATEOBJECT("wwJsonSerializer")
loResponse = loSer.Deserialize(lcResult)

On the Deserialize call, I get this error and the loSer reference goes NULL:

Any ideas what might be wrong?

David Stevenson

Gravatar is a globally recognized avatar based on your email address. re: Type not loaded Error trying to use wwJsonSerializer
  Rick Strahl
  David Stevenson
  May 14, 2024 @ 11:26am

Is the error coming from the serializer or your .NET component?

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Type not loaded Error trying to use wwJsonSerializer
  David Stevenson
  Rick Strahl
  May 15, 2024 @ 02:26am

Problem solved!!!

I removed the ww... components and Newtonsoft.Json from my VFP project folder and replaced them with some from a different computer where I had tested this several months ago.

They seem to be the same version (7.33), but now are working just fine.

I'm confused, but happy that it's working now.

Gravatar is a globally recognized avatar based on your email address. re: Type not loaded Error trying to use wwJsonSerializer
  Rick Strahl
  David Stevenson
  May 15, 2024 @ 11:42am

The trick is to make sure that the same version of the components are used for both the component you're using and wwDotnetBridge. If the versions are incompatible you end up with a problem.

wwJsonSerializer currently uses the latest version of the Newtonsoft libraries so we should generally be Ok, but if you were referencing an old version that would cause a problem.

You can tweak what version is required via Assembly Redirects in .NET:

This is a good read to understand how .NET finds and loads assemblies and how you can affect what versions are used.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Type not loaded Error trying to use wwJsonSerializer
  Rick Strahl
  Rick Strahl
  May 15, 2024 @ 11:46am

One additional concern is that you have to worry about the differences between .NET Framework and .NET Core.

I think that these actually load separately and can run side by side since they are effectively different runtime types. So wwJsonSerializer will use the .NET Framework, while your component access is using .NET Core (wwDotetBridgeCore) which can be confusing.

Most likely your issue was due to the .NET Framework version using an old newtonsoft assembly which would have been a problem regardless of the .NET/.NET Core mismatch.

+++ Rick ---

© 1996-2024