Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Oooooh baby... Attempted to read or write protected memory

Status
Not open for further replies.

JurkMonkey

Programmer
Nov 23, 2004
1,731
CA
Attempted to read or write protected memory. This is often an indication that other memory is corrupt."


I am calling a method on another C# DLL that works with an unmanaged dll. Somehow, this error keeps popping up ever since I upgraded to the 2.0 Framework.

I have uninstalled the 2.0 framework, and reinstalled it, and done windows updates on it for security fixes, and still nothing!


Someone posted a link about source safe possibly causing issues and I noticed that I get a dialog when I open my project that says "To ensure optimal source control integration with Microsoft Visual Studio, check with your source control provider for compatibility and update information"

So I'm going to try that next.

Has anyone else had this issue and know a solution to it?

I'm about to go postal here!

Thanks
 
I've had this exact problem today. Turned out that somebody modified the signature of a method in a COM we're using in order to suit his own needs, but forgot to update all calls from C# to that method. And an unmodified call gave the "attempted to read or write protected...".

Any other details you might give? Any custom marshalling? Has anyone messed with the call to the unmanaged method? (such as initialization routines; marshalling problems can lead to invalid pointers in unmanaged and there you are...; anything?)
 
Well, I got rid of one C++ Exception by changing

Tools->Options
Debugging->General
uncheck option "Suppress JIT optimization on module load"

But I still get 2 more exceptions. Look like it may be a marshaling thing but the DLL I'm referencing is not my code. I'm just trying to get things moving in the right direction. I do have access to that code.
 
This is a structure we are passing into a C++ call to be populated. This seems to be where our exceptions are being thrown. Can anyone tell me the correct way to marshal this?

Code:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
      struct ImageInfo
      {  
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
            public string customerID;

            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
            public string productID;

            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
            public string SKU;

            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
            public string filepath;

 
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
            public string thumbpath;

 
            [MarshalAs(UnmanagedType.I4)]
            public int total;

      }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top