3

I try to make Visual Studio Extension. It will be extension for debug. It will work at debug mode. I need get object instance from debugged application in my extension. And I do not know how to do it.

I have follow code:

var dte = (DTE)_serviceProvider.GetService(typeof(DTE));
var debugger = dte?.Debugger;
var currentMode = debugger?.CurrentMode;
if (currentMode != dbgDebugMode.dbgBreakMode) return;

var expression = debugger.GetExpression(myExpression);

myExpression contains expression for retrieve some object, for example IDbConnection.

How can I get IDbConnection in my extension-code? expression.Value has string-value.

Is that even possible?

Андрей NOP
  • 203
  • 5
  • 16
  • Do you mean this [IDbConnection](https://learn.microsoft.com/en-us/dotnet/api/system.data.idbconnection?view=netframework-4.8), if so please check [this document](https://learn.microsoft.com/en-us/dotnet/api/envdte.expression?view=visualstudiosdk-2017), it's not supported to retrieve IDBConnection from an object of Expression. – LoLance Nov 05 '19 at 11:06
  • @LanceLi-MSFT, for example: in debugged application I have code: `var connection = new SqlConnection(...); ...;`. I make breakpoint after this code and in my VS extension I write: `string myExpression = "connection"; ...; var expression = debugger.GetExpression(myExpression);` How can I get IDbConnection instance in VS extension code? I have `expression.IsValidValue == true` and `expression.Type == "System.Data.SqlClient.SqlConnection"`, but I cannot retrieve IDbConnection instance from `expression`. Is it possible? – Андрей NOP Nov 05 '19 at 12:16
  • 1
    [No](https://stackoverflow.com/a/2188441/17034) – Hans Passant Nov 06 '19 at 19:52
  • Maybe you should look into Concord which is VS's underlying debugger engine, it's powerful but only partially documented: https://github.com/microsoft/ConcordExtensibilitySamples – Simon Mourier Nov 07 '19 at 08:36
  • if expression is valid you should be able to retrieve it with Value property. And expression should be the variable name what you want to retrieve – Eldar Nov 12 '19 at 19:49
  • Yes, I can retrieve Value, but Value is not object, it is string. @Eldar – Андрей NOP Nov 12 '19 at 19:53
  • 1
    It seems you can only retrieve string from DTE. If it is a complex object DataMembers property will be populated and you can find the property via iterating that collection but all you get will be strings not actual objects. – Eldar Nov 12 '19 at 20:06

0 Answers0