Examples of using External Language Server for Dotnet
Hey everyone.
I have been taking a look at the External Language Server functionality to hook into some Dotnet functions, and I am hitting a bit of a wall.
Based on the example in the documentation here I can get the same result doing:
ENV>Set netGate = $System.external.getDotNetGateway()
ENV>Set netProxy=netGate.new("System.DateTime",0)
ENV>Write netProxy.Now,!
2025-12-31 14:37:58.6022705However, if I then try another system class, I get an error:
ENV>Set netGate = $System.external.getDotNetGateway()
ENV>Set netProxy=netGate.new("System.Convert",0)
ENV>Write netProxy.ToBoolean(123)
<THROW>%Constructor+33^%Net.Remote.Object.1 *%Net.Remote.Exception <GATEWAY> InterSystems.Data.IRISClient.Gateway.GatewayException InterSystems.Data.IRISClient.Gateway.Gateway.dynamicFindConstructor(String className, Int32 parameterCount, Boolean isRecast) Constructor not found: System.Convert(1)(don't judge the method choice, I know it's not supposed to do anything except return what's being passed in. Just seemed like a safe choice)
It feels like I'm missing an obvious step here.
Comments
I suggest to have a look to the Discussion The new $system.external interface and the linked .NET samples available in GitHub.
The linked samples are very helpful, thank you!
gateway.new() calls a constructor, but the System.Convert class has no constructors.
To call a static method, use gateway.invoke(), but keep in mind that if you call the following code, an error will occur <FONT COLOR=red>"Unable to resolve method overloading ambiguity":
write netGate.invoke("System.Convert","ToBoolean",123)
To avoid it, specify the name of the method with the full specification of the parameters, for example:
s gw = $System.external.getDotNetGateway()
w gw.invoke("System.Convert","ToBoolean(int)",123),! ; -> 1
w gw.invoke("System.Convert","ToBoolean(string)","false"),! ; -> 0
w gw.invoke("System.Convert","ToBoolean(string)","true"),! ; -> 1
PS: see Mapping Specification (pay special attention to the sections "Overloaded Methods" and "Restrictions")
Ahh, I see. So I was trying to call a static method as if it was a constructor. Thank you for showing me this!
Interestingly, if I try your examples, I can recreate the ambiguity error, but then get an error when attempting to specify the full param specification:
Method not found: System.Convert.ToBoolean(int)
However this + the reply from Enrico has got me on a good footing, so will try a few things and see where I land.
Interestingly, if I try your examples, I can recreate the ambiguity error, but then get an error when attempting to specify the full param specificationWhat is your version of IRIS and .NET? I have IRIS 2025.3CE and .NET 8.0/Framework 4.6.2 - the examples above work flawlessly and give respectively 1, 0, 1 as indicated in the comments.
This is also possible:
USER>s gw = $System.external.getDotNetGateway()
USER>w gw.invoke("System.Convert","ToBoolean(System.UInt64)",123)
1
USER>
.NET 6 and IRIS 2022.1.
As "w gw.invoke("System.Convert","ToBoolean(System.UInt64)",123)" also doesn't work for me, I have to assume there's an issue with my older versions.
Thanks again for your help!