上下文
大约一个月以来,我的Outlook外接程序在使用C# PropertyPageSite
对象更改属性时突然开始崩溃。当属性页中的文本字段发生更改并调用PropertyPageSite
对象的PropertyPageSite
函数时,就会发生这种情况。
我将Outlook降级为2021年的版本,而崩溃并没有发生,这很可能意味着由于outlook的更新,问题正在发生。
我所得到的错误如下
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>
我第一次注意到这个错误是在2205中。自上一次运行以来,应用程序本身并没有改变。
码
下面的代码段很重要。
OptionPage类声明如下
public partial class OptionPage : UserControl, Outlook.PropertyPage {
...
}
从外部源为PropertyPageSite
和属性本身注册一个load事件。
public OptionPage()
{
InitializeComponent();
// Register for the Load event.
this.Load += new EventHandler(OptionPage_Load);
}
load事件的事件处理程序
void OptionPage_Load(object sender, EventArgs e)
{
// Load our Settings here
LoadOptions();
// Get our Parent PropertyPageSite Object and store it into Classvariable.
_PropertyPageSite = GetPropertyPageSite();
}
我抓取PropertyPageSite
对象的方式似乎得到了许多论坛线程的建议。然而,据我所知,除了使用visual之外,Microsoft没有任何关于如何获取对象的信息。
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;
}
更改文本字段时通过事件处理程序调用的脏检查
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();
}
}
我试过
PropertyPageSite
对象的方法,或者dll字符串替换是否必要,但我无法让它以其他方式工作。WinDbg results
堆栈跟踪
[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
....
大会。错误发生在最后一行。
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
版本
是什么改变了导致这种行为的原因?
编辑1 请求程序转储
编辑2 请求TTD
发布于 2022-08-22 08:05:22
这是一个Outlook错误,它已经被微软修复了。
见评论
https://stackoverflow.com/questions/73190229
复制相似问题