Question

I am getting a System.AccessViolationException thrown during the execution of an Azure Web Role (run on the Azure emulator, this has not been uploaded to Azure yet) when a call is made to an overridden method of an object when a local int variable is passed as one of the method parameters. The exception message is "Attempted to read or write protected memory. This is often an indication that other memory is corrupt".

The code where the exception is thrown is part of a local library that has been used for several years on live systems (not Azure) with no issues. The part that errors is as follows:

foreach (XmlDataComponent item in this.items)
{
   int index = 0;
   XmlNode node = item.ToXml(dataSet, xmlDocument, this, index);  // Exception thrown when this call is made
   ...
}

The XmlDataComponent is a base class, when the code runs item is one of its derived classes. The ToXml() method is overridden in the derived classes. The exception is thrown as soon as the call is made to ToXml().

The problem is the index parameter. If I swap this to use an explicit value instead of the local variable, e.g.

item.ToXml(dataSet, xmlDocument, this, 0)

there are no errors.

Similarly, if I cast the item to its actual type e.g.

((XmlDataItem)item).ToXml(dataSet, xmlDocument, this, index))

and mark the ToXml() method in the XmlDataItem class as new instead of override there are no errors.

I have also tried calling the library from a console application rather than a web role with exactly the same data (i.e. everything the same other than running under a web role). Again, this caused no problems.

It appears that when run under the Azure emulator, accessing a local variable as a parameter to an overridden method is an issue!!!

I'm hoping this is only an issue when run under the emulator, however we still need a fix otherwise dev is more difficult.

Any suggestions or advise would be much appreciated.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top