How to unload .NET assemblies

Originally posted by Henry1 on December 01, 2025

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

Originally posted by rraghvani on December 01, 2025

That’s expected behaviour as Dispose() frees your class resources but doesn’t unload the assembly. The DLL remains locked until the TestComplete hosting process ends, so replacing the DLL requires closing/reopening the project or reopening TestComplete. Standard behaviour as mentioned in https://learn.microsoft.com/en-us/dotnet/standard/assembly/load-unload

Originally posted by Henry1 on December 01, 2025

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?

Originally posted by rraghvani on December 01, 2025

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

Originally posted by Henry1 on December 01, 2025

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.

Originally posted by rraghvani on December 01, 2025

Unfortunately, it’s not possible then.

Originally posted by Henry1 on December 01, 2025

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

Originally posted by rraghvani on December 01, 2025

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

Originally posted by Hassan_Ballan on December 01, 2025

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.

Originally posted by Henry1 on December 01, 2025

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

Originally posted by rraghvani on December 02, 2025

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.

Originally posted by Henry1 on December 03, 2025

Thank you very much. I agree with you that killing a process is not the most elegant solution. But it seems that there is no official way to terminate tcHostingProcess.exe directly from TestComplete.

Your suggestion would actually help me, because then I can create a postbuild event in Visual Studio that first terminates tcHostingProcess.exe and then copies the DLL to the target directory.

Originally posted by Henry1 on December 03, 2025

FYI: It works perfectly if tcHostingProcess.exe is still running, but throws an error if it has already stopped. To avoid this, these two lines of code should do the trick:

tasklist /FI "IMAGENAME eq tcHostingProcess.exe" 2>NUL | find /I /N "tcHostingProcess.exe">NUL
if "%ERRORLEVEL%"=="0" taskkill /f /im tcHostingProcess.exe