Forum Discussion

sanjay0288's avatar
sanjay0288
Frequent Contributor
7 years ago
Solved

Question on CLR bridge

Hi,

 

Can anyone shed some light or working on CLR bridge through test complete? Sorry for being dumb, I am trying to write some data to a text file using StreamWriter and finding no success. Can anyone guide me to a sample on working with CLR bridge

  • AlexKaras's avatar
    AlexKaras
    7 years ago

    sanjay0288:
    Hi,

     

    I think that https://support.smartbear.com/testcomplete/docs/testing-with/advanced/using-external-functions/calling-from-dotnet-assemblies.html contains quite good description of the CLR Bridge.
    Basically, you may consider CLR Bridge to be an analogue of the rundll.exe utility from native Windows. I.e. CLR Bridge just passes the name of the assembly and the method to the .Net runtime and leaves all further processing to it.

    One case that I met recently in CLR Bridge and that we are working on now with Support is that there is a problem with assembly version redirection.
    The problem occurs when some assembly A internally references another assembly B of certain version, but the target system contains assembly B of another version. For the regular .Net executable this is handled via the <app>.exe.config file that instructs .Net runtime what redirections must be done for the absent assemblies. But this does not work for CLR Bridge because there is no executable in this case and thus settings from .exe.config cannot be applied.

    Otherwise. the usage of CLR Bridge is pretty straightforward and should not provide you with any major problem.

6 Replies

    • sanjay0288's avatar
      sanjay0288
      Frequent Contributor

      HI tristaanogre,

       

      As a first step to understand I have written a sample vbscript to write a line to text file using clr bridge. The problem is I am able to create a file but not able to write the contents to the file. Below is the sample routine which is written

       

      Sub Test
      fileName = "C:\sv1.txt"
      Set z = dotnet.System_IO.StreamWriter
      z.zctor_5(fileName).WriteLine "Sample text"

      End Sub

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        As tristaanogre said, there's no need for CLR Bridge here, use the aqFile object instead.

         

        As for why your code doesn't work -- place the cursor after

        z.zctor_5(fileName).

        and press Ctrl+Space to open the code completion. You'll see there are several WriteLine* methods -- WriteLine, WriteLine_2, WriteLine_3, and so on. They correspond to different overloads of the WriteLine(...) method.

         

        WriteLine without numeric suffixes corresponds to the parameterless version of the method, that's why the text parameter is ignored. Try WriteLine_9 or another version. And be sure to close the file afterwards.

        Set sw = z.zctor_5(fileName)
        sw.WriteLine_9 "Sample text"
        sw.Close