Managed Debugging Assistants (zz)

来源:互联网 发布:淘宝网免费下载 编辑:程序博客网 时间:2024/05/01 14:39

Getting RID of Just-In-Time debugge

//z 2013-08-08 17:15:23 IS2120@BG57IV3.T1665221783.K[T300,L4609,R130,V3618]

After Visual Studio is installed on a server, the default behavior when an unhandled exception occurs is to show an Exception dialog that requires user intervention to either start Just-In-Time debugging or ignore the exception. This may be undesirable for unattended operation. To configure the server to no longer show a dialog when an unhandled exception occurs (the default behavior prior to installing Visual Studio), use the registry editor to delete the following registry keys:

  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger

  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\DbgManagedDebugger

On a 64-bit operating system also delete the following registry keys:

  • HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger

  • HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\DbgManagedDebugger

//z 2013-08-08 17:15:23 IS2120@BG57IV3.T1665221783.K[T300,L4609,R130,V3618]

JIT-attach debugging is the phrase used to describe attaching a debugger to an executable image that throws an uncaught exception. In unmanaged code, it is what happens when you see a message box that invites you to:

  • Click OK to terminate the program

  • Click CANCEL to debug the program

If you click CANCEL, a debugger is started and attached to the process. The registry key that controls this is calledHKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\Current Version\AeDebug.

For an application that includes managed code, the common language runtime will present a similar dialog to JIT-attach a debugger. The registry key that controls this option is called HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\DbgJITDebugLaunchSetting.

  • If value = 0, prompt the user by means of a message box. This only applies to processes that are interactive with the desktop; services and other noninteractive processes will terminate.

    In the .NET Framework versions 1.0 and 1.1, or the .NET Framework version 2.0 on Windows 98 and Windows Me, the message box choices are:

    • Continue. This results in a stack dump to the console and process termination.

    • Attach a debugger. In this case, the runtime spawns the debugger listed in the DbgManagedDebugger registry key. If none is found, the process is terminated.

    In the .NET Framework version 2.0 on platforms other than Windows 98 and Windows Me, the choices are:

    • Send. An error report is sent to Microsoft, followed by process termination. See http://winqual.microsoft.com for information on how to retrieve these reports.

    • Don't Send. This results in a stack dump to the console and process termination.

    • Debug. The runtime spawns the debugger listed in the DbgManagedDebugger registry key. If none is found, the process is terminated.

  • If value = 1, simply return control. This results in a stack dump, after which the process is terminated.

  • If value = 2, spawn the debugger listed in the DbgManagedDebugger registry key.

  • If value = 16, in the .NET Framework version 2.0 only, the runtime presents the message box described above for processes that are interactive with the desktop. For processes that are not interactive, the runtime spawns the debugger listed in the DbgManagedDebugger registry key. This is the default setting for the .NET Framework version 2.0.

//z 2013-08-08 17:15:23 IS2120@BG57IV3.T1665221783.K[T300,L4609,R130,V3618]

For an application that includes managed code, the common language runtime will present a similar dialog to JIT-attach a debugger. The registry key that controls this option is called HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\DbgJITDebugLaunchSetting.

  • If value = 0, prompt the user by means of a message box. The choices are:
    • Continue. This results in a stack dump and process termination.
    • Attach a debugger. In this case, the runtime spawns the debugger listed in the DbgManagedDebuggerregistry key. If none, control is returned, and the process is terminated.
  • If value = 1, simply return control. This results in a stack dump, after which the process is terminated.  (No more dialog)
  • If value = 2, spawn the debugger listed in the DbgManagedDebugger registry key.

Option 2: If you want to disable the JIT debug dialog, but still want an error dialog:[暂时没在 VS 2008 上没有发现这个选项]

Visual Studio.NET|Tools|Options|Debugging|Just-In-Time and deselect "Common Language Runtime" and now you’ll get an OK/Cancel dialog instead of the select a Debugger Dialog.  Note: The registry entry from Option 1 above will need to be 0 for the dialog to show up.

Open Start>Control Panels>Internet Options: Advanced and activate (check box)

* Disable Script Debugging (Internet Explorer)
* Disable Script Debuggung (Other) 

Enabling or disabling Just-In-Time debugging

You can enable or disable Just-In-Time debugging from the Options dialog box.

To enable or disable Just-In-Time debugging

  1. On the Tools menu, click Options.

  2. In the Options dialog box, select the Debugging folder.

  3. In the Debugging folder, select the Just-In-Time page.

  4. In the Enable Just-In-Time debugging of these types of code box, select or clear the relevant program types: ManagedNative, or Script.

    To disable Just-In-Time debugging, once it has been enabled, you must be running with Administrator privileges. Enabling Just-In-Time debugging sets a registry key, and Administrator privileges are required to change that key.

  5. Click OK.

