使用用C ++编写的DLL与.Net应用程序

问题描述:

我最近不得不使用Visual Studio 2010在我的C#应用​​程序中引用一个DLL。看起来它是用C ++编写的,我要检查使用不安全它使用一种简单的方法。代码如下。它在我的32位系统上运行正常,但是当我在64位系统上运行时,我得到了以下错误。我尝试了配置中的所有内容但它不会运行。任何建议将不胜感激



I recently had to reference a DLL in my C# application using Visual Studio 2010. It appears it was written in C++ and I ahve to check "use unsafe" It uses a simple method. The code is below. It runs fine on my 32 bit system but I get the error below when I run it on my 64 bit system. I tried everything in the configuration but it will not run. Any suggestings would be appreciated

static void Main(string[] args)
       {
           string file = "STGFEWR"

           var reesult = Calculate_Retention_Time(file);
       }
       public static double Calculate_Retention_Time(string sequence)
       {
           unsafe
           {
               SSRCalc.Class1 c = new SSRCalc.Class1();
               char* p = (char*)System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(sequence).ToPointer();
               double hydrophobicity_factor = c.TSUM3((sbyte*)p);
               return hydrophobicity_factor;
           }
       }







无法加载文件或程序集''SSRCalc .dll''或其中一个依赖项。应用程序无法启动,因为它的并排配置不正确。有关更多详细信息,请参阅应用程序事件日志或使用命令行sxstrace.exe工具。 (来自HRESULT的异常:0x800736B1)




Could not load file or assembly ''SSRCalc.dll'' or one of its dependencies. The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail. (Exception from HRESULT: 0x800736B1)

你必须使你的exe 32位。实际上,它运行为64位,并且不能与您的DLL共存。将构建设置更改为32位。
You have to make your exe 32 bit. As it is, it''s running as 64 bit, and can''t co-exist with your DLL. Change the build settings to be 32 bit.