West Wind Internet and Client Tools
Intermittent Problem Loading wwDotNetBridge
Gravatar is a globally recognized avatar based on your email address. Intermittent Problem Loading wwDotNetBridge
  Doug Hennig
  All
  Sep 11, 2023 @ 05:04am

Occasionally I get this when starting an application that instantiates wwDotNetBridge at startup:

If I click No, I get an "Unable to load Clr Instance" error. However, if I close the app and try again, it works, so it isn't a consistent problem. Any suggestions?

Gravatar is a globally recognized avatar based on your email address. re: Intermittent Problem Loading wwDotNetBridge
  Rick Strahl
  Doug Hennig
  Sep 11, 2023 @ 10:30am

Hmmm... I've never seen that.

Are you using the full framework .NET runtime, or .NET Core? With Core I can think of perhaps loading the wrong version (64bit vs. 32bit).

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Intermittent Problem Loading wwDotNetBridge
  Rick Strahl
  Doug Hennig
  Sep 11, 2023 @ 10:38am

It might help if you explicitly load the .NET Runtime on startup, to avoid having the app auto-detect the runtime.

I wonder if it might be because the first assembly you load might be different. If it's NetStandard or .NET Core component it might load differently depending on which component gets first loaded. By explicitly loading for your runtime you force the version you need and it should be consistent.

You can use GetwwDotnetBridge() or GetwwDotnetCoreBridge() to initialize the runtime.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Intermittent Problem Loading wwDotNetBridge
  Doug Hennig
  Rick Strahl
  Sep 13, 2023 @ 04:54am

A little background first. I have a .NET DLL that uses a newer version of Newtonsoft.Json.dll than wwIPStuff does. To avoid a version conflict, I have a wwClient subdirectory of the app folder containing just wwIPStuff.dll, wwDotNetBridge.dll, and the version of Newtonsoft.Json.dll wwIPStuff needs (10.0). The app folder contains the .NET DLL, the version of Newtonsoft.Json.dll it needs (12.0), and the wwClient PRGs (which of course are built into the EXE).

Here's how I'm starting up:

set path to (fullpath('wwClient')) additive

do wwJsonSerializer.prg

lcFolder = justpath(fullpath('wwDotNetBridge.dll'))
lcCurDir = fullpath('')
cd (lcFolder)

loBridge = GetwwDotNetBridge()

cd (lcCurDir)

if vartype(loBridge) = 'O'
	addproperty(_vfp, 'oBridge', loBridge)

* Specifically load this version of the JSON library so the correct one is loaded.

	if not loBridge.LoadAssembly('wwClient\Newtonsoft.Json.dll')
		error 'Error loading Newtonsoft.Json.dll: ' + loBridge.cErrorMsg
	endif

* Load the .NET DLL.

	if not _vfp.oBridge.LoadAssembly('SO.Document.dll')
		error 'Error loading SO.Document.dll: ' + _vfp.oBridge.cErrorMsg
	endif
endif

The error I get after cancelling the dialog that pops up comes from this code in wwDotNetBridge.Init:

IF ISNULL(this.Load())
   ERROR "Unable to load wwDotNetBridge: " + this.cErrorMsg
   RETURN .F.
ENDIF

As I said, the weird thing is that it's intermittent. Usually the app starts up without a problem but this happens occasionally. Maybe anti-virus scanning wwIPStuff.dll or wwDotNetBridge.dll preventing it from being accessed temporarily?

Doug

Gravatar is a globally recognized avatar based on your email address. re: Intermittent Problem Loading wwDotNetBridge
  Rick Strahl
  Doug Hennig
  Sep 13, 2023 @ 05:47am

You can specify the exact version that should be used using Assembly Redirects in the <yourApp>.exe.config file. This basically maps any reference of Newtonsoft.Json to the specified version, regardless of what version the actual DLL/binary is bound to.

This works for any reference and works as long as the binary interfaces stay the same (they do with JSON.NET which has been stable since v6 at least).

That said, it does seem odd that it would be intermittent but again I think it might have to do with the order of components loading in different order. If you have multiple dependencies that use different versions of JSON.NET you might be hitting one that doesn't want to load or loads the wrong version. The assembly redirect should solve that. Another way would be to explicitly load the DLL with LoadAssembly() on startup which also guarantees that that version will be used since only one version of a DLL can be present at any time in a process.

FWIW, latest versions of Web Connection and Client Tools ship Newtonsoft.Json with version 13.0.3 which is the latest.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Intermittent Problem Loading wwDotNetBridge
  Doug Hennig
  Rick Strahl
  Sep 13, 2023 @ 10:54am

Thanks. I've implemented the redirect and can now clean up a bunch of stuff thanks to that. We'll see if it also resolves the intermittent issue.

Doug

© 1996-2024