System.AccessViolationException [英] System.AccessViolationException

查看:66
本文介绍了System.AccessViolationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我尝试访问Frotran dll时,我收到此异常。这里

是示例代码。

使用System;

使用System.Collections.Generic;

使用System.Text;

使用System.Runtime.InteropServices;


名称空间TestApplicationFracEngine

{

class InterfaceClass

{

[DllImport(" fortran.dll",EntryPoint =" FR_MAIN_DLL",

CallingConvention = CallingConvention.StdCall) ]

public static extern void FR_MAIN_DLL(int errorNumber,string

errorMessage,int length);

public void CallFortran()

{

FR_MAIN_DLL(1,",120);

}

}

}

}

我已经复制了调试目录中的所有相关dll。当我运行

这个程序时,我得到以下异常,我无法摆脱它。

发生类型''System.AccessViolationException'的未处理异常在

TestApplicationFracEngine.exe


附加信息:尝试读取或写入受保护的内存。这是

经常表明其他内存已损坏。


请帮助我解决这个问题。

Hi,
I am getting this exceptions when I am trying to access the Frotran dll. Here
is sample code for that.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace TestApplicationFracEngine
{
class InterfaceClass
{
[DllImport("fortran.dll", EntryPoint = "FR_MAIN_DLL",
CallingConvention = CallingConvention.StdCall)]
public static extern void FR_MAIN_DLL(int errorNumber, string
errorMessage, int length);
public void CallFortran()
{
FR_MAIN_DLL(1, "", 120);
}
}
}
}
I have copied the all the dependent dlls in the debug directory. When I run
this program I am getting the following exception which I couldn''t get rid of.
An unhandled exception of type ''System.AccessViolationException'' occurred in
TestApplicationFracEngine.exe

Additional information: Attempted to read or write protected memory. This is
often an indication that other memory is corrupt.

Please help me out in solving this issue.

推荐答案




它是一个clasic内存边界违规。

尝试制作:


" string errorMessage"


a


" StringBuilder errorMessage"

并在StringBuilder的构造函数中提供

其容量,例如120个字符120个字符。试着把它拿到

足够大。你的Pinvoke应该像这样看待




[DllImport(" fortran.dll",EntryPoint =" FR_MAIN_DLL",
$ b) $ b CallingConvention = CallingConvention.StdCall)]

public static extern void FR_MAIN_DLL(int errorNumber,StringBuilder

errorMessage,int length);

你的调用应该如下所示:


StringBuilder sb = new StringBuilder(512);

int error_code = 1;


FR_MAIN_DLL(error_code,sb,sb.Capacity);


然后sb将保留翻译的错误消息。你可以通过执行sb.ToString()获得字符串
;但是如果你的函数声明有效并且

调用约定等也是有效的,那么

onyl就可以工作了。我的pinvoke电话

基于你的签名。最明显的错误

是缺少的StringBuilder,其他数据,我知道
知道,因为我不知道这个函数签名。试试

它让我知道,或者告诉我原始签名,...


希望这有帮助,...


问候


Kerem

-

------------ -----------

Beste Gr ?? sse /致敬/ Votre bien devoue

Kerem G ?? mr ?? kc ?? < br $>
最新项目: http://www.codeplex.com/restarts

最新的开源项目: http://entwicklung.junetz .de

-----------------------

这个回复是按原样提供,没有任何明示或暗示的保证。

SSekar" < u46044 @ uweschrieb im Newsbeitrag新闻:89de08c96fcea @ uwe ...
Hi,

it is a "clasic" memory boundary violation.
Try to make the:

"string errorMessage"

a

"StringBuilder errorMessage"

and supply in the Constructor of the StringBuilder
its capacity e.g. 120 for 120 chars. Try to hold it
big enough. You Pinvoke should look
like this:

[DllImport("fortran.dll", EntryPoint = "FR_MAIN_DLL",
CallingConvention = CallingConvention.StdCall)]
public static extern void FR_MAIN_DLL(int errorNumber, StringBuilder
errorMessage, int length);
Your call should look like this:

