web-dev-qa-db-fra.com

System.Windows.Markup.XamlParseException

J'ai écrit une application WPF, elle fonctionne bien sur mon ordinateur. J'essaie maintenant de déployer l'application wpf sur un ordinateur W7. Et obtenant l'exception suivante:

Description: The process was terminated due to an unhandled exception.
Exception Info: System.Windows.Markup.XamlParseException
Stack:
   at System.Windows.Markup.XamlReader.RewrapException(System.Exception, System.Xaml.IXamlLineInfo, System.Uri)
   at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)
   at System.Windows.Application.LoadComponent(System.Uri, Boolean)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at System.Threading.ExecutionContext.runTryCode(System.Object)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at System.Windows.Application.Run()
   at CAMXSimulator.App.Main()

Une idée de ce qui ne va pas ici? 

Merci 

18
user838557

Ce type d'exception est courant lorsqu'une partie de votre constructeur de fenêtre principale ou de vos opérations de chargement échoue. Si vous pouvez mettre la main sur la trace de la pile, examinez l'exception interne et vous trouverez probablement le problème réel.

9
A.R.

J'ai eu ce problème parce que je montrais un formulaire dans le constructeur de l'application. Ce formulaire utilisait Style = "{StaticResource XYZ}". Cette ressource statique a été définie dans le fichier XAML de l'application.

J'ai résolu le problème en affichant le formulaire à un stade ultérieur de l'application, lorsque l'objet Application était entièrement construit.

5
krosenvold

J'ai eu le même rapport d'exception. Je pourrais le résoudre en utilisant le programme windbg.

  • téléchargez la version windbg x86 (pas x64).
  • ouvrez le fichier .exe de l'application qu'il contient (menu Fichier -> ouvrez exe.)
  • lancez ces commandes pour voir la vraie exception:

Après l'analyse, j'ai constaté que l'assembly System.Net.Http.Formatting était absent du système.

0:000> g
0:000> sxe clr
0:000> g
0:000> !loadby sos clr
0:000> !CLRStack
0:000> !PrintException

Exception type: System.IO.FileNotFoundException
Message: Could not load file or Assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
    InnerException: <none>
3
VahidN

Assurez-vous que vous avez construit l'architecture correcte x86 ou x64 lorsque vous vous exécutez sur la machine cible. Je suis également confronté au même problème, l’application capable de fonctionner sur ma clé USB FAT32, mais elle a échoué sur une autre machine avec Windows 7 - 32 bits (je sais que Windows 7 avec 32 bits est assez étrange). Voir http: //social.msdn .Microsoft.com/Forums/vstudio/en-US/8f803f28-dfda-4be5-9e8d-f7d82db95961/c-wpf-systemwindowsmarkupxamlparseexception? Forum = wpf

0
yancyn

J'ai remarqué un comportement similaire lors de l'installation d'une application ClickOnce sur une machine propre. J'ai résolu en définissant les exigences de l'application pour installer à la fois. Net 4 et .Net 3.5 complet.

Ce n'était plus arrivé.

0
Mario Vernari

la seule chose à laquelle je peux penser est de savoir si les deux boîtes ont la même version .NET dessus. NET 4 a quelques nouvelles fonctionnalités (analyseur XAML) que 3.5 SP1 n'a pas

0
Bek Raupov