How to remove reference to .net assembly in Matlab
I have created a dll in C #. I have added a link to this DLL in MATLAB as shown below. Everything works fine. The problem is that when I want to update my dll, I have to close MATLAB, otherwise I cannot rebuild my DLL, which is quite annoying. How in MATLAB can I remove the reference to this DLL - I thought there would only be a line of code for this?
% add reference to dll
cls = NET.addAssembly('C:\MyFolder\MyDllFolder\bin\Debug\MyDll.dll');
% reference my class
mycls = MyNameSpace.MyClass();
source to share
Have you tried cls.delete
and then added the link again?
I seem to remember being clear classes
helpful too. Sorry I can't be more definitive, I don't have Matlab to set up the example.
Edit
Looks like I was wrong, according to this link , "you cannot unload an assembly from MATLAB."
source to share
As a workaround, you can start a new Matlab instance from within Matlab itself with the system call and Matlab command line parameters, and only load the libraries in the new instance. This is described in the answer to the question: Release .NET Assembly from MATLAB
source to share
If the most important thing is downtime when changing an assembly, you can do this without loading a new MATLAB instance at all (which is very slow).
Even in pure .NET, it is not possible to unload an assembly from the AppDomain. Too much state depends on the JIT process - bits of code from this assembly could have been embedded into many other functions. This is actually one of the main reasons for having the AppDomain function in the first place.
So, you need a .NET assembly that acts like a wrapper and never changes. Its function will be to create an AppDomain and load the assembly for testing into a child AppDomain. And when it changes, destroy the child AppDomain and create a new one.
Difficult, but insulates MATLAB from complexity.
source to share