Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
396 views
in Technique[技术] by (71.8m points)

windows 8 - VS2012/ Blend 5: Debugging an Exception (only) occurring in design view

I'm developing a Metro-style app (for Windows 8) using C# and XAML. I have set up my viewmodels to be used as design-time datacontexts, like so:

xmlns:vm="using:hub.ViewModels"
d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type=vm:ViewModels

My app appears to work perfectly when run, but in the design views of both VS 2012 and Blend, I occasionally get this (unhelpful) error message:

An Exception was thrown. TargetException: Error in the application.
Stacktrace
at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
InnerException: None

This only happens in the design view - meaning I can't set breakpoints around all my INotifyPropertyChanged() events.

What is the best approach to debugging design-time errors?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If this happens consistently or semi-consistently, you can attach the debugger to the XAML designer:

  1. Start Visual Studio; open your project and open a XAML file, causing the XAML designer to load

  2. Start a second instance of Visual Studio. Open your project but make sure no XAML documents are open.

  3. Ensure that Just My Code is disabled: From the Tools menu, select Options. Select the Debugging category. In the General page, ensure the check box next to Enable Just My Code is unchecked.

  4. From the Debug menu, select Exceptions... and check the Thrown check box next to Common Language Runtime Exceptions. This will enable first chance handling of all CLR exceptions. If you know the specific type of the exception, you can enable first chance handling for just that type.

  5. From the Debug menu, select Attach to Process. In the Attach to: field, click Select... and check the Managed (v4.5, v4.0) entry in the list and click OK.

    This is necessary because the debugger may misdetect the process as a native process if it attaches while the process is executing native code. If your project contains native code, you'll want to check the Native check box in the list as well (you can debug both managed and native code at the same time).

  6. In the Available Processes list box, find the xdesproc.exe that corresponds to your project and click Attach.

    If there are multiple processes (usually because you have multiple projects open or because the designer is reloading or has recently reloaded), it can be difficult to determine which designer process belongs to which Visual Studio instance. It's often easiest just to attach to all of them. A tool like Process Explorer can help you figure out which designer process belongs to which instance of Visual Studio.

    Note: Do not attach the debugger to a designer process (xdesproc) that belongs to the same instance of Visual Studio that you are using for debugging: doing so is likely to cause Visual Studio to hang. You must always use two different instances of Visual Studio.

  7. Do whatever you need to do to repro the bug. When it occurs, the debugger will break at the point where the exception is thrown. The debugger should load the symbols for your assemblies.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...