How do I know which .NET assembly to load when I get the "Unable to resolve the name" error?
12 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2025-5-15
编辑: MathWorks Support Team
2025-5-16
I'm trying to use the System.IO.MemoryMappedFiles.CreateNew method to create a memory-mapped file, so I can create shared memory for inter-process communication. I loaded the System.IO.MemoryMappedFiles assembly, but I'm getting an "Unable to resolve the name" error when I use the method.
>> NET.addAssembly('System.IO.MemoryMappedFiles')
>> memMapFile = System.IO.MemoryMappedFiles.MemoryMappedFile.CreateOrOpen('mySharedFile', 1024)
Unable to resolve the name
'System.IO.MemoryMappedFiles.MemoryMappedFile.CreateOrOpen'.
How can I access this method?
采纳的回答
MathWorks Support Team
2025-5-16
编辑:MathWorks Support Team
2025-5-16
Generally, this error indicates that the required assembly is missing. In this example, if you are getting this error, then it means that MATLAB is set up for .NET Framework, which requires the System.Core assembly to run this method. Loading the System.IO.MemoryMappedFiles assembly would be appropriate if you are using .NET Core. You can use the dotnetenv function in MATLAB to display or set the version of .NET.
In general, when using .NET Base classes and methods you may need to load an assembly, but the assembly to load may depend on what version of .NET you are using: Framework or Core. The steps below illustrate how to determine what assembly is required and how to load an use it.
Follow the steps below to determine which assembly to load for your Base class.
1. Go to the .NET Microsoft API documentation
2. Select the .NET API and .NET version. For example, ".NET Version 8" or ".NET Framework Version 4.8".
3. Enter the name of the class that you want to use in the search bar (e.g, System.IO.MemoryMappedFiles.MemoryMappedFile) and select the appropriate link to go to the class documentation.
4. On the class documentation page note the assembly and namespace listed in the" Definition" section. If more than one assembly is listed, either one can be used.
Run the following code in MATLAB to load the assembly and use the MemoryMappedFile class.
% Add assemblies and import namespaces
% .NET Core and Framework require different assemblies for the MemoryMappedFiles class
env = dotnetenv;
if (env.Runtime == "framework")
NET.addAssembly('System.Core');
else
% For example, the assembly required for .NET Core 8
NET.addAssembly('System.IO.MemoryMappedFiles'); % or netstandard
end
% Create or open a MemoryMappedFile
memMapFile = System.IO.MemoryMappedFiles.MemoryMappedFile.CreateOrOpen('mySharedFile', 1024)
In the example code above, you can see that .NET Framework requires the System.Core assembly, and .NET Core 8 requires the System.IO.MemoryMappedFiles (or netstandard) assembly.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!