Click here to Skip to main content
15,942,847 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hey guys,

I have a small yet irritating problem.

I designed my apps using VB 2010 on a Win Ultimate (7600) system and when I try to debug the apps they all say that "You have attempted to read or write protected... Bla bla bla".

Why would you suppose that would be?

Minor suggestions what other programmers gave me was to add something such as a garbage collector which acts as a memory releaser and changing all my variables to Null/Nothing, The other one was to check out my permissions on the system, and well they are set to full access for my user.

Even when I add a catch ex as Exception part it still happens, oh by the way it happens randomly all over my code.

Hope someone could help me out though.

Updated 13-Nov-11 23:43pm
Wayne Gaylard 14-Nov-11 5:45am    
Can you give us an example of some code that is causing this ?
Yvan Rodrigues 14-Nov-11 9:23am    
We need to see code. Are you using interop, unsafe code, or something that uses interop, like GDI+?
Dave Kreskowiak 16-Jan-12 10:51am    
Are you using any controls on your forms that are not in the standard ToolBox or some other COM-based component?? You can run into apartment threading issues if the app expects one threading model and your control(s) are using another.

1 solution

Any use of unsafe or unmanaged code can get you that type of exceptions.

An access violation occurs in unmanaged or unsafe code when the code attempts to read or write to memory that has not been allocated, or to which it does not have access. This usually occurs because a pointer has a bad value. Not all reads or writes through bad pointers lead to access violations, so an access violation usually indicates that several reads or writes have occurred through bad pointers, and that memory might be corrupted. Thus, access violations almost always indicate serious programming errors. In the .NET Framework version 2.0, an AccessViolationException clearly identifies these serious errors.

In programs consisting entirely of verifiable managed code, all references are either valid or null, and access violations are impossible. An AccessViolationException occurs only when verifiable managed code interacts with unmanaged code or with unsafe managed code.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900