How can I interface a C# created .NET assembly with MATLAB?

17 views (last 30 days)
I have created a .NET assembly using C# and would like to know how can I interface it with MATLAB.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 May 2022 at 4:00
Edited: MathWorks Support Team on 25 May 2022 at 6:29
This enhancement has been incorporated in Release 2009a (R2009a). For previous product releases, read below for any possible workarounds.
There are two possible cases:
1. If you already have the assembly:
The assembly should be COM visible to interface with MATLAB. This can be done by generating the Type-Library using the 'tlbexp.exe' utility, which comes with the Microsoft .NET Framework SDK. This utility can be found under the installation directory of MS Visual Studio, for example, 'C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0'.
To create the Type-Library, follow these steps:
1. Click on 'Start->Programs->.NET Framework SDK->SDK Command Prompt'.
2. Bring your C# DLL to this folder. Now execute:
tlbexp myDLL.dll /out:myDLL.tlb
3. To deploy the DLL, register it using the 'regasm' utility, which comes with Microsoft .NET Framework, for example, under 'C:\WINNT\Microsoft.NET\Framework\v2.0.50727' :
regasm /codebase myDLL.dll /tlb:myDLL.tlb
2. If you are about to write code to generate the assembly:
Ensure that the assembly is COM compliant. For example, Microsoft Visual Studio gives the option to configure the generated assembly to be 'COM Visible'. This should automatically generate the required Type-Library when the assembly is built. When deploying the assembly, make sure that it is registered using the 'regasm' utility with '/codebase' option as in (1) above.
For more information on 'regasm' refer to:
To interface the assembly with MATLAB, use the ACTXSERVER command:

More Answers (0)

MathWorks Support


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!