Forum Discussion

Grit's avatar
Grit
Occasional Contributor
2 years ago

Calling non-static .NET routines via dotNET Object - class constructor missing

Hi,

as the heading says, I am trying to call a non-static .NET routines via dotNET Object using as described here https://support.smartbear.com/testcomplete/docs/testing-with/advanced/using-external-functions/calling-from-dotnet-assemblies.html.

 

I have added the assembly to the CLR bridge and am able to access the classes via dotNET, but for one of the classes I need to instantiate, there is no constructor available, i.e. no zctor() method. For another class in the same assembly it works fine.

The only difference I can see, are the input parameters of the constructor. For the class where it is working, the input parameters are all of simple types (string, int and bool). For the class, where the constructor is missing in TestComplete, the input parameter type is a class from the same assembly.

 

Here is an example of the TestComplete script code:

 

     var endpoint = dotNET.MSGsup_NET_Messaging_Data.Endpoint.zctor("default", "channel1", "c:\\test", 250, false); //this works fine
     var protocolHandler = dotNET.MSGsup_NET_Messaging.ProtocolHandler.zctor(endpoint, null, null);                         //here no zctor method is found

 

 

Does anyone know, how I can instantiate the ProtocolHandler class here?

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    What is ProtocolHandler? Is there documentation that explains the object?

     

    It's mentioned, "To call a non-static member" use either

    dotNET.namespace.class.zctor()
    dotNET.namespace.class.zctor_2.(parameters)
    • Grit's avatar
      Grit
      Occasional Contributor

      It is a class defined in my c# assembly that I am trying to instantiate.

       

      In the assembly code the constructor is defined like this:

       

      public ProtocolHandler(Endpoint endpoint, SessionManager sessionManager = null, ILogger logger = null)

       

      Using zctor, zctor_2 or similar does not work, because those methods are not available in the TestComplete script for this class.

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    .NET routines with optional parameters, you need to use

    dotNET.System.Type.Missing

    for example,

    dotNET.TestNamespace.MyTestClass.Method1(1, dotNET.System.Type.Missing)

    where,

    namespace TestNamespace
    {
      static public class MyTestClass
      {
        static public void Method1(int param1, string param2 = "")
        {
           // Todo
        }
    
    • Grit's avatar
      Grit
      Occasional Contributor

      I have tried that already, but it does not change the original issue, which is that the constructor method is not available at all in TestComplete. The code completion only shows Equals and ReferenceEquals.

       

       

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Since you've said "there is no constructor available", and code completion is only showing two methods. Is this class an abstract class, even though it's public?

     

    Is there a demo with ProtocolHandler, which I can try on my end?