Resolve Error Using .NET Base Class: Undefined Function or Variable
Issue
A frequently encountered error message when using a .NET class indicates that MATLAB® cannot find the specified class or variable:
Unrecognized function or variable 'ClassName'.
Possible Solutions
This happens because MATLAB cannot resolve the .NET type until the assembly is loaded using the
NET.addAssembly function. Follow
these steps to determine which assembly to load.
Call
dotnetenvin MATLAB. Note theRuntimeandVersionproperties to determine the .NET Version.Go to the Microsoft® documentation for the class you want to use.
Select the appropriate .NET Version, for example,
Frameworkor.NET 9.The class definition on the reference page shows the assemblies containing the class. Call the
NET.addAssemblyfunction to load the assembly.Create or use the class in your MATLAB code.