主要内容

NET.unloadAssembly

Unload .NET Core assembly from MATLAB

Since R2026a

    Description

    asmInfo = NET.unloadAssembly(asm) unloads a .NET Core assembly from MATLAB®. To unload an assembly, first set the Unloadable parameter in NET.addAssembly to true. Then call the NET.unloadAssembly function which removes the MATLAB class definitions for all .NET types defined in the assembly, unloads the assembly from the .NET Runtime, and asynchronously removes the file lock on the assembly, which is held by the MATLAB process, after garbage collection removes all references to the assembly. If the assembly is not loaded in MATLAB, the function does nothing.

    Note

    Unloading a .NET Framework assembly is not supported.

    example

    Examples

    collapse all

    Suppose that you have an assembly MyAssembly.dll containing the class MyAssembly.MyClass located at C:\myPath\.

    Select .NET Core.

    dotnetenv("core");

    Add the types defined in MyAssembly to MATLAB and enable unloading the assembly.

    asmPath = "C:\myPath\MyAssembly.dll";
    asmInfo = NET.addAssembly(asmPath,Unloadable=true);

    Create a MyClass object.

    obj = MyAssembly.MyClass;

    Unload the assembly and display the status.

    asmInfo = NET.unloadAssembly("MyAssembly");
    disp(asmInfo.AssemblyStatus);
    
    unloading

    Input Arguments

    collapse all

    Assembly name, specified as a string scalar, character vector, System.Reflection.AssemblyName object, or NET.Assembly object. If you specify a string scalar or character vector, the name can be an assembly short name or a fully qualified path to an assembly.

    Example: "MyAssembly"

    Example: "C:\asmPath\MyAssembly.dll"

    Output Arguments

    collapse all

    Assembly information containing names of the members of the assembly, returned as a NET.Assembly object. If the assembly is not loaded into MATLAB, the function returns a 0x0 NET.Assembly object.

    Version History

    Introduced in R2026a

    See Also

    Functions

    Objects