Why do I receive a runtime error when running an application that uses .NET 4.0 framework created with MATLAB Compiler 4.14 (R2010b)?

5 次查看(过去 30 天)
I have a code that calls a .NET 4.0 DLL using NET.AddAssembly. This code works fine inside MATLAB. I am using MATLAB Compiler 4.14 to build a console application from the aforementioned code. I receive the following error at runtime
This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

采纳的回答

MathWorks Support Team
This issue occurs when the compiled executable tries to load the assembly with .NET 2.0 framework by default. In order to overcome this issue, create a CONFIG file. For example, if your executable is 'foo.exe', create a file called 'foo.exe.config'. Add the following contents to that file
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
This will make sure .NET 4.0 is available when the application is running. The CONFIG file should be located in the same directory as the executable.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Getting Started with Microsoft .NET 的更多信息

产品


版本

R2010a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by