Reputation: 11
Context
Since about a month, my Outlook addin has suddenly started crashing when changing properties using the C# PropertyPageSite
object. It occurs when a text field in the property page changes and the OnStatusChange
function of the PropertyPageSite
object is called.
I downgraded outlook to a version from 2021 and the crash didn't occur, which most likely means the problem is occuring due to an update in Outlook.
The error I am getting is the following
System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
The first time I noticed the error was with Outlook version 2205. The application itself hasn't changed since the last time it worked.
Code
The following pieces of code are important.
The OptionPage class is declared like this
public partial class OptionPage : UserControl, Outlook.PropertyPage {
...
}
Registering a load event for the PropertyPageSite
and the properties themselves from an external source.
public OptionPage()
{
InitializeComponent();
// Register for the Load event.
this.Load += new EventHandler(OptionPage_Load);
}
The event handler for the load event
void OptionPage_Load(object sender, EventArgs e)
{
// Load our Settings here
LoadOptions();
// Get our Parent PropertyPageSite Object and store it into Classvariable.
_PropertyPageSite = GetPropertyPageSite();
}
The way I grab the PropertyPageSite
object which seems to be adviced by many forum threads. However, as far as I can tell, Microsoft doesn't have any information on how to get the object, except for when using visual basic.
Outlook.PropertyPageSite GetPropertyPageSite()
{
Type type = typeof(System.Object);
string assembly = type.Assembly.CodeBase.Replace("mscorlib.dll", "System.Windows.Forms.dll");
assembly = assembly.Replace("file:///", "");
string assemblyName = System.Reflection.AssemblyName.GetAssemblyName(assembly).FullName;
Type unsafeNativeMethods = Type.GetType(System.Reflection.Assembly.CreateQualifiedName(assemblyName, "System.Windows.Forms.UnsafeNativeMethods"));
Type oleObj = unsafeNativeMethods.GetNestedType("IOleObject");
System.Reflection.MethodInfo methodInfo = oleObj.GetMethod("GetClientSite");
object propertyPageSite = methodInfo.Invoke(this, null);
return (Outlook.PropertyPageSite)propertyPageSite;
}
The dirtyness check called through event handlers when changing text fields
void OnDirty(bool isDirty)
{
_Dirty = isDirty;
// When this Method is called, the PageSite checks for Dirty Flag of all Optionspages.
if (_PropertyPageSite != null)
{
_PropertyPageSite.OnStatusChange();
}
}
I have tried
PropertyPageSite
object or if the dll string replace was necessary, but I couldn't get it working any other wayWinDbg results
Stack trace
[0x0] outlook!SmoothScroll + 0x33fa4
[0x1] outlook!OlkGetResourceHandle + 0xd77d
[0x2] outlook!StdCoCreateInstance + 0x9e630
[0x3] outlook!SmoothScroll + 0x34f3a
[0x4] outlook!StdCoCreateInstance + 0x3c047
[0x5] outlook!StdCoCreateInstance + 0x8bf7
[0x6] outlook!RefreshOutlookETWLoggingState + 0x782b
[0x7] 0x7ffd28553c06
[0x8] MyOutlookAddin_28b66070000!MyOutlookAddin.OptionPage.OnDirty + 0x6d
[0x9] MyOutlookAddin_28b66070000!MyOutlookAddin.OptionPage.textBox_TextChanged + 0x55
[0xa] System_Windows_Forms_ni!System.Windows.Forms.Control.OnTextChanged + 0x96
....
Dissasembly. The error occurs on the last line
00007ff6`b3f47ba2 488b8f38020000 mov rcx, qword ptr [rdi+238h]
00007ff6`b3f47ba9 48894de7 mov qword ptr [rbp-19h], rcx
00007ff6`b3f47bad 4883c8ff or rax, 0FFFFFFFFFFFFFFFFh
00007ff6`b3f47bb1 48ffc0 inc rax
00007ff6`b3f47bb4 66393441 cmp word ptr [rcx+rax*2], si
Versions
What has changed that causes this behaviour?
Edit 1 Requested procdump
Edit 2 Requested TTD
Upvotes: 0
Views: 155
Reputation: 11
This was an Outlook bug an it has been fixed by Microsoft.
See comments
Upvotes: 0