Forum Discussion

MaryL's avatar
14 years ago

RemotingException when try to call dotnet dll

I wrote a test script to determine whether all the text on a control can be displayed i.e. whether the control is wide enough to fit it all in.

I already have a .NET dll which will take a control and return true or false depending whether it is big enough to display the text



I added this dll to the CLR bridge and called it using the following code:



Function   DoesTextFitOnControl(control)

  Dim RtnValue

  Dim validator

    

  Set validator =  dotNET.TextValidation.ControlTextValidator.zctor   

  RtnValue = true

  if not validator.WillTextFitOnControl(control)  Then

       RtnValue = false

  end if

   DoesTextFitOnControl = RtnValue

 

End Function



I got an exception shown in the attached screen shot



What is the problem and what should I do about it?

2 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Mary,



    If this .Net DLL is a home-made one then I would recommend you to ask your developers first as the problem looks like to be specific to dll code.



    Also you may try to check if the problem exists when you pass to the validator not TestComplete wrapped object (via control variable), but the native one.
  • Hi,



    The problem is that you pass a control located in your application to a method from an external assembly. This is not allowed, and you get an exception. You need to load your assemby to your application's appdomain and use its dotNet object instead of CLR Bridge.



    For example:



    Sub loadAssembly(appDomain, name)

    Dim assemblyName

    Set assemblyName = dotNET.System_Reflection.AssemblyName.zctor_2(name)

    Call appDomain.Load_2(assemblyName)

    End Sub

    '...

    Function DoesTextFitOnControl(control)

    Set appDomain = Sys.Process("MyApp").AppDomain("MyApp.exe")

    name = "MyAssembly,Version=1.0.0.0,Culture="""",PublicKeyToken=something"

    Call loadAssembly(appDomain, name)

    Set validator = appDomain.dotNET.TextValidation.ControlTextValidator.zctor

    ' the rest of your code

    End Function