gpt4 book ai didi

c# - 在 .net 4.5 项目中使用 .net 2.0 dll(vshost 在调试时崩溃)

转载 作者:行者123 更新时间:2023-11-30 22:08:41 26 4
gpt4 key购买 nike

我正在尝试使用通过 dotnetbuilder ( http://www.mathworks.se/help/dotnetbuilder/ug/create-a-net-component-from-matlab-code.html) 从 matlab 创建的 dll 文件。

为了使用该 dll,我必须添加对名为“MWArray.dll”(http://www.mathworks.se/help/dotnetbuilder/ug/integrate-your-net-component-in-a-c-application.html)的 matlab dll 的引用,遗憾的是,该 dll 似乎仅适用于 .net 2.0。

我能够使一个简单的控制台应用程序与我从 matlab 创建的 dll 一起工作的唯一方法是执行以下操作:

  • 在 matlab 中构建 .net 2.0 的 dll 时使用点网 build 者。
  • 更改控制台中使用的 .net 版本应用到 2.0 版

如果我不这样做,控制台应用程序将在我尝试运行项目时崩溃 vshost.exe。

我希望能够使用 .net 4.+ 功能,因此将项目配置为使用 .net 2.0 是 Not Acceptable 。当我让这个简单的控制台应用程序至少在 .net 4.0 上运行时,我会尝试让它也能在 F# 3.0 应用程序中工作。

我的程序是这样的:

...
using MathWorks.MATLAB.NET.Arrays;
using makesquare;

namespace Matlabski
{
class Program
{
static void Main(string[] args)
{
try
{
var stuff = new makesquare.MLTestClass();
var res = stuff.makesquare(1, 3);
Console.WriteLine(res[0]);
Console.WriteLine("sdfsdf");
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadKey();
}
}
}

并且我试图编辑 app.config 文件以能够同时处理 .net 2 和 4:

<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
<supportedRuntime version="v2.0"/>
</startup>
</configuration>

但是没用..

是否可以设置项目,以便我可以同时使用 .net 2.0 和 4.5,这会使我的项目工作吗?还是我必须做其他事情才能使用这个恼人的 .net 2.0 dll..?

我正在使用:

  • VS2013
  • MATLAB R2013b(64 位)

最佳答案

解决了问题!

我针对 .net 4 编译了我的 matlab 函数...然后我添加了

[assembly: MathWorks.MATLAB.NET.Utility.MWMCROption("-nojit")] 

代码..

生成的代码如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MathWorks.MATLAB.NET.Arrays;
using makesquare;
[assembly: MathWorks.MATLAB.NET.Utility.MWMCROption("-nojit")]

namespace Matlabski
{
class Program
{
static void Main(string[] args)
{
try
{
MLTestClass stuff = new MLTestClass();
object[] res = stuff.makesquare(1, 3);
Console.WriteLine(res[0].ToString());
Console.WriteLine("sdfsdf");
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadKey();
}
}
}

app.config 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

然而,似乎不需要app.config...

关于c# - 在 .net 4.5 项目中使用 .net 2.0 dll(vshost 在调试时崩溃),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22100113/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com