have a problem using ww DotNetBridge. I’m trying to import the System.Numerics Assembly and instantiate a Complex structure. I get no errors, all the methods return .T., not object references. I’m obviously doing something wrong, but I don’t know what.
My code:
*!* This doesn't work
cApp = "c:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\3.1.4\;
System.Numerics.dll"
PUBLIC oApp
oApp = loBridge.loadAssembly(cApp)
*!* RETURNS .T.
IF oApp
? "Success"
else
? loBridge.CERRORMSG
ENDIF
v1 = 2.0
v2 = 3.0
PUBLIC oNum
oNum = loBridge.createInstance( "System.Numerics.Complex",v1,v2)
*!* oNum is .T. NOT A Complex structure
Unfortunately this doesn't work currently. Mainly because the value returned is a .NET Struct type which is currently not supported for a constructor operation. Structs work as values but not to instantiate.
I've added this functionality, but it's not released yet.
Either way structs are a pain in the ass because they can't be directly accessed over COM - which is why the construction code doesn't work. The work around in the fix is - as it is for other high level invoke/get/set methods is that the value is stored in a wrapper ComValue
object.
do wwDotNetBridge
LOCAL loBridge as wwDotNetBridge
loBridge = GetwwDotnetBridge()
*** System.Numerics is GAC'd type so fullname is required
? loBridge.Loadassembly("System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
*** Returns a ComValue object (.Value property is the struct)
loComplexValue = loBridge.CreateInstance("System.Numerics.Complex",1.1,2.1)
*** The following don't work because it's a struct which is not COM accessible
*? loComplexValue.Value
* loDoubleVal = loBridge.GetProperty(loComplexValue.Value,"Magnitude")
loDoubleVal = loBridge.GetProperty(loComplexValue,"Magnitude")
? loDoubleVal
Note this code won't work with the current released version of Client Tools or the OSS wwDotnetBridge yet.
There are two fixes in this update to wwDotnetBridge
:
- Constructor results value is fixed up like GetProperty and InvokeMethod
- All explicit methods (Get/Set/Invoke) will treat ComValue instance type as using the .Value property
In short it's fixed but there's no update yet except in Web Connection 7.13 at this point.
+++ Rick ---
You can grab an updated wwDotnetBridge.dll
from here:
https://west-wind.com/files/WebConnectionExperimental.zip
that has the fixed described in it and that code should work with the code from the last message.
+++ Rick ---