How to set a VisualizerTargetType of type byte*?

Bodo Scheumann 0 Reputation points
2024-10-20T14:54:22.7066667+00:00

I am trying to write a visualizer for VS2022. I managed to set it up for the byte[], but failing for the type byte*.

the line
new VisualizerTargetType("Byte* Visualizer", typeof(byte*)) gives me an compile time error.

If I use byte[] instead, i can call the Visualizer from the debugee side on an element of byte*, but it gives me an error message of "Invalid ObjRef provided"

How do I tell the visualizer the right object type?

Visual Studio Extensions
Visual Studio Extensions
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Extensions: A program or program module that adds functionality to or extends the effectiveness of a program.
225 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bodo Scheumann 0 Reputation points
    2024-10-21T12:22:30.3166667+00:00

    I am using the latest version of VS2022.

    I was trying to use the 'new' Extension implementation and followed the following docs:

    https://blog.elmah.io/creating-custom-debug-visualizers-for-visual-studio-2022/

    https://github.com/MicrosoftDocs/visualstudio-docs/blob/main/docs/extensibility/visualstudio.extensibility/inside-the-sdk/remote-ui.md

    https://github.com/MicrosoftDocs/visualstudio-docs/blob/main/docs/extensibility/visualstudio.extensibility/debugger-visualizer/debugger-visualizers.md

    targeting net8.0.

    so the interesting parts are quite short:

    /// <summary>
    /// Debugger visualizer provider class for <see cref="System.String"/>.
    /// </summary>
    [VisualStudioContribution]
    internal class CTypesDebuggerVisualizerProvider : DebuggerVisualizerProvider
    {
      /// <summary>
      /// Initializes a new instance of the <see cref="CTypesDebuggerVisualizerProvider"/> class.
      /// </summary>
      /// <param name="extension">Extension instance.</param>
      /// <param name="extensibility">Extensibility object.</param>
      public CTypesDebuggerVisualizerProvider(
        CTypesVisualizer.CTypesDebuggerVisualizerExtension extension, 
        VisualStudioExtensibility extensibility)
          : base(extension, extensibility)
      {
      }
      /// <inheritdoc/>
      public override DebuggerVisualizerProviderConfiguration DebuggerVisualizerProviderConfiguration
          => new
        (
            //new VisualizerTargetType("Byte* Visualizer", typeof(byte*).AssemblyQualifiedName!),
            //new VisualizerTargetType("Byte* Visualizer", typeof(byte*)),
            new VisualizerTargetType("CTypes Visualizer", typeof(Byte[]))
        )
          {
            VisualizerObjectSourceType = new(typeof(CTypesVisualizerSource.CTypesObjectSource)),
          };
      /// <inheritdoc/>
      public override async Task<IRemoteUserControl> CreateVisualizerAsync(
        VisualizerTarget visualizerTarget, CancellationToken cancellationToken)
      {
        
        VisualizerObjectSourceClient client = visualizerTarget.ObjectSource;
        CTypesModel? model = await visualizerTarget
        .ObjectSource
        .RequestDataAsync<CTypesModel>(jsonSerializer: null, CancellationToken.None);
        return await Task.FromResult<IRemoteUserControl>(
            new CTypesVisualizer.CTypesVisualizerUserControl(model));
      }
    }
    
    

    and on the other side

      public class CTypesObjectSource : VisualizerObjectSource
      {
        
        public CTypesObjectSource()
        {
        }
        public override void GetData(object target, Stream outgoingData)
        {
              var result = new CTypesModel
              {
                Name = "Test byte[]",
                Length = 0,
                DataString = "Test Mode Data"
              };
              SerializeAsJson(outgoingData, result);
        }
      }
    
    
    

    the Byte[] type seems to also apply for the byte* variable ....

    User's image

    but if i click the view, i get the error message

    User's image

    if i do the same on a 'real' byte[] variable, everything works fine.

    The exception occurs before the GetData method on the debugee-side is called.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.