By default, Windows Forms applications have a top-level exception handler that allows the program to continue to run if it can recover. As a result, you must perform the following additional steps to enable Just-In-Time debugging of a Windows Forms application.

To enable Just-In-Time debugging of a Windows Form

  1. Set the jitDebugging value to true in the in the system.windows.form section of the machine.config or application.exe.config file:

    <configuration>    <system.windows.forms jitDebugging="true" /></configuration>
  2. In a C++ Windows Form application, you must also set DebuggableAttribute in a .config file or in your code. If you compile with /Zi and without /Og, the compiler sets this attribute for you. If you want to debug a non-optimized release build, however, you must set this yourself. You can do this by adding the following line to your the AssemblyInfo.cpp file of your application:

    [assembly:System::Diagnostics::DebuggableAttribute(true, true)]; 
Just-In-Time debugging errors

You might see the following error messages that are associated with Just-In-Time debugging.

  • An unhandled win32 exception occurred in <program>. Just-In-Time debugging this exception failed with the following error: The logged in user did not have access to debug the crashing application.

    This message indicates that Just-In-Time debugging failed because you do not have proper access permissions. For information on the required permissions, see Remote Debugging Permissions.

  • Unable to attach to the crashing process. The specified program is not a Windows or MS-DOS program.

    This error occurs when you try to attach to a process running as another user under Windows 2000.

    To work around this problem, start Visual Studio, open the Attach to Process dialog box from the Debug menu, and find the process you want to debug in the Available Processes list. If you do not know the name of the process, look at the Visual Studio Just-In-Time Debugger dialog and note the process ID. Select the process in the Available Processes list and click Attach. In the Visual Studio Just-In-Time Debugger dialog, click No to dismiss the dialog box.

  • Debugger could not be started because no user is logged on.

    This error occurs when Just-In-Time debugging tries to start Visual Studio on a machine where there is no user logged onto the console. Because no user is logged on, there is no user session to display the Just-In-Time debugging dialog box.

    To fix this problem, log onto the machine.

  • Class not registered.

    This error indicates that the debugger tried to create a COM class that is not registered, probably due to an installation problem.

    To fix this problem, use the setup disk to reinstall or repair your Visual Studio installation.



Just-In-Time debugging launches Visual Studio automatically when an exception or crash occurs in an application running outside Visual Studio. This enables you to test your application when Visual Studio is not running and begin debugging with Visual Studio when a problem occurs.

Just-In-Time debugging does not work for Windows Store apps. Just-In-Time debugging does not work for managed code that is hosted in a native application, such as Visualizers.

Using Just-In-Time debugging

When you install Visual Studio, Just-In-Time debugging is enabled by default. If you need to disable or reenable Just-In-Time debugging, see Enabling or disabling Just-In-Time Debugging.

When Just-In-Time debugging is enabled, you can test your application outside of Visual Studio. When a crash or exception occurs, you will see a dialog box appears with a message that looks something like this:

An unhandled exception ('System.TypeInitializationException') occurred in terrarium.exe[3384]

When this dialog box appears, you can begin debugging with the following procedure.

To begin Just-In-Time debugging when an error occurs

  1. In the Just-In-Time Debugging dialog box, in the Possible Debuggers list, click New instance of Visual Studio 2012 or click an instance of Visual Studio that is already running.

  2. To use Visual Studio automatically for all future crashes, click Set the currently selected debugger as the default.

  3. If you want to choose what types of code you will be able to debug, click Manually choose the debugging engines. If you do not choose this option, Visual Studio automatically selects the appropriate debug engines for the type of code in your program.

Just-In-Time debugging launches Visual Studio automatically when an exception or crash occurs in an application running outside Visual Studio. This enables you to test your application when Visual Studio is not running and begin debugging with Visual Studio when a problem occurs.

Just-In-Time debugging does not work for Windows Store apps. Just-In-Time debugging does not work for managed code that is hosted in a native application, such as Visualizers.

Using Just-In-Time debugging

When you install Visual Studio, Just-In-Time debugging is enabled by default. If you need to disable or reenable Just-In-Time debugging, see Enabling or disabling Just-In-Time Debugging.

When Just-In-Time debugging is enabled, you can test your application outside of Visual Studio. When a crash or exception occurs, you will see a dialog box appears with a message that looks something like this:

An unhandled exception ('System.TypeInitializationException') occurred in terrarium.exe[3384]

When this dialog box appears, you can begin debugging with the following procedure.

To begin Just-In-Time debugging when an error occurs

  1. In the Just-In-Time Debugging dialog box, in the Possible Debuggers list, click New instance of Visual Studio 2012 or click an instance of Visual Studio that is already running.

  2. To use Visual Studio automatically for all future crashes, click Set the currently selected debugger as the default.

  3. If you want to choose what types of code you will be able to debug, click Manually choose the debugging engines. If you do not choose this option, Visual Studio automatically selects the appropriate debug engines for the type of code in your program.


