473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

AccessViolationException in 2008 but not 2005

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.
Feb 8 '08 #1
12 3503
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?
Feb 8 '08 #2
Can I clarify; is this all on the same machine?

Marc
Feb 8 '08 #3
Yes, it is all on the same machine.

Rob
Feb 8 '08 #4
OK; that's odd.

.... {stumped} ...
Feb 8 '08 #5
(Cheers, I was kind-of hoping you might spot this one ;-p)
Feb 8 '08 #6
Here's the exception message:

System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often
an indication that other memory is corrupt."
Source="OldFortranDllWrapper"
StackTrace:
at OldFortranDllWrapper.FortranDll.foo(InputData& inputData,
OutputData& outputData)
<snipthe rest of the stack trace is just my code down to this call </
snip>
InnerException:

I agree that it is probably a bad pointer or memory allocation in the
fortran dll. But it works when the calling c# exe was created in
vs2005, but not in vs2008. Is vs2008 less forgiving of this type of
thing, and if so is there a way of turning that off or working around
this?

Rob
Feb 8 '08 #7
"Marc Gravell" <ma**********@gmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
(Cheers, I was kind-of hoping you might spot this one ;-p)

Well, all I know is that the OP is dealing with some invalid pointer issue.
One could argue why this works in V1.X and not in V2, one of the the reasons
might be that V2 is linked with the safe CRT library, and the interop layer
enforces more strict pointer validation rules. So it's possible that this
faulty code ran 'perfectly' well on V1.X but fails (as it should) on V2.

Willy.

Feb 8 '08 #8
Thanks Willy. That makes sense, and that means I'm probably out of
luck. I may have to try to reverse-engineer that old dll. :-(

Rob
Feb 8 '08 #9
One could argue why this works in V1.X and not in V2

2005 vs 2008 - both v2 and the same runtime, surely?
Feb 8 '08 #10
"Marc Gravell" <ma**********@gmail.comwrote in message
news:6e**********************************@s8g2000p rg.googlegroups.com...
>One could argue why this works in V1.X and not in V2

2005 vs 2008 - both v2 and the same runtime, surely?

Sure, my bad, I meant V2. and V2 SP1. Sorry for the confusion.

Willy.

Feb 8 '08 #11
Running dumpbin /headers | findstr "DLL characteristics" on the exe
didn't produce any output. I had tried running editbin /nxcompat:no
on the exe before and it did not make any difference.
Mind to post some of the caller's code, or a small but complete sample that
illustrates the problem?
Would you mind if I just emailed an example project to you, Willy?
The fortran dll comes from another company and I am not comfortable
posting it all to a public site.

Rob
Feb 11 '08 #12
<rm********@gmail.comwrote in message
news:43**********************************@b2g2000h sg.googlegroups.com...
Running dumpbin /headers | findstr "DLL characteristics" on the exe
didn't produce any output. I had tried running editbin /nxcompat:no
on the exe before and it did not make any difference.
>Mind to post some of the caller's code, or a small but complete sample
that
illustrates the problem?

Would you mind if I just emailed an example project to you, Willy?
The fortran dll comes from another company and I am not comfortable
posting it all to a public site.

Rob

Ok, go ahead ;-)

Willy.

Feb 11 '08 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Marc Bartsch | last post by:
Hi, My C# app throws the following exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. From...
1
by: =?Utf-8?B?SmFzb24gUm9kbWFu?= | last post by:
I have a wierd problem in my application where any call to Assembly.GetFullName of the currently running assembly fails with an AccessViolationException. This only happens on windows vista, all...
7
by: Cirene | last post by:
I installed the RTM version of Visual Studio 2008 today. Initially when I would open any of my 2005 projects (.NET 2.0) it would simply open them. Now the Visual Studio Conversion Wizard is...
4
by: =?Utf-8?B?dGhlamFtaWU=?= | last post by:
Can NET 2008 run side by side with NET 2005? -- Regards, Jamie
3
by: jaems | last post by:
When I upgrade from VS 2005 to VS 2008 and then run VS 2008 linked to my remote website: 1) what is it doing to my website when the wizard upgrades my site? Is it only changing the web.config...
8
by: SSix2 | last post by:
.Net 2005 Managed C++ Background. I am writing a managed c++ wrapper for legacy unmanaged code. I created a test application in C# to create the legacywrapper and I am attempting to get some value...
2
by: =?Utf-8?B?VHJpc3RhbiBNU0ROIEtlZW4=?= | last post by:
I've written a test harness in C# to test one of our company's products, which is written in C. If the application crashes, the Instruction Address, Memory Address and the Access Type are stored...
6
by: AAaron123 | last post by:
I need to move a database from sql server 2008 to sql express 2008. Will backing up the sql server 2008 database to a file and then using that file to restore to sql express 2008 work? I don't...
0
by: mikeosoft | last post by:
Hi there, this is my first post here! I hope someone can help me. What I'm trying to do is : Storing Fonts in SQL Server And recalling them without installing the file in Windows\Fonts So I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.