2

WindowsVistaまたはWindows7で動作しているWord2007で「検索して置換」しようとすると、次の例外が発生します。

System.AccessViolationException:保護されたメモリの読み取りまたは書き込みを試みました。これは多くの場合、他のメモリが破損していることを示しています。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)

これに対する解決策はありますか?

Iamは.NET3.5C#を使用しています。

**********コード****************

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
        );
4

2 に答える 2

2

Officeを再インストールした後、問題は修正されました:)...しかし、問題の原因はまだわかりません

于 2010-04-30T13:03:34.837 に答える
1

これは、あなたが持っているコードを示さずに答えることはほぼ不可能です。

(ワイルドな)推測では、初期化されていないWordと対話するときにクラス/構造を指定すると、Wordは初期化されていないメモリにアクセスしようとします。

于 2010-04-30T12:11:30.720 に答える