还可以通过环境变量 COMPLUS_MDA 控制 MDA 激活,此变量将重写注册表项。 COMPLUS_MDA 字符串是一个区分大小写的分号分隔的 MDA 名称列表或其他特殊控制字符串。 在托管或非托管调试器下启动将默认启用一组 MDA。 这是通过在环境变量或注册表项的值前面隐式附加默认在调试器下启用的分号分隔的 MDA 的列表来实现的。 特殊控制字符串如下:

  • 0 - 停用所有 MDA。

  • 1 - 从应用程序名称.mda.config 读取 MDA 设置。

  • managedDebugger - 显式激活在调试器下启动托管可执行文件时隐式激活的所有 MDA。

  • unmanagedDebugger - 显式激活在调试器下启动非托管可执行文件时隐式激活的所有 MDA。

如果存在冲突的设置,则最新的设置重写先前的设置:

  • COMPLUS_MDA=0 禁用所有 MDA,包括在调试器下隐式启用的那些 MDA。

  • COMPLUS_MDA=gcUnmanagedToManaged 启用 gcUnmanagedToManaged 以及在调试器下隐式启用的任何 MDA。

  • COMPLUS_MDA=0;gcUnmanagedToManaged 启用 gcUnmanagedToManaged,但是禁用将在调试器下隐式启用的 MDA。

d21c150d.collapse_all(zh-cn,VS.110).gif使用特定于应用程序的配置设置启用和禁用 MDA

可以在应用程序的 MDA 配置文件中单独地启用、禁用和配置某些助手。 若要使用用于配置 MDA 的应用程序配置文件,则必须设置 MDA 注册表项或 COMPLUS_MDA 环境变量。 应用程序配置文件通常与应用程序的可执行文件 (.exe) 位于同一目录中。 文件名采用“应用程序名称.mda.config”形式;例如,notepad.exe.mda.config。 在应用程序配置文件中启用的助手可能包含专门设计用于控制该助手的行为的特性或元素。 下面的示例演示如何启用和配置封送 MDA

<mdaConfig>  <assistants>    <marshaling>      <methodFilter>        <match name="*"/>      </methodFilter>      <fieldFilter>        <match name="*"/>      </fieldFilter>    </marshaling>  </assistants></mdaConfig>

对于应用程序中每个托管到非托管的转换,Marshaling MDA 会发出有关正在被封送处理为非托管类型的托管类型的信息。 Marshaling MDA 还能够分别筛选 <methodFilter> 和 <fieldFilter> 子元素中提供的方法和结构字段的名称。

下面的示例演示如何使用其默认设置来启用多个 MDA。

<mdaConfig>  <assistants>    <illegalPrepareConstrainedRegion />    <invalidCERCall />    <openGenericCERCall />    <virtualCERCall />  </assistants></mdaConfig>
重要说明重要事项

若在配置文件中指定了多个助手,则必须按字母顺序列出这些助手。 例如,若要同时启用 virtualCERCall 和 invalidCERCall MDA,则必须先添加<invalidCERCall /> 项,再添加 <virtualCERCall /> 项。 如果这些项未按字母顺序排列,则将显示未处理的无效配置文件异常消息。

d21c150d.collapse_all(zh-cn,VS.110).gifMDA 输出

MDA 输出类似于下面的示例,此示例显示了来自 pInvokeStackImbalance MDA 的输出。

A call to PInvoke function 'MDATest!MDATest.Program::StdCall' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

___________________________________________________________________________________________________________________________________

Just-In-Time debugging launches Visual Studio automatically when an exception or crash occurs in an application running outside Visual Studio. This enables you to test your application when Visual Studio is not running and begin debugging with Visual Studio when a problem occurs.

Just-In-Time debugging does not work for Windows Store apps. Just-In-Time debugging does not work for managed code that is hosted in a native application, such as Visualizers.

Just-In-Time debugging launches Visual Studio automatically when an exception or crash occurs in an application running outside Visual Studio. This enables you to test your application when Visual Studio is not running and begin debugging with Visual Studio when a problem occurs.

Just-In-Time debugging does not work for Windows Store apps. Just-In-Time debugging does not work for managed code that is hosted in a native application, such as Visualizers.

Using Just-In-Time debugging

When you install Visual Studio, Just-In-Time debugging is enabled by default. If you need to disable or reenable Just-In-Time debugging, see Enabling or disabling Just-In-Time Debugging.

When Just-In-Time debugging is enabled, you can test your application outside of Visual Studio. When a crash or exception occurs, you will see a dialog box appears with a message that looks something like this:

An unhandled exception ('System.TypeInitializationException') occurred in terrarium.exe[3384]

When this dialog box appears, you can begin debugging with the following procedure.

