When I try to load in Matlab my .NET assembly foo.dll by typing:
asm = NET.addAssembly('fullpath\foo.dll');
I get the following error: "Could not load file or assembly 'file:///fullPath\foo.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. Source: mscorlib HelpLink:"
I've Matlab R2010a and I tried to build the assembly both for .NET framework 4.0 and .NET framework 3.0 with no success.
EDIT
I did several tests and now maybe I've partly discovered the problem. In the above example I was trying to add a private assembly by giving the full path. I then remembered to have also previously registered the same开发者_如何学JAVA assembly (targeted for .NET 4.0) in the GAC (through the gacutil /i foo.dll
command). Hence I removed the assembly from the GAC (gacutil /u foo
) and now at least I'm able to add the private assembly targeted for .NET 3.0 but still not if I want to target .NET 4.0.
I presume that before, when I was trying to add a private assembly for .NET 3.0, Matlab was still trying to add the assembly for .NET 4.0 installed in the GAC, because of some conflict. However, I still do not understand why I cannot use .NET 4.0 .
I can't reproduce the error. This is the example I used:
MyClass.cs
using System;
namespace ClassLibraryTest
{
public class MyClass
{
public static double add(double x, double y)
{
return x + y;
}
}
}
MATLAB
>> NET.addAssembly('C:\path\to\ClassLibraryTest.dll');
>> ClassLibraryTest.MyClass.add(1,2)
ans =
3
I tried different .NET target frameworks 4.0/3.5/3.0, and they all worked fine. Note that you can't unload an assembly once loaded, and the only way to release the .NET resources is to restart MATLAB...
精彩评论