StringBuilder sb = new StringBuilder(512);
int error_code = 1;

FR_MAIN_DLL(error_code,sb,sb.Capacity);

then sb will hold the translated error message. You
can get the string by doing a sb.ToString(); But this
onyl works if your function declaration is valid and
calling convention etc is also valid. My pinvoke call
is basing on your signature. The most obvious fault
was the missing StringBuilder, the other data, i dint
know since i dont know this functions signature. Try
it and let me know, or show me the orignal signature,...

Hope this helps,...

Regards

Kerem
--
-----------------------
Beste Gr??sse / Best regards / Votre bien devoue
Kerem G??mr??kc??
Latest Project: http://www.codeplex.com/restarts
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."
"SSekar" <u46044@uweschrieb im Newsbeitrag news:89de08c96fcea@uwe...



我正在尝试这种例外访问Frotran dll。

这里

是示例代码。

使用系统;

使用系统.Collections.Generic;

使用System.Text;

使用System.Runtime.InteropServices;


命名空间TestApplicationFracEngine
{

class InterfaceClass

{

[DllImport(" fortran.dll",EntryPoint =" FR_MAIN_DLL",

CallingConvention = CallingConvention.StdCall)]

public static extern void FR_MAIN_DLL(int errorNumber,string

errorMessage,int length);

public void CallFortran()

{

FR_MAIN_DLL(1,"",120);

}

}

}

}


我已经复制了调试目录中的所有相关dll。当我

运行

这个程序我得到以下异常,我无法摆脱

of。


发生类型''System.AccessViolationException'未处理的异常



TestApplicationFracEngine.exe


附加信息:尝试读取或写入受保护的内存。这个

通常表示其他内存已损坏。


请帮我解决这个问题。 />
Hi,
I am getting this exceptions when I am trying to access the Frotran dll.
Here
is sample code for that.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace TestApplicationFracEngine
{
class InterfaceClass
{
[DllImport("fortran.dll", EntryPoint = "FR_MAIN_DLL",
CallingConvention = CallingConvention.StdCall)]
public static extern void FR_MAIN_DLL(int errorNumber, string
errorMessage, int length);
public void CallFortran()
{
FR_MAIN_DLL(1, "", 120);
}
}
}
}
I have copied the all the dependent dlls in the debug directory. When I
run
this program I am getting the following exception which I couldn''t get rid
of.
An unhandled exception of type ''System.AccessViolationException'' occurred
in
TestApplicationFracEngine.exe

Additional information: Attempted to read or write protected memory. This
is
often an indication that other memory is corrupt.

Please help me out in solving this issue.


嗨Kerem,

感谢您的回复。我根据你的建议尝试了但是它不适用于我/ b $ b我。在C ++代码中调用相同的函数。我在这里尝试相同的

在C#中。

请在C ++中找到以下声明。


DllExport void __stdcall PL_MAIN_DLL( int * driverErrorNumber,

char * errorMessage,

unsigned int * lengthArg);

Kerem G ?? mr ?? kc ??写道:
Hi Kerem,
Thanks for your reply. I tried as per your suggestion but it doesn''t work for
me. The same function is being called in C++ code. I am trying the same here
in C#.
Please find the following declaration in C++.

DllExport void __stdcall PL_MAIN_DLL(int *driverErrorNumber,
char *errorMessage,
unsigned int *lengthArg);
Kerem G??mr??kc?? wrote:

>

它是一个clasic内存边界违规。
尝试制作:

" string errorMessage"

StringBuilder errorMessage它的容量,例如120个字符120个字符。试着把它拿得足够大。你Pinvoke应该看起来像这样:

[DllImport(" fortran.dll",EntryPoint =" FR_MAIN_DLL",
CallingConvention = CallingConvention.StdCall)]

public static extern void FR_MAIN_DLL(int errorNumber,StringBuilder
errorMessage,int length);

