New Posts New Posts RSS Feed: Attempted to read or write protected memory.
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Attempted to read or write protected memory.

 Post Reply Post Reply
Author
RJayTaylor View Drop Down
Newbie
Newbie
Avatar

Joined: 27-Jun-2007
Location: Canada
Posts: 3
Post Options Post Options   Quote RJayTaylor Quote  Post ReplyReply Direct Link To This Post Topic: Attempted to read or write protected memory.
    Posted: 03-Apr-2008 at 11:56am
All of the tests I'm having trouble with are tests on certain methods of my business objects. 

So far the methods that are giving me trouble are business object methods that require another business object as a parameter.  The parameter object's properties are then accessed within the method and some action is performed; usually a data query. ( The parameter object's properties being used as arguments for query's clause ).

For these tests the objects that are being used as parameters are often newly created just before they are being passed into the methods being tested. 

For example I may create a "Product" within the test method to be used while testing the "GetInvoices" method on the "Invoice" business object.  The hope being that I get an EntityList of "Invoices" that contain the given "Product".

This is a high risk test where my error message is concerned.

I should mention that other methods with similar functionality do not fail, and even the ones that do fail do not fail all the time, although they fail more often than they pass, and it seems to go in sets of may failures followed by a string of successes.

It's almost like the new business object being used as the parameter is the culprit as no tests that involve simple string and integer parameters ever seem to fail.
Back to Top
pkarsh View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 32
Post Options Post Options   Quote pkarsh Quote  Post ReplyReply Direct Link To This Post Posted: 03-Apr-2008 at 11:30am
Does it only happen in certain unit tests? Does it happen frequently or rarely within these tests? What is the content of these tests?

Back in the old days of C programming a common cause of the equivalent of those sorts of exceptions was uninitialized pointers or uninitialized memory. If the memory you got happened to be "nulled out" then everything would be fine but if it wasn't, and/or a pointer had a value such that it was pointing to protected memory for some reason, the program would crash with an error that was the equivalent of what you're getting.

C# and VB don't have pointers and the .NET environment handles memory management so these could not be the direct cause, but think about what might be different in different invocations of your code. For example, is the exception dependent on the data that is being worked on? Take a look and see if you are dealing with values of null somewhere in your data and see if you are handling that properly. We had a bug at one point where under a certain set of unexpected circumstances an exception would be thrown when an attempt was made to read a table that had no data in it.

Hope this helps.
Back to Top
RJayTaylor View Drop Down
Newbie
Newbie
Avatar

Joined: 27-Jun-2007
Location: Canada
Posts: 3
Post Options Post Options   Quote RJayTaylor Quote  Post ReplyReply Direct Link To This Post Posted: 03-Apr-2008 at 11:10am
I get the following error message while running certain unit tests, but the frustrating thing is that the error doesn't always occur which is making it extremely difficult to debug. 

The error:

IdeaBlade.Persistence.PersistenceServerException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. --->  System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt..

This error will also occur while the project, which is a web project, is running in a browser, but again it only happens sometimes, and I can't seem to figure out what the occurances have in common.

The project is an ASP.NET web app being developed in VS2008.

Any insight appreciated.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down