How can I define which .Net framework shall a deployed MATLAB function use?

14 ビュー (過去 30 日間)
Bíró
Bíró 2012 年 8 月 16 日
I have a MATLAB function that uses some .Net assembly what are builded with .Net 4.0. I deployed this function and I set the .Net version to 4.0 (in project settings). When I use this deployed MATLAB function in a C# project it throws an exception when it try to load the .Net dll:
"Could not load file or assembly 'file:///c:\something.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."
Is there any option to define te version of .Net framework? Is there any other solution?

採用された回答

Friedrich
Friedrich 2012 年 8 月 17 日
編集済み: Friedrich 2012 年 8 月 17 日
Hi,
first of all this is expected behavior due some .NET Security Policies. The MCR load the 2.0 CLR which then needs to load 4.0 CLR for you Assembly. This must be allowed be a .config file.
So Place the following contents into a file with the name 'myTestAppl.exe.config' (change myTestAppl to the name of your exe)
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
Place this file in the same folder as your exe and it should be fine.
Please note MATLAB itself has this file. You can look it up in the bin\win32 or \win64 subfolder of your MATLAB installation (matlab.exe.config).
  1 件のコメント
Bíró
Bíró 2012 年 8 月 17 日
I had this config already but I missed the v2.0... tag. Thank you.

サインインしてコメントする。

その他の回答 (1 件)

Kaustubha Govind
Kaustubha Govind 2012 年 8 月 16 日
Are you using a MATLAB version older than R2011a? If yes, this may be related to a known bug.
  2 件のコメント
Bíró
Bíró 2012 年 8 月 16 日
No. I use R2011b.
Kaustubha Govind
Kaustubha Govind 2012 年 8 月 17 日
Ah! Could you contact MathWorks Tech Support please? I don't have expertise in this area to be able to help more.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall MATLAB from .NET についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by