To begin Just-In-Time debugging when an error occurs

  1. In the Just-In-Time Debugging dialog box, in the Possible Debuggers list, click New instance of Visual Studio 2012 or click an instance of Visual Studio that is already running.

  2. To use Visual Studio automatically for all future crashes, click Set the currently selected debugger as the default.

  3. If you want to choose what types of code you will be able to debug, click Manually choose the debugging engines. If you do not choose this option, Visual Studio automatically selects the appropriate debug engines for the type of code in your program.


Diagnosing Errors with Managed Debugging Assistants

Using Just-In-Time debugging

When you install Visual Studio, Just-In-Time debugging is enabled by default. If you need to disable or reenable Just-In-Time debugging, see Enabling or disabling Just-In-Time Debugging.

When Just-In-Time debugging is enabled, you can test your application outside of Visual Studio. When a crash or exception occurs, you will see a dialog box appears with a message that looks something like this:

An unhandled exception ('System.TypeInitializationException') occurred in terrarium.exe[3384]

When this dialog box appears, you can begin debugging with the following procedure.

To begin Just-In-Time debugging when an error occurs

  1. In the Just-In-Time Debugging dialog box, in the Possible Debuggers list, click New instance of Visual Studio 2012 or click an instance of Visual Studio that is already running.

  2. To use Visual Studio automatically for all future crashes, click Set the currently selected debugger as the default.

  3. If you want to choose what types of code you will be able to debug, click Manually choose the debugging engines. If you do not choose this option, Visual Studio automatically selects the appropriate debug engines for the type of code in your program.


Managed debugging assistants (MDAs) are debugging aids that work in conjunction with the common language runtime (CLR) to provide information on runtime state. The assistants generate informational messages about runtime events that you cannot otherwise trap. You can use MDAs to isolate hard-to-find application bugs that occur when transitioning between managed and unmanaged code. You can enable or disable all MDAs by adding a key to the Windows registry or by setting an environment variable. You can enable specific MDAs by using application configuration settings. You can set additional configuration settings for some individual MDAs in the application's configuration file. Because these configuration files are parsed when the runtime is loaded, you must enable the MDA before the managed application starts. You cannot enable it for applications that have already started.

Note Note

When an MDA is enabled, it is active even when your code is not executing under a debugger. If an MDA event is raised when a debugger is not present, the event message is presented in an unhandled exception dialog box, although it is not an unhandled exception. To avoid the dialog box, remove the MDA-enabling settings when your code is not executing in a debugging environment.

Note Note

When your code is executing in the Visual Studio integrated development environment (IDE), you can avoid the exception dialog box that appears for specific MDA events. To do that, on the Debug menu, click Exceptions. (If the Debug menu does not contain an Exceptions command, click Customize on theTools menu to add it.) In the Exceptions dialog box, expand the Managed Debugging Assistants list, and then clear the Thrown check box for the individual MDA. For example, to avoid the exception dialog box for a contextSwitchDeadlock MDA clear the Thrown check box next to its name in theManaged Debugging Assistants list. You can also use this dialog box to enable the display of MDA exception dialog boxes.

The following table lists the MDAs that ship with the .NET Framework.

asynchronousThreadAbort MDA

bindingFailure MDA

callbackOnCollectedDelegate MDA

contextSwitchDeadlock MDA

dangerousThreadingAPI MDA

dateTimeInvalidLocalFormat MDA

dirtyCastAndCallOnInterface MDA

disconnectedContext MDA

dllMainReturnsFalse MDA

exceptionSwallowedOnCallFromCom MDA

failedQI MDA

fatalExecutionEngineError MDA

gcManagedToUnmanaged MDA

gcUnmanagedToManaged MDA

illegalPrepareConstrainedRegion MDA

invalidApartmentStateChange MDA

invalidCERCall MDA

invalidFunctionPointerInDelegate MDA

invalidGCHandleCookie MDA

invalidIUnknown MDA

invalidMemberDeclaration MDA

invalidOverlappedToPinvoke MDA

invalidVariant MDA

jitCompilationStart MDA

loaderLock MDA

loadFromContext MDA

marshalCleanupError MDA

marshaling MDA

memberInfoCacheCreation MDA

moduloObjectHashcode MDA

nonComVisibleBaseClass MDA

notMarshalable MDA

openGenericCERCall MDA

overlappedFreeError MDA

pInvokeLog MDA

pInvokeStackImbalance MDA

raceOnRCWCleanup MDA

reentrancy MDA

releaseHandleFailed MDA

reportAvOnComRelease MDA

streamWriterBufferedDataLost MDA

virtualCERCall MDA

By default, the .NET Framework activates a subset of MDAs for all managed debuggers. You can view the default set in Visual Studio by clicking Exceptions on the Debug menu and expanding the Managed Debugging Assistants list.

Enabling and Disabling MDAs