你的电话应该是这样的:

StringBuilder sb = new StringBuilder(512);
int error_code = 1;

FR_MAIN_DLL(error_code,sb,sb.Capacity);

然后sb将保留已翻译的错误信息。你可以通过sb.ToString()获得字符串;但是,如果您的函数声明有效且调用约定等也有效,则此
onyl可用。我的pinvoke电话
基于你的签名。最明显的错误是缺少StringBuilder,其他数据,我知道,因为我不知道这个函数签名。试试
它并让我知道,或者告诉我原始签名,......

希望这有帮助,...

问候

Kerem
>Hi,

it is a "clasic" memory boundary violation.
Try to make the:

"string errorMessage"

a

"StringBuilder errorMessage"

and supply in the Constructor of the StringBuilder
its capacity e.g. 120 for 120 chars. Try to hold it
big enough. You Pinvoke should look
like this:

[DllImport("fortran.dll", EntryPoint = "FR_MAIN_DLL",
CallingConvention = CallingConvention.StdCall)]
public static extern void FR_MAIN_DLL(int errorNumber, StringBuilder
errorMessage, int length);

Your call should look like this:

StringBuilder sb = new StringBuilder(512);
int error_code = 1;

FR_MAIN_DLL(error_code,sb,sb.Capacity);

then sb will hold the translated error message. You
can get the string by doing a sb.ToString(); But this
onyl works if your function declaration is valid and
calling convention etc is also valid. My pinvoke call
is basing on your signature. The most obvious fault
was the missing StringBuilder, the other data, i dint
know since i dont know this functions signature. Try
it and let me know, or show me the orignal signature,...

Hope this helps,...

Regards

Kerem

>
当我尝试访问Frotran dll时,我收到此异常。
>Hi,
I am getting this exceptions when I am trying to access the Frotran dll.


[引用文字剪辑 - 35行]

[quoted text clipped - 35 lines]


>>
请帮我解决这个问题。
>>
Please help me out in solving this issue.



-

通过 http://www.dotnetmonster.com

--
Message posted via http://www.dotnetmonster.com


嗨,,


重点是。什么是IN参数以及什么

是OUT参数? IN表示我们必须

将数据插入到调用中,OUT表示

应用程序将数据填入我们的

varibale。这是我可以提出的另一个建议:


[DllImport(" fortran.dll",

EntryPoint =" FR_MAIN_DLL",

CallingConvention = CallingConvention.Winapi)]

public static extern void FR_MAIN_DLL(ref System.Int32 errorNumber,

StringBuilder errorMessage,

ref System.UInt32长度);


请告诉我这些参数究竟是什么意思,以及哪一个必须给予函数
,如果有的话

应用程序写入我们的变量。也很重要

知道这是UNCIODE还是ANSI调用,我的意思是

字符串部分,但由于char指针它似乎是ANSI。 。


请尝试使用签名并告诉我我们正在处理的参数

究竟是什么...

问候


Kerem

-

------------------ -----

Beste Gr ?? sse /致敬/ Votre bien devoue

Kerem G ?? mr ?? kc ??

最新项目: http://www.codeplex.com/restarts
最新的开源项目: http://entwicklung.junetz.de

-----------------------

此回复按原样提供,不提供保修明示或暗示。

SSekar通过DotNetMonster.com" < u46044 @ uweschrieb im Newsbeitrag

news:89e3394d790a7 @ uwe ...
Hi,,

the point is. What is a IN parameter and what
is a OUT parameter? IN means that we have to
insert the data nto the call and OUT means
that the application will fill the data into our
varibale. This is another suggestion i can make:

[DllImport("fortran.dll",
EntryPoint = "FR_MAIN_DLL",
CallingConvention = CallingConvention.Winapi)]
public static extern void FR_MAIN_DLL(ref System.Int32 errorNumber,
StringBuilder errorMessage,
ref System.UInt32 length);

