Create a Remotable .NET Assembly

Building a Remotable Component Using the Library Compiler App

  1. Copy the example files as follows depending on whether you plan to use the MWArray API or the native .NET API:

    • 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 directory (cd) to the new MagicSquareRemoteComp subfolder 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 directory (cd) to the new MagicSquareRemoteComp subfolder in your working folder.

  2. Write the MATLAB function Your MATLAB code does not require any additions to support .NET Remoting. The following code for the makesquare function is in the file makesquare.m in the MagicSquareRemoteComp subfolder:

    function y = makesquare(x)
    
       y = magic(x);
    
  3. Click the Library Compiler app in the apps gallery.

  4. In the Additional Runtime Settings area, select Enable .NET Remoting.

  5. Build the .NET component. See the instructions in Create a .NET Assembly for more details.

Building a Remotable Component Using the mcc Command

From the MATLAB prompt, issue the following command:

mcc -B "dotnet:CompName,ClassName,
FrameworkVersion,ShareFlag,
RemoteFlag"
where:

  • CompName is the name of the component you want to create.

  • ClassName is the name of the C# class to which the component belongs.

  • FrameworkVersion is the version of .NET Framework for the component you are building. For example, 2.0 would denote .NET Framework 2.0.

  • ShareFlag designates access to the component. Values are either private or shared. Default is private.

  • RemoteFlag designates either a remote or local component. Values are either remote or local. Default is local.

To build a private remotable component, the mcc command to build the component for the .NET 2.0 Framework will look similar to:

mcc -B "dotnet:MagicSquareComp,MagicSquareClass,2.0,
             private,remote"

Files Generated by the Compilation Process

After compiling the components, ensure you have the following files in your for_redistribution_files_only folder:

  • MagicSquareComp.dll — The MWArray API component implementation assembly used by the server.

  • IMagicSquareComp.dll — The MWArray API component interface assembly used by the client .

  • MagicSquareCompNative.dll — The native .NET API component implementation assembly used by the server.

  • IMagicSquareCompNative.dll — The native .NET API component interface assembly used by the client. You do not need to install a MATLAB Runtime on the client when using this interface.

Was this topic helpful?