DataTable descendant with DebuggerDisplay attribute loses DebuggerVisualizer
I have a descendant of DataTable that has the DebuggerDisplay attribute defined. The default visualizer for DataTable is removed when I add the DebuggerDisplay attribute. If I remove the DebuggerDisplay attribute, the DataTable visualizer returns. I want the default DataTable visualizer and my override for DebuggerDisplay.
Do you guys know how to get it working?
//does not work
//[DebuggerVisualizer("Microsoft.VisualStudio.D开发者_C百科ebugger.DataSetVisualizer", typeof(DataTable))]
//DebuggerDisplay attribute removes DataTable visualizer. Odd behavior to me.
[DebuggerDisplay("{TableName}, Count = {Rows.Count}, {GetColumnNames()}")]
public class MyTable<T> : DataTable where T : class{}
Just to clarify, I've got no idea why deriving and specifying a different attribute disables the visualizer.
I've tried something similar and nothing stops you from having both DebuggerDisplay
and DebuggerVisualizer
applied to a type. The image below shows both, the left circle is the debugger visualizer, the right circle is the debugger display:
However, you may get issues with trying to use the DataSetVisualizer
type on your class. It took a lot of jiggery-pokery, but I ended up with the following definition for my class:
[Serializable]
[DebuggerVisualizer(typeof(EnhancedDataSetVisualizer.DataSetVisualizer),
typeof(EnhancedDataSetVisualizer.DataSetVisualizerSource))]
[DebuggerDisplay("{Name}")]
public sealed class SpecFlowTableWrapper : DataSet
{
// Body omitted, not important.
}
I was constantly having to change what arguments I specified in DebuggerVisualizer
. It turns out the missing piece for me was specifying the VisualizerObjectSource
.
I then get the debugger display showing my data set name, and when I click the magnifying glass it loads the DataSetVisualizer
.
The important part in all this is two references:
- Microsoft.VisualStudio.Debugger.DataSetVisualizer
This contains the DataSetVisualizer
and DataSetVisualizerSource
types.
- Microsoft.VisualStudio.DebuggerVisualizers
This is a dependency of the other reference.
The second item is generally available in the "Add References..." dialog in Visual Studio, however the first item is found in the VS installation directory.
For me (VS version may vary):
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\Visualizers\
Called:
Microsoft.VisualStudio.Debugger.DataSetVisualizer.dll
Make sure "Copy Local" is true for the first reference as well (it should be true by default anyway). Note that for debugging, this reference is now a dependency so you need to make sure it is in the working directory of whatever project you are debugging, otherwise you get VS debugger errors.
Re-build, start debugger, enjoy. Sorry it was 2 years late.
精彩评论