Forum Discussion

Henry1's avatar
Henry1
Contributor
3 days ago
Solved

How to unload .NET assemblies

Hej,

I am using a .dotNet DLL that I have integrated into TestComplete via the CLR Bridge.

Example:

function DataConn(User : string, Pass : string, Host : string, Group : string, Query : string) : string;
var
  CHelpers,
  Ret;
begin
  CHelpers := dotNET.HelpersClassLibrary.CHelpers.zctor();

  Ret := CHelpers.DataConnection(User,Pass,Host,Group,Query);
  
  CHelpers.Dispose();

  if Ret.Success then
    result := Ret.Rueck.OleValue
  else
    Log.Error(Ret.Errormessage.OleValue);
end;

My .dotNET DLL is derived from IDisposable and implements a public function Dispose.

I call this last from TestComplete, thereby releasing all resources used.

If I call a function from the DLL once, I can no longer replace the DLL with a newer version because it now remains open by tcHostingProcess.

I then have to completely close the TestComplete project each time, replace the DLL, and then reload the project.

This Calling Functions From .NET Assemblies | TestComplete Documentation only describes how the assembly is loaded into the helper hosting process. However, it does not mention how to release the assembly again.

Has anyone had a similar experience and can give me a tip?

Thank you,

Henry

12 Replies

  • Hassan_Ballan's avatar
    Hassan_Ballan
    Icon for Champion Level 3 rankChampion Level 3

    Just to add: while TestComplete can’t unload .NET assemblies once loaded, a few workarounds help avoid restarting the project every time:

    • Versioned build folders – output each DLL build to a new folder so TC loads it as a fresh assembly.
      • Shadow-copy loader – use a small .NET loader that copies and loads the DLL, keeping the original file unlocked.
      • Out-of-process wrapper – expose your logic via a small external service/COM server so TC never locks the DLL at all.

    Doesn’t unload the assembly, but makes development much smoother.

    • Henry1's avatar
      Henry1
      Contributor

      Thank you very much Hassan for your excellent additions. The COM server approach looks promising. I'll give it a try.

      • rraghvani's avatar
        rraghvani
        Icon for Champion Level 3 rankChampion Level 3

        I'm against killing processes, but since tcHostingProcess.exe doesn't impact TestComplete you can kill the process via the command, in the Command Prompt

        taskkill /im tcHostingProcess.exe /f

        and copy the DLL over. Next time you run your script, the process will respawn. I've just tried this and it works.

         

  • Henry1's avatar
    Henry1
    Contributor

    That's a shame. Nevertheless, thank you for taking the time.

    • rraghvani's avatar
      rraghvani
      Icon for Champion Level 3 rankChampion Level 3

      It's worth logging a Support Ticket, as there might/could be a workaround for this, which hasn't been documented!

  • Henry1's avatar
    Henry1
    Contributor

    I just tried it. When I remove the DLL completely and then click Reload, the DLL remains locked and I cannot overwrite or delete the file. Unfortunately, I still have to close the project in TestComplete first.

    • rraghvani's avatar
      rraghvani
      Icon for Champion Level 3 rankChampion Level 3

      Unfortunately, it's not possible then.

  • Henry1's avatar
    Henry1
    Contributor

    Thank you for your prompt reply.

    That is precisely my question: How can I release the assembly from TestComplete WITHOUT having to close and reopen the project?

    • rraghvani's avatar
      rraghvani
      Icon for Champion Level 3 rankChampion Level 3

      It's not possible. However, saying that, have you tried this?