You can enable and disable MDAs by using a registry key, an environment variable, and application configuration settings. You must enable either the registry key or the environment variable to use the application configuration settings.

In Visual Studio 2005 and later versions, when the hosting process is enabled, you cannot disable MDAs that are in the default set or enable MDAs that are not in the default set. The hosting process is enabled by default, so it must be explicitly disabled.

To disable the hosting process in Visual Studio, do the following:

  1. In Solution Explorer, select a project.

  2. On the Project menu, click Properties.

    The Project Designer window appears.

  3. Click the Debug tab.

  4. In the Enable Debuggers section, clear the Enable the Visual Studio hosting process check box.

However, disabling the hosting process can affect performance. You can avoid the need to disable MDAs by preventing Visual Studio from displaying the MDA dialog box whenever an MDA notification is received. To do that, click Exceptions on the Debug menu, expand the Managed Debugging Assistants list, and then select or clear the Thrown check box for the individual MDA.

Enabling and Disabling MDAs by Using a Registry Key

You can enable MDAs by adding the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\MDA subkey (type REG_SZ, value 1) in the Windows registry. Copy the following example into a text file named MDAEnable.reg and double-click the file name in File Explorer to enable MDAs on that computer. Setting the subkey to 1 enables the reading of MDA settings from the ApplicationName.mda.config file. See Enabling and Disabling MDAs by Using Application-Specific Configuration Settings for more information. The registry setting can be overridden by the COMPLUS_MDA environment variable. See Enabling and Disabling MDAs by Using an Environment Variable for more information.

Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]"MDA"="1"

To disable MDAs, set the MDA subkey to 0 (zero) using the Windows Registry Editor. Alternatively, you can copy the following example into a text file named MDADisable.reg and double-click the file name in File Explorer.

Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]"MDA"="0"

By default, some MDAs are enabled when you run an application that is attached to a debugger, even without adding the registry key. Examples of such assistants are pInvokeStackImbalance MDA and invalidApartmentStateChange MDA. You can disable these assistants by running the MDADisable.reg file as described earlier in this section.

Enabling and Disabling MDAs by Using an Environment Variable

MDA activation can also controlled by the environment variable COMPLUS_MDA, which overrides the registry key. The COMPLUS_MDA string is a case-insensitive, semicolon-delimited list of MDA names or other special control strings. Starting under a managed or unmanaged debugger enables a set of MDAs by default. This is done by implicitly prepending the semicolon-delimited list of MDAs enabled by default under debuggers to the value of the environment variable or registry key. The special control strings are the following:

  • 0 - Deactivates all MDAs.

  • 1 - Reads MDA settings from ApplicationName.mda.config.

  • managedDebugger - Explicitly activates all MDAs that are implicitly activated when a managed executable is started under a debugger.

  • unmanagedDebugger - Explicitly activates all MDAs that are implicitly activated when an unmanaged executable is started under a debugger.

If there are conflicting settings, the most recent settings override previous settings:

  • COMPLUS_MDA=0 disables all MDAs, including those implicitly enabled under a debugger.

  • COMPLUS_MDA=gcUnmanagedToManaged enables gcUnmanagedToManaged in addition to any MDAs that are implicitly enabled under a debugger.

  • COMPLUS_MDA=0;gcUnmanagedToManaged enables gcUnmanagedToManaged but disables MDAs that would otherwise be implicitly enabled under a debugger.

Enabling and Disabling MDAs by Using Application-Specific Configuration Settings

You can enable, disable, and configure some assistants individually in the MDA configuration file for the application. To enable the use of an application configuration file for configuring MDAs, either the MDA registry key or the COMPLUS_MDA environment variable must be set. The application configuration file is typically located in the same directory as the application's executable (.exe) file. The file name takes the formApplicationName.mda.config; for example, notepad.exe.mda.config. Assistants that are enabled in the application configuration file may have attributes or elements specifically designed to control that assistant's behavior. The following example shows how to enable and configure the marshaling MDA.

<mdaConfig>  <assistants>    <marshaling>      <methodFilter>        <match name="*"/>      </methodFilter>      <fieldFilter>        <match name="*"/>      </fieldFilter>    </marshaling>  </assistants></mdaConfig>

The Marshaling MDA emits information about the managed type that is being marshaled to an unmanaged type for each managed-to-unmanaged transition in the application. The Marshaling MDA can also filter the names of the method and structure fields supplied in the <methodFilter> and<fieldFilter> child elements, respectively.

The following example shows how to enable multiple MDAs by using their default settings.

<mdaConfig>  <assistants>    <illegalPrepareConstrainedRegion />    <invalidCERCall />    <openGenericCERCall />    <virtualCERCall />  </assistants></mdaConfig>
Important noteImportant