Please tell me what exactly hese parameters mean and which
one must be given to the function as in and wich one does the
application write into our variable. Also would be important
to know whether this is a UNCIODE or ANSI call, i mean the
string part, but it seems to be a ANSI due to char pointer...

Please try th Signature and tell me what exactly the parameters
are on which we are working on...
Regards

Kerem
--
-----------------------
Beste Gr??sse / Best regards / Votre bien devoue
Kerem G??mr??kc??
Latest Project: http://www.codeplex.com/restarts
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."
"SSekar via DotNetMonster.com" <u46044@uweschrieb im Newsbeitrag
news:89e3394d790a7@uwe...

Hi Kerem,

感谢您的回复。我根据你的建议尝试了但是它没有工作



我。在C ++代码中调用相同的函数。我在这里尝试相同的


C#中的


请在C ++中找到以下声明。


DllExport void __stdcall PL_MAIN_DLL(int * driverErrorNumber,

char * errorMessage,

unsigned int * lengthArg);


Kerem G ?? mr ?? kc ??写道:
Hi Kerem,
Thanks for your reply. I tried as per your suggestion but it doesn''t work
for
me. The same function is being called in C++ code. I am trying the same
here
in C#.
Please find the following declaration in C++.

DllExport void __stdcall PL_MAIN_DLL(int *driverErrorNumber,
char *errorMessage,
unsigned int *lengthArg);
Kerem G??mr??kc?? wrote:

>>

它是一个clasic内存边界违规。
尝试制作:

" string errorMessage"

StringBuilder errorMessage它的容量,例如120个字符120个字符。试着把它拿得足够大。你Pinvoke应该看起来像这样:

[DllImport(" fortran.dll",EntryPoint =" FR_MAIN_DLL",
CallingConvention = CallingConvention.StdCall)]
public static extern void FR_MAIN_DLL(int errorNumber,
StringBuilder
errorMessage,int length);

你的电话应该是这样的:

StringBuilder sb = new StringBuilder(512);
int error_code = 1;

FR_MAIN_DLL(error_code,sb,sb.Capacity);

然后sb将保留已翻译的错误信息。你可以通过sb.ToString()获得字符串;但是,如果您的函数声明有效且调用约定等也有效,则此
onyl可用。我的pinvoke电话
基于你的签名。最明显的错误是缺少StringBuilder,其他数据,我知道,因为我不知道这个函数签名。试试
它并让我知道,或者告诉我原始签名,......

希望这有帮助,...

问候

Kerem
>>Hi,

it is a "clasic" memory boundary violation.
Try to make the:

"string errorMessage"

a

"StringBuilder errorMessage"

and supply in the Constructor of the StringBuilder
its capacity e.g. 120 for 120 chars. Try to hold it
big enough. You Pinvoke should look
like this:

[DllImport("fortran.dll", EntryPoint = "FR_MAIN_DLL",
CallingConvention = CallingConvention.StdCall)]
public static extern void FR_MAIN_DLL(int errorNumber,
StringBuilder
errorMessage, int length);

Your call should look like this:

StringBuilder sb = new StringBuilder(512);
int error_code = 1;

FR_MAIN_DLL(error_code,sb,sb.Capacity);

then sb will hold the translated error message. You
can get the string by doing a sb.ToString(); But this
onyl works if your function declaration is valid and
calling convention etc is also valid. My pinvoke call
is basing on your signature. The most obvious fault
was the missing StringBuilder, the other data, i dint
know since i dont know this functions signature. Try
it and let me know, or show me the orignal signature,...

Hope this helps,...

Regards

Kerem

>>
当我尝试访问Frotran dll时,我得到了这个例外。
>>Hi,
I am getting this exceptions when I am trying to access the Frotran dll.


[引用文字剪辑 - 35行]

[quoted text clipped - 35 lines]


>>>
请帮帮我在解决这个问题。
>>>
Please help me out in solving this issue.



-

通过 http://www.dotnetmonster.com


这篇关于System.AccessViolationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