Tuesday, October 15, 2013

AccessViolationException: Attempted to read or write protected memory - COM libraries


In one of my project I have a .NET library that is registered to COM in order to be used from a C++ library.
Due to some error, I had to change the interface of an type; I added a new property ID and I set the type of this ID property to be int.
Once testing was done, I deployed the library in production and I started to see the following error:
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. T
his is often an indication that other memory is corrupt.
   at System.String.wstrcpy(Char* dmem, Char* smem, Int32 charCount)
   at System.String.CtorCharPtrStartLength(Char* ptr, Int32 startIndex, Int32 length)
   at System.StubHelpers.BSTRMarshaler.ConvertToManaged(IntPtr bstr)

The source of this error was pretty obvious (since the modification I stated earlier was the only one).
I remembered that the type in which I've added the new property ID is mapped to an Entity Framework type (using AutoMapper) and in this entity the ID was of type decimal. After changing the type from int to decimal, the AccessViolationException was gone...


Sunday, October 13, 2013

Programming languages guide (on Apple AppStore)

My second app was approved on Apple AppStore.
You can find it here.

For support and questions, please comment here!