本文介绍了在.NET 4.5的项目中使用.NET 2.0的DLL(在调试vshost崩溃)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用从MATLAB创建一个dll文件的dotnetbuilder(的)..

I am trying to use a dll file created from matlab with the dotnetbuilder (http://www.mathworks.se/help/dotnetbuilder/ug/create-a-net-component-from-matlab-code.html)..

为了使用DLL,我有一个REFFERENCE添加到MATLAB DLL称为MWArray.dll(http://www.mathworks.se/help/dotnetbuilder/ug/integrate-your-net-component-in-a-c-application.html),而可悲的是这个DLL似乎只是可用于.NET 2.0。

In order to use the dll, I have to add a refference to a matlab dll called 'MWArray.dll' (http://www.mathworks.se/help/dotnetbuilder/ug/integrate-your-net-component-in-a-c-application.html), and sadly this dll only seem to be available for .net 2.0.

我已经能够做出与我从MATLAB创建的DLL一个简单的控制台应用程序的唯一途径,就是通过执行以下操作:

The only way I've been able to make a simple console application work with the dll I created from matlab, was by doing following:

  • 与建设,当它在MATLAB针对该dll的.NET 2.0dotnetbuilder。
  • 更改我的控制台的.NET使用的版本申请到2.0版
  • target the dll for .net 2.0 when building it in matlab withdotnetbuilder.
  • change the version of .net used in my consoleapplication to version 2.0

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

If I don't do this, the console application will crash vshost.exe when I try to run the project.

我希望能够使用.NET 4 +的功能,因此在配置项目中使用.NET 2.0是不能接受的。而当我得到这个简单的控制台应用程序至少.NET 4.0上运行,我会努力得到它在F#3.0应用程序的工作,以及。

I wish to be able to use .net 4.+ features, so configuring the project to use .net 2.0 is not acceptable.. And when I get this simple console application running with at least .net 4.0, I will try to get it working in an F# 3.0 application as well.

我的计划是这样的:

...
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:

and I have attempted to edit the app.config file to be able to handle both .net 2 and 4:

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

不过,这是行不通的。

But it doesn't work..

是否可以设置的项目,这样我可以同时使用.NET 2.0和4.5,而这样会令我的项目的工作?或者我必须做一些其他人使用这个恼人的.NET 2.0的DLL ..?

我使用的:

  • 在VS2013
  • 在MATLAB R2013b(64位)

推荐答案

解决了这个问题!

我编我的目标.NET 4 matlab函数...然后我加了

I compiled my matlab function targeting .net 4...and then I added

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

到code ..

to the code..

所产生的code是这样的:

the resulting code looks like this:

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看起来是这样的:

the app.config looks like this:

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

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

however, the app.config doesn't seem to be needed...

这篇关于在.NET 4.5的项目中使用.NET 2.0的DLL(在调试vshost崩溃)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 18:39