When you specify more than one assistant in a configuration file, you must list them in alphabetical order. For example, if you want to enable both thevirtualCERCall and the invalidCERCall MDAs, you must add the <invalidCERCall /> entry before the <virtualCERCall /> entry. If the entries are not in alphabetical order, an unhandled invalid configuration file exception message is displayed.

MDA Output

MDA output is similar to the following example, which shows the output from the pInvokeStackImbalance MDA.

A call to PInvoke function 'MDATest!MDATest.Program::StdCall' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

Just-In-Time debugging launches Visual Studio automatically when an exception or crash occurs in an application running outside Visual Studio. This enables you to test your application when Visual Studio is not running and begin debugging with Visual Studio when a problem occurs.

Just-In-Time debugging does not work for Windows Store apps. Just-In-Time debugging does not work for managed code that is hosted in a native application, such as Visualizers.

Using Just-In-Time debugging

When you install Visual Studio, Just-In-Time debugging is enabled by default. If you need to disable or reenable Just-In-Time debugging, see Enabling or disabling Just-In-Time Debugging.

When Just-In-Time debugging is enabled, you can test your application outside of Visual Studio. When a crash or exception occurs, you will see a dialog box appears with a message that looks something like this:

An unhandled exception ('System.TypeInitializationException') occurred in terrarium.exe[3384]

When this dialog box appears, you can begin debugging with the following procedure.

To begin Just-In-Time debugging when an error occurs

  1. In the Just-In-Time Debugging dialog box, in the Possible Debuggers list, click New instance of Visual Studio 2012 or click an instance of Visual Studio that is already running.

  2. To use Visual Studio automatically for all future crashes, click Set the currently selected debugger as the default.

  3. If you want to choose what types of code you will be able to debug, click Manually choose the debugging engines. If you do not choose this option, Visual Studio automatically selects the appropriate debug engines for the type of code in your program.


我在run一个测试界面UI的工程中,遇到了一个NonComVisibleBaseClass异常,编译的时候不会遇到这个问题,网上搜了一下解决方案如下,在VS里:

1. Navigate to Debug->Exceptions...
2. Expand "Managed Debugging Assistants"
3. Uncheck the NonComVisibleBaseClass Thrown option.
4. Click [Ok]


______________________________________________________________________________________________________________

Just-In-Time debugging launches Visual Studio automatically when an exception or crash occurs in an application running outside Visual Studio. This enables you to test your application when Visual Studio is not running and begin debugging with Visual Studio when a problem occurs.

Just-In-Time debugging does not work for Windows Store apps. Just-In-Time debugging does not work for managed code that is hosted in a native application, such as Visualizers.

Using Just-In-Time debugging

When you install Visual Studio, Just-In-Time debugging is enabled by default. If you need to disable or reenable Just-In-Time debugging, see Enabling or disabling Just-In-Time Debugging.

When Just-In-Time debugging is enabled, you can test your application outside of Visual Studio. When a crash or exception occurs, you will see a dialog box appears with a message that looks something like this:

An unhandled exception ('System.TypeInitializationException') occurred in terrarium.exe[3384]

When this dialog box appears, you can begin debugging with the following procedure.

To begin Just-In-Time debugging when an error occurs

  1. In the Just-In-Time Debugging dialog box, in the Possible Debuggers list, click New instance of Visual Studio 2012 or click an instance of Visual Studio that is already running.

  2. To use Visual Studio automatically for all future crashes, click Set the currently selected debugger as the default.

  3. If you want to choose what types of code you will be able to debug, click Manually choose the debugging engines. If you do not choose this option, Visual Studio automatically selects the appropriate debug engines for the type of code in your program.


nonComVisibleBaseClass MDA

.NET Framework 4.5
Other Versions
0 out of 1 rated this helpful Rate this topic

The nonComVisibleBaseClass managed debugging assistant (MDA) is activated when a QueryInterface call is made by native or unmanaged code on the COM callable wrapper (CCW) of a COM-visible managed class that derives from a base class that is not COM visible. The QueryInterface call causes the MDA to activate only in cases where call requests the class interface or default IDispatch of the COM-visible managed class. The MDA is not activated when theQueryInterface is for an explicit interface that has the ClassInterfaceAttribute attribute applied and is explicitly implemented by the COM-visible class.

Symptoms

QueryInterface call made from native code that is failing with a COR_E_INVALIDOPERATION HRESULT. The HRESULT might be due to the runtime disallowing QueryInterface calls that would cause the activation of this MDA.

Cause

The runtime cannot allow QueryInterface calls for the class interface or default IDispatch interface of a COM-visible class that derives from a class that is not COM-visible because of potential versioning problems. For example, if any public members were added to the base class that is not COM-visible, existing COM clients using the derived class could potentially break because the vtable of the derived class, which contains the base class members, would be altered by such a change. Explicit interfaces exposed to COM do not have this problem because they do not include the base members of interfaces in the vtable.

