Catch Exception - Attempted to read or write protected memory in ESRI ArcObjects .Net 4.0 Framework
First - Don't write the code to throw "Attempted to read or write protected memory" ..it is bad. Second - If you are working on legacy codes and COM objects that throws "Attempted to read or write protected memory" while writing ArcMap add-ins, catch exceptions to prevent application crash, in my case ArcMap. Step #1 - Add following snippet to config file - app.config for Arc-addin <configuration> <runtime> < legacyCorruptedStateExceptionsPolicy enabled = "true" /> </ runtime > </ configuration > Step #2 Add - [HandleProcessCorruptedStateExceptions] [SecurityCritical] on the top of function you are tying catch the exception [HandleProcessCorruptedStateExceptions] [SecurityCritical] public IFeatureLayer GetOrCreateFeatureLayer ( string path , esriGeometryType type , ISpatialReference sr ) { //body }