Share via


VisualizerObjectSource Class

Definition

Provides access to the object being visualized.
Subclass this class to provide custom functionality.

public ref class VisualizerObjectSource
[Windows::Foundation::Metadata::WebHostHidden]
class VisualizerObjectSource
public class VisualizerObjectSource
type VisualizerObjectSource = class
Public Class VisualizerObjectSource
Inheritance
VisualizerObjectSource

Examples

[assembly: System.Diagnostics.DebuggerVisualizer(  
   typeof(MyFirstVisualizer.DebuggerSide),  
   // The object source is specified on the next line <<<<<  
   typeof(VisualizerObjectSource),  
   Target = typeof(System.String),  
   Description = "My First Visualizer")]  

Remarks

A visualizer is a small program that the Visual Studio debugger uses to display (visualize) an object of a specific data type in meaningful manner. To visualize an object, a visualizer uses code that runs in the debugger process (the debugger side) and code in the process being debugged (the debuggee side).

The debugger side and debuggee side communicate with each other by using VisualizerObjectSource and IVisualizerObjectProvider.

The debugee side uses the DebuggerVisualizerAttribute to specify a VisualizerObjectSource object for the debugger side. The debugger side has access to it indirectly through the IVisualizerObjectProvider interface.

Constructors

VisualizerObjectSource()

Properties

IsBinaryFormatterSupported

Returns true if the debuggee process where the visualizer is hosted supports the Binary Formatter class. If that is not the case, classes that derive from this class should serialize their objects via JSON.

SelectedFormatterPolicy

The format policy that this class intends to use when serializing/deserializing information. However, it can be overridden by the debugger in scenarios where the chosen format policy is not supported.

Methods

CreateReplacementObject(Object, Stream)

Creates and returns a replacement object for the object passed in based on the serialized data.

Deserialize(Stream)
Obsolete.

Legacy helper method used by old visualizers that makes it easier to write serialization code. It uses default binary serialization to read the given object from the stream. However, due to security vulnerabilities with its usage, it should no longer be used, and will throw on newer versions of .NET like ASP.NET Core 5.0.

If called on a target app that supports Binary Serialization, after the method finishes the stream read pointer is advanced past the bytes of the object

DeserializeFromJson(Stream, Type, Object)

Deserializes the data in JSON format from the specified stream into an object of a specific type using the Newtonsoft.Json library.

DeserializeFromJson<T>(Stream, Object)

Deserializes the data in JSON format from the specified stream into an object of a specific type using the Newtonsoft.Json library.

GetData(Object, Stream)

Gets a blob of data. Writes data from the object into the memorystream.

GetDeserializableObject(Stream)

Helper method that can be used to get a deserializable object for cases in which the target app might not support Binary Serialization. In these cases the underlying format should be serialized using JSON, so callers can query individual properties to determine the type of the object they want to deserialize.

Serialize(Stream, Object)

Serializes the specified object into a stream.

By default, objects will be serialized using binary serialization via the BinaryFormatter. However, if the target app does not support binary serialization (as in the case of ASP.NET Core 5.0+ applications), the method will serialize the object using whatever JSON serialization technology is available.

Binary serialization is not supported in out of process visualizers. Therefore, this method will always serialize them using the Newtonsoft.Json library.

SerializeAsJson(Stream, Object, Object)

Serializes the specified object as JSON into a stream using the Newtonsoft.Json library.

TransferData(Object, Stream, Stream)

Invoked when the UI-side visualizer type calls IVisualizerObjectProvider.TransferData(Stream) or IVisualizerObjectProvider.TransferObject(object).

This method can be used to define a custom message passing protocol to communicate between the UI-side and debuggee-side visualizer types, or to invoke custom actions on the debuggee-side visualizer type. The UI-side visualizer type can pass in arbitrary data serialized into incomingData and the debuggee-side visualizer type can respond with arbitrary data serialized into outgoingData.

Applies to