je reçois l'exception suivante lorsque je tente de « trouver et remplacer » dans Word 2007 travaillant sur Windows Vista ou Windows 7.System.AccessViolationException: Tentative de lecture ou d'écriture mémoire protégée
System.AccessViolationException: Tentative de lecture ou d'écriture de la mémoire protégée . C'est souvent une indication que l'autre mémoire est corrompue. à Microsoft.Office.Interop.Word.Find.Execute (Object & FindText, objet & matchCase, objet & MatchWholeWord, objet & MatchWildcards, objet & MatchSoundsLike, objet & MatchAllWordForms, objet & avant, & Object Habillage, Objet & Format, objet & RemplacerAvec, Objet & Remplacer, Objet & MatchKashida, Objet & MatchDiacritics, objet & MatchAlefHamza, objet & MatchControl)
Y at-il une solution pour cela?
Iam utilisant .NET3.5 C#.
********** CODE ****************
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
);