2008年的AccessViolationException但不是2005年 [英] AccessViolationException in 2008 but not 2005
问题描述
我在vs2008 express中从c#调用旧版本
fortran dll时收到AccessViolationException,但相同的代码在vs2005中运行良好
。
如果我创建一个vs2005 c#wrapper dll来调用旧的fortran dll,那么
如果我从vs2008控制台调用该包装dll,我会得到异常
应用程序,但如果我从vs2005控制台应用程序调用它,则不行。我试过改变vs2008代码来定位2.0框架,但我仍然得到了
的异常。这都是在同一台机器上完成的。
我正在运行Xpsp2,所以我不认为这是数据执行预防
问题。我尝试使用editbin来更改控制台应用程序中的nxcomp位
exe,但它并没有任何区别。我还尝试通过
控制面板从dep明确排除控制台应用程序exe,并且这也没有任何区别。
我可以在dll上调用几个简单的实用工具方法,而不是获得异常,但是当我调用主处理方法然后
它会发生。这个dll足够老了,我确定那里确实有一个内存分配或指针问题。但我需要使用它来自vs2008的
并且我无法更改dll。
关于vs2008中可能导致的更改的任何想法这个,
以及我可以做些什么来解决它?
如果有帮助,对主处理方法的调用如下所示:
[DllImport(" foo.dll",EntryPoint =" foo")]
protected static extern void foo(ref InputData inputData,ref
OutputData outputData);
InputData和OutputData是包含旧fortran
样式固定数组和类型的结构。它们非常大,所以我不会发布完整的东西,因为你觉得这很重要。但这里是一个子集
作为例子:
[StructLayout(LayoutKind.Sequential)]
public struct OutputData
{
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 10)]
public char [] Version;
public int ValidSolution;
public int ErrorNo;
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 500)]
public char [] ErrorMessage;
public int NumberOfUnits;
}
先谢谢你的帮助。
I am getting an AccessViolationException when calling an old legacy
fortran dll from c# in vs2008 express, but the same code worked fine
in vs2005.
If I create a vs2005 c# wrapper dll to call the old fortran dll, then
I get the exception if I call that wrapper dll from a vs2008 console
app, but not if I call it from a vs2005 console app. I''ve tried
changing the vs2008 code to target the 2.0 framework, but I still get
the exception. This is all done on the same machine.
I''m running Xpsp2, so I don''t think it''s the data execution prevention
issue. I tried using editbin to change the nxcomp bit in console app
exe anyway, but it didn''t make any difference. I also tried
explicitly excluding that console app exe from the dep through the
control panel, and that didn''t make any difference either.
I can call a couple of simple utility methods on the dll without
getting the exception, but when I call the main processing method then
it happens. The dll is old enough that I''m sure there really is a
memory allocation or pointer problem in there. But I need to use it
from vs2008 and I can''t get the dll changed.
Any thoughts about what changed in vs2008 that might have caused this,
and what I might be able to do to work around it?
If it helps, the call to the main processing method looks like this:
[DllImport("foo.dll", EntryPoint = "foo")]
protected static extern void foo(ref InputData inputData, ref
OutputData outputData);
The InputData and OutputData are structures that include old fortran
style fixed arrays and types. They''re quite large, so I won''t post
the whole thing uless you think it''s important. But here''s a subset
as an example:
[StructLayout(LayoutKind.Sequential)]
public struct OutputData
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public char[] Version;
public int ValidSolution;
public int ErrorNo;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 500)]
public char[] ErrorMessage;
public int NumberOfUnits;
}
Thanks in advance for your help.
推荐答案
谢谢Marc,但我试过了。如果我在vs2005中创建一个包装器dll,
那么如果我从vs2005 exe调用该包装器它可以正常工作,但如果我从vs2008 exe调用它,那么它不会是
。
还有其他想法吗?
Thanks Marc, but I tried that. If I make a wrapper dll in vs2005,
then it works fine if I call that wrapper from a vs2005 exe, but not
if I call it from a vs2008 exe.
Any other ideas?
我可以澄清一下吗?这一切都在同一台机器上吗?
Marc
Can I clarify; is this all on the same machine?
Marc
是的,它都在同一台机器上。
Rob
Yes, it is all on the same machine.
Rob
这篇关于2008年的AccessViolationException但不是2005年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!