Resolution

Do not expose the class interface. Define an explicit interface and apply the ClassInterfaceAttribute attribute to it.

Effect on the Runtime

This MDA has no effect on the CLR.

Output

The following is an example message for a QueryInterface call on a COM-visible class Derived that derives from a non-COM-visible class Base.

A QueryInterface call was made requesting the class interface of COM visible managed class 'Derived'. However since this class derives from non COM visible class 'Base', the QueryInterface call will fail. This is done to prevent the non COM visible base class from being constrained by the COM versioning rules. 
Configuration

<mdaConfig>  <assistants>    <nonComVisibleBaseClass />  </assistants></mdaConfig>

Just-In-Time debugging launches Visual Studio automatically when an exception or crash occurs in an application running outside Visual Studio. This enables you to test your application when Visual Studio is not running and begin debugging with Visual Studio when a problem occurs.

Just-In-Time debugging does not work for Windows Store apps. Just-In-Time debugging does not work for managed code that is hosted in a native application, such as Visualizers.

Using Just-In-Time debugging

When you install Visual Studio, Just-In-Time debugging is enabled by default. If you need to disable or reenable Just-In-Time debugging, see Enabling or disabling Just-In-Time Debugging.

When Just-In-Time debugging is enabled, you can test your application outside of Visual Studio. When a crash or exception occurs, you will see a dialog box appears with a message that looks something like this:

An unhandled exception ('System.TypeInitializationException') occurred in terrarium.exe[3384]

When this dialog box appears, you can begin debugging with the following procedure.

To begin Just-In-Time debugging when an error occurs

  1. In the Just-In-Time Debugging dialog box, in the Possible Debuggers list, click New instance of Visual Studio 2012 or click an instance of Visual Studio that is already running.

  2. To use Visual Studio automatically for all future crashes, click Set the currently selected debugger as the default.

  3. If you want to choose what types of code you will be able to debug, click Manually choose the debugging engines. If you do not choose this option, Visual Studio automatically selects the appropriate debug engines for the type of code in your program.


An option here is to turn off the managed Debugging Assistant for the "NonComVisibleBaseClass" exception in Visual Studio:

1. Navigate to Debug->Exceptions.
2. Expand "Managed Debugging Assistants"
3. Uncheck the NonComVisibleBaseClass Thrown option.
4. Click "OK"

Just-In-Time debugging launches Visual Studio automatically when an exception or crash occurs in an application running outside Visual Studio. This enables you to test your application when Visual Studio is not running and begin debugging with Visual Studio when a problem occurs.

Just-In-Time debugging does not work for Windows Store apps. Just-In-Time debugging does not work for managed code that is hosted in a native application, such as Visualizers.

Using Just-In-Time debugging

When you install Visual Studio, Just-In-Time debugging is enabled by default. If you need to disable or reenable Just-In-Time debugging, see Enabling or disabling Just-In-Time Debugging.

When Just-In-Time debugging is enabled, you can test your application outside of Visual Studio. When a crash or exception occurs, you will see a dialog box appears with a message that looks something like this:

An unhandled exception ('System.TypeInitializationException') occurred in terrarium.exe[3384]

When this dialog box appears, you can begin debugging with the following procedure.

To begin Just-In-Time debugging when an error occurs

  1. In the Just-In-Time Debugging dialog box, in the Possible Debuggers list, click New instance of Visual Studio 2012 or click an instance of Visual Studio that is already running.

  2. To use Visual Studio automatically for all future crashes, click Set the currently selected debugger as the default.

  3. If you want to choose what types of code you will be able to debug, click Manually choose the debugging engines. If you do not choose this option, Visual Studio automatically selects the appropriate debug engines for the type of code in your program.


检测到 NonComVisibleBaseClass 错误  

Just-In-Time debugging launches Visual Studio automatically when an exception or crash occurs in an application running outside Visual Studio. This enables you to test your application when Visual Studio is not running and begin debugging with Visual Studio when a problem occurs.

Just-In-Time debugging does not work for Windows Store apps. Just-In-Time debugging does not work for managed code that is hosted in a native application, such as Visualizers.

Using Just-In-Time debugging

When you install Visual Studio, Just-In-Time debugging is enabled by default. If you need to disable or reenable Just-In-Time debugging, see Enabling or disabling Just-In-Time Debugging.

When Just-In-Time debugging is enabled, you can test your application outside of Visual Studio. When a crash or exception occurs, you will see a dialog box appears with a message that looks something like this:

An unhandled exception ('System.TypeInitializationException') occurred in terrarium.exe[3384]

When this dialog box appears, you can begin debugging with the following procedure.

