Create Remotable .NET Assembly
This example shows how to create a remotable .NET assembly using MATLAB® Compiler SDK™.
Preparation
Decide whether you plan to use the
MWArrayAPI or the native .NET API. For more information, see Compare MWArray and Native .NET API for Remotable Assemblies.If using the MWArray API, copy the following folder that ships with the MATLAB product to your working folder:
matlabroot\toolbox\dotnetbuilder\Examples\VSVersion\NET\MagicRemoteExample\MWArrayAPI\MagicSquareRemoteComp
After you copy the files, at the MATLAB command prompt, change the working folder (navigate) to the new
MagicSquareRemoteCompsubfolder in your working folder.If using the native .NET API, copy the following folder that ships with the MATLAB product to your working folder:
matlabroot\toolbox\dotnetbuilder\Examples\VSVersion\NET\MagicRemoteExample\NativeAPI\MagicSquareRemoteComp
After you copy the file, at the MATLAB command prompt, change the working folder (navigate) to the new
MagicSquareRemoteCompsubfolder in your working folder.
Write the MATLAB function. Your MATLAB code does not require any additions to support .NET remoting. The following code for the
makesquarefunction is in the filemakesquare.min theMagicSquareRemoteCompsubfolder:function y = makesquare(x) y = magic(x);
Build Remotable Component Using .NET Assembly Compiler App
Click the .NET Assembly Compiler app in the apps gallery, or type
dotNetAssemblyCompilerat the MATLAB command prompt.In the Assembly Options area, select Enable .NET Remoting.

Build the .NET component using the following values.
Field Value Library Name MagicRemoteCompClass Name MagicClassFile to Compile makesquare.mFor more details, see the instructions in Generate .NET Assembly and Build .NET Application.
Build Remotable Component Using compiler.build.dotNETAssembly
As an alternative to the .NET Assembly Compiler app, you can create a .NET assembly using a programmatic approach.
From the MATLAB prompt, issue the following command:
buildResults = compiler.build.dotNETAssembly('makesquare.m', ... 'AssemblyName','MagicRemoteComp', ... 'ClassName','MagicClass', ... 'EnableRemoting','on');
Note
The generated assembly does not include MATLAB Runtime or an installer. To create an installer using the
buildResults object, see compiler.package.installer.
Files Generated by the Compilation Process
After compiling the components, ensure you have the following files in your output folder:
MagicRemoteComp.dll— TheMWArrayAPI component implementation assembly used by the server.IMagicRemoteComp.dll— TheMWArrayAPI component interface assembly used by the client.MagicRemoteCompNative.dll— The native .NET API component implementation assembly used by the server.IMagicRemoteCompNative.dll— The native .NET API component interface assembly used by the client. You do not need to install MATLAB Runtime on the client when using this interface.