4

I am trying to load the xaml file in visual studio but its throwing an exception but when I run the app the design and all the functionality is absolutely fine. The exception is below :

InvalidCastException: Unable to cast object of type 'System.Windows.Application' to type 'Omnia.PIE.VTA.App'.
   at Omnia.PIE.VTA.MainWindow.get_Instance()
   at Omnia.PIE.VTA.Views.AccountHolderInfo.UserControl_Loaded(Object sender, RoutedEventArgs e)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Sorry in advance but I am a total beginner in visual studio and after spending few hours I can't resolve it still.

dymanoid
  • 14,771
  • 4
  • 36
  • 64
Talib
  • 1,134
  • 5
  • 31
  • 58
  • 1
    Please post the complete markup of your *.xaml file as well as the code of the *.xaml.cs file – jazb Jul 25 '19 at 07:59
  • Form contains a control `Omnia.PIE.VTA.Views.AccountHolderInfo` that Visual Studio XAML Designer tries to initiaze but it throws an exception inside `UserControl_Loaded`. if you have source codes of `AccountHolderInfo` you can debug it. Open second Visual Studio, go to Debug menu, then Attach to Process, search for devenv.exe and select it. Then open Debug > Windows > Exception settings and mark "Common Language Runtime Exceptions". Then try to open XAML editor again and second instance of Visual Studio breaks and will show where the exception occured. – Misaz Jul 25 '19 at 08:02
  • 1
    Please don't set the `visual-studio` tag for questions that have nothing to do with the IDE itself. You should read the tag description if you are not sure whether a particular tag applies. I removed this tag from your question. – dymanoid Jul 28 '19 at 13:38

3 Answers3

6

I was able to sort this issue out. It was related to project cache. I followed the below steps to resolve it :

  1. closed Visual Studio
  2. Removed .vs, bin and obj files
  3. Started VS and cleaned the project
  4. Rebuild the project

After these steps I was able to open all the .xaml files.

Talib
  • 1,134
  • 5
  • 31
  • 58
1

I'm sorry if I'm not understanding your question. It sounds like you're saying the designer isn't working, but running it is.

If that is the case, Visual studio has trouble running the application that renders your xaml (called xdescproc I belive) in x64 mode. To fix that, try switching to x86. If that works but you don't want to have x86 as an option, you can try configuring an AnyCPU configuration that favors x64, but still will allow x86 (which will mean in design mode it shows x86, which will allow xdescproc to run).

0

In my case, somehow the target platform for my project had got changed to x64. I reverted it to older configuration after which the XAML designer started work again.

RBT
  • 24,161
  • 21
  • 159
  • 240