To begin Just-In-Time debugging when an error occurs

  1. In the Just-In-Time Debugging dialog box, in the Possible Debuggers list, click New instance of Visual Studio 2012 or click an instance of Visual Studio that is already running.

  2. To use Visual Studio automatically for all future crashes, click Set the currently selected debugger as the default.

  3. If you want to choose what types of code you will be able to debug, click Manually choose the debugging engines. If you do not choose this option, Visual Studio automatically selects the appropriate debug engines for the type of code in your program.


//z 2013-08-08 18:10:38 IS2120@BG57IV3.T831336281 .K[T188,L2036,R72,V2840]
Just-In-Time debugging launches Visual Studio automatically when an exception or crash occurs in an application running outside Visual Studio. This enables you to test your application when Visual Studio is not running and begin debugging with Visual Studio when a problem occurs.

Just-In-Time debugging does not work for Windows Store apps. Just-In-Time debugging does not work for managed code that is hosted in a native application, such as Visualizers.

Using Just-In-Time debugging

When you install Visual Studio, Just-In-Time debugging is enabled by default. If you need to disable or reenable Just-In-Time debugging, see Enabling or disabling Just-In-Time Debugging.

When Just-In-Time debugging is enabled, you can test your application outside of Visual Studio. When a crash or exception occurs, you will see a dialog box appears with a message that looks something like this:

An unhandled exception ('System.TypeInitializationException') occurred in terrarium.exe[3384]

When this dialog box appears, you can begin debugging with the following procedure.

To begin Just-In-Time debugging when an error occurs

  1. In the Just-In-Time Debugging dialog box, in the Possible Debuggers list, click New instance of Visual Studio 2012 or click an instance of Visual Studio that is already running.

  2. To use Visual Studio automatically for all future crashes, click Set the currently selected debugger as the default.

  3. If you want to choose what types of code you will be able to debug, click Manually choose the debugging engines. If you do not choose this option, Visual Studio automatically selects the appropriate debug engines for the type of code in your program.


错误提示:
检测到 NonComVisibleBaseClass
Message: 执行了 QueryInterface 调用,请求提供 COM 可见的托管类“MS.Internal.AutomationProxies.WindowsEditBox”的类接口。不过,由于该类是从非 COM 可见的类“MS.Internal.AutomationProxies.ProxyHwnd”派生的,QueryInterface 调用将失败。这样做的目的是避免非 COM 可见的基类受 COM 版本规则的约束。

错误分析:
Actuall this diag is not considered as an exception, it only display when you debug the Auto UI program, if you build a release version for your program, it will run normally, at least in my demo it was that.
    class Program
    {
        static void Main(string[] args)
        {
            Process pro = new Process();
            pro.StartInfo = new ProcessStartInfo("Excel.exe");
            pro.Start();
            
            Thread.Sleep(1000);
            AutomationElement excel = GetFirstWindow();// GetWindowElement("Microsoft Excel - Book1");
            excel.SetFocus();
            AutomationElementCollection view = null;
            view = excel.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "View"));
            AutomationElement test = view[0];
            InvokePattern btntest = test.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
            btntest.Invoke();

        }
if you step into this demo, it will give that diag, when you continue step, it will normal.

解决办法:
You can turn off the managed Debugging Assistant for the "NonComVisibleBaseClass" exception. In Visual Studio,

1. Navigate to Debug->Exceptions...
2. Expand "Managed Debugging Assistants"
3. Uncheck the NonComVisibleBaseClass Thrown option.
4. Click [Ok]



Just-In-Time debugging launches Visual Studio automatically when an exception or crash occurs in an application running outside Visual Studio. This enables you to test your application when Visual Studio is not running and begin debugging with Visual Studio when a problem occurs.

Just-In-Time debugging does not work for Windows Store apps. Just-In-Time debugging does not work for managed code that is hosted in a native application, such as Visualizers.

Using Just-In-Time debugging

When you install Visual Studio, Just-In-Time debugging is enabled by default. If you need to disable or reenable Just-In-Time debugging, see Enabling or disabling Just-In-Time Debugging.

When Just-In-Time debugging is enabled, you can test your application outside of Visual Studio. When a crash or exception occurs, you will see a dialog box appears with a message that looks something like this:

An unhandled exception ('System.TypeInitializationException') occurred in terrarium.exe[3384]

When this dialog box appears, you can begin debugging with the following procedure.

To begin Just-In-Time debugging when an error occurs

  1. In the Just-In-Time Debugging dialog box, in the Possible Debuggers list, click New instance of Visual Studio 2012 or click an instance of Visual Studio that is already running.

  2. To use Visual Studio automatically for all future crashes, click Set the currently selected debugger as the default.

  3. If you want to choose what types of code you will be able to debug, click Manually choose the debugging engines. If you do not choose this option, Visual Studio automatically selects the appropriate debug engines for the type of code in your program.
    //z 2013-08-08 18:15:45 IS2120@BG57IV3.T336305916 .K[T189,L2047,R74,V2842]