Aren
Aren

Reputation: 55946

Visual Studio soft-crashing when encountering XAML Errors in initialize

I've been having some serious issues with Visual Studio 2010 as of late. It's been crashing in a peculiar way when I encounter certain types of XAML errors during the InitializeComponent() of a control/window.

The program breaks and visual studio gears up like it's catching an exception (because it is) and then stops midway displaying a broken highlight in my XAML file with no details as to what is wrong. Example:

alt text

There is not pop outs, or details Anywhere about what is wrong, only a callstack that points to my InitializeComponent() call.

Now normally I'd just do some trial and error to fix this problem, and find out where i messed up, but the real problem isn't my code. Visual Studio is rendered completely useless at this point. It reports my application still in "Running" mode. The Stop/Break/Restart buttons on the toolbar or in the menus don't do anything (but grey out).

Closing the application does not stop this behaviour, closing visual studio gets it stuck in a massive loop where it yells at me complaining every file open is not in the debug project, then repeats this process when i have exausted every open file.

I have to force-close devenv.exe, and after this happening 3-4 times in a row it's a lot of wasted time (as my projects are usually pretty big and studio can be quite slow @ loading).

To the point

  1. Has anyone else experienced this?
  2. How can I stop studio from locking up.
  3. Can I at LEAST get information out of this beast another way so i can fix my XAML error sooner rather than after 3-4 trial-and-error compiles yielding the same crash?

Any & All help would be appreciated.

Visual Studio 2010 version: 10.0.30319.1RTM

Edit & Update

FWIW, mostly the errors that cause this are XamlParseExceptions (I figured this out after i found what was wrong with my XAML).

I think I need to be clearer though, Im not looking for the solution to my code problem, as these are usually typos / small things, I'm looking for a solution to VStudio getting all buggered up as a result.

The particular error in the above image that 100% for sure caused this was a XamlParseException caused by forgetting a Value attribute on a data trigger.

I've fixed that part but it still doesn't tell my why my studio becomes a lump of neutered program when a perfectly normal exception is thrown in the parsing of the XAML.

Code that will cause this issue (at least for me)

This is the base template WPF Application, with the following Window.xaml code. The problem is a missing Value="True" on the <DataTrigger ...> in the template. It generates a XamlParseException and Visual Studio Crashes as described above when debugging it.

<Window x:Class="XamlParseExplosion.MainWindow"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="MainWindow" Height="350" Width="525">
  <Window.Resources>
   <DataTemplate x:Key="BankListItemTemplate">
    <Border x:Name="ItemBorder" Width="250" Margin="1" BorderBrush="Blue" BorderThickness="5,0,0,0">
     <Grid>
      <Label Content="{Binding Name}" />
     </Grid>
    </Border>
    <DataTemplate.Triggers>
     <DataTrigger Binding="{Binding IsDirty}">
      <Setter TargetName="ItemBorder" Property="BorderBrush" Value="Red" />
     </DataTrigger>
    </DataTemplate.Triggers>
   </DataTemplate>
  </Window.Resources>
  <Grid>
   <ListView ItemTemplate="{StaticResource BankListItemTemplate}" />
  </Grid>
 </Window>

Final Notes

The following solutions did not help me:

  1. Restarting Visual Studio
  2. Rebooting
  3. Reinstalling Visual Studio
  4. Disabling add-ins like ReSharper & Reflector

Update (Way Later) w/ Answer

I want to add to this (as a pseudo answer) because I found out more information about this later that I want to pass along to people finding this question in google.

The Real Problem: XamlParseException was selected in Debug -> Exceptions to break when it occurs, because this happens during the WPF wireup vstudio cannot catch it correctly (normally it would fall down a couple more levels and be handled there where vstudio could handle it).

Simply turn that off and life will be good again.

I didn't want to put this as an answer because the answer provided by mazelo was correct too, when vstudio is run as Administrator it seems to be able to catch the exception properly and debug from there so I didn't want to take away his answered status because his solution does work.

Upvotes: 4

Views: 2710

Answers (8)

GMG
GMG

Reputation: 21

Just had a similar issue and the above listed answers didn't work for me. I'll post my solution here in case this happens to others. I had a window containing some suspect xaml, which, when I tried opening the window tab in VS caused it to crash each time. Awesome when you want to get in there to delete the bad code! Simple solution: Open up the xaml file in notepad, delete the bad code, and then rebuild it in VS. Simple, but worked for me.

Upvotes: 2

Claudiu Constantin
Claudiu Constantin

Reputation: 2218

This also happened to me. I can reproduce the issue everytime when having a simple scenario:

<UserControls:OperationLoader
              DepProperty1="{Binding VMProperty1}"
              DepProperty2="{Binding VMProperty2, Converter={StaticResource boolToInverse}}}"/>

If I remove the converter part everything works just fine. Probably the problem is the converter implementation which looks like this:

public sealed class BooleanToInverseConverter : BooleanConverter<bool>
{
    public BooleanToInverseConverter() :
        base(false, true)
    {
    }
}

Upvotes: 0

mazelo
mazelo

Reputation: 86

I had a similar problem. After hours i had the idea to start visual studio as admin. Fixed the problem, but still don't know why.

Upvotes: 1

AMissico
AMissico

Reputation: 21684

Change your video card drivers. Either update them or revert to the drivers supplied by Microsoft.

At my work computer, I reverted to built-in Intel video adapter and Visual Studio and Windows Explorer no longer crash.

See

Upvotes: 0

Try disabling visual effects in the Visual Studio settings. I know it sounds crazy, and sounds unrelated, but when I did that on my rather old graphics card, it all crashed a lot less.

As for the crashes re-occuring, I suggest submitting a report to Microsoft Connect if the above doesn't work.

Upvotes: 0

Tomas Voracek
Tomas Voracek

Reputation: 5914

Something similar happened to me in aspx file, project on MOSS. There was single line which was causing VS crash everytime. I figured out that only solution was remove line and add it only when the file was not opened in VS.

Did you check file format, i mean is it correct Unicode/Ansi/etc file? Check it at binary level.

Try open new WPF project, past XAML (no codebehind) and see if it still crashes. Try-catch around Initialize will not help?

Edit: I tried XAML you posted, no error. Same version of VS.

Upvotes: 0

AMissico
AMissico

Reputation: 21684

Things to try:

  • Turn off "exception assistant" under debugging options.
  • Disable "Visual Studio hosting process" under the project's debug properties.

Does the behavior differ if you enable "break on CLR exceptions" in the Exceptions dialog (Ctrl+Shift+E) and disabled "Enable Just My Code..."?

Upvotes: 0

Indy9000
Indy9000

Reputation: 8851

It's probably crashing in the initialization of an embedded UserControl. Take a look at how the DependencyProperties of that control is handled.

Upvotes: 1

Related Questions