gpt4 book ai didi

exception - System.AccessViolationException : Attempted to read or write protected memory

转载 作者:行者123 更新时间:2023-12-04 06:53:50 24 4
gpt4 key购买 nike

当我尝试在 Windows Vista 或 Windows 7 上运行的 Word 2007 中“查找和替换”时,出现以下异常。

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at Microsoft.Office.Interop.Word.Find.Execute(Object& FindText, Object& MatchCase, Object& MatchWholeWord, Object& MatchWildcards, Object& MatchSoundsLike, Object& MatchAllWordForms, Object& Forward, Object& Wrap, Object& Format, Object& ReplaceWith, Object& Replace, Object& MatchKashida, Object& MatchDiacritics, Object& MatchAlefHamza, Object& MatchControl)



有什么解决办法吗?

我正在使用 .NET3.5 C#。

**********代码****************
public static Application Open(string fileName)
{
object fileNameAsObject = (object)fileName;
Application wordApplication;
wordApplication = new Application();
object readnly = false;
object missing = System.Reflection.Missing.Value;
wordApplication.Documents.Open(
ref fileNameAsObject, ref missing, ref readnly,
ref missing,ref missing, ref missing, ref missing,
ref missing,ref missing, ref missing, ref missing,
ref missing,ref missing, ref missing, ref missing,
ref missing
);

return wordApplication;
}
private static void ReplaceObject(
ref Application wordApplication,
object ObjectTobeReplaced, object NewObject)
{
// ++++++++Find Replace options Starts++++++

object findtext = ObjectTobeReplaced;
object findreplacement = NewObject;
object findforward = true;
object findformat = false;
object findwrap = WdFindWrap.wdFindContinue;
object findmatchcase = false;
object findmatchwholeword = false;
object findmatchwildcards = false;
object findmatchsoundslike = false;
object findmatchallwordforms = false;
object replace = 2; //find = 1; replace = 2
object nevim = false;
Range range = wordApplication.ActiveDocument.Content;
range.Find.Execute(
ref findtext, ref findmatchcase, ref findmatchwholeword,
ref findmatchwildcards,ref findmatchsoundslike,
ref findmatchallwordforms, ref findforward, ref findwrap,
ref findformat, ref findreplacement, ref replace,
ref nevim, ref nevim, ref nevim, ref nevim
);

最佳答案

重新安装 Office 后问题已修复 :)...但仍然不知道是什么导致了问题

关于exception - System.AccessViolationException : Attempted to read or write protected memory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2744318/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com