1

I have a C# class with a property that uses System.IO.Ports.SerialPort to query data from a device.

When broken into the program with the debugger, evaluating that property first shows

Evaluation of method (...) calls into native method Microsoft.Win32.Win32Native.CreateEvent
(Microsoft.Win32.Win32Native+SECURITY_ATTRIBUTES, bool, bool, string).
Evaluation of native methods in this context is not supported.

and then apparently still tries to execute it, showing

Function evaluation disabled because a previous function evaluation timed out. You must
continue execution to reenable function evaluation.

afterwards and leaves the serial port object in an invalid state.

I can hide the property from being shown when looking at the parent object by setting DebuggerBrowsableAttribute.

However, moving the mouse over the property name itself still evaluates the property. Is it possible to suppress this as well, or at least let the code detect that it is executing in a debugger context and skip its evaluation?

Dale K
  • 25,246
  • 15
  • 42
  • 71
Timbo
  • 27,472
  • 11
  • 50
  • 75
  • 2
    https://stackoverflow.com/questions/572082/is-there-a-net-attribute-to-prevent-property-evaluation-within-the-debugger - although frankly, I'd say that if you are doing P/Invoke, this **should not be a property** - it should be a method – Marc Gravell Oct 24 '19 at 09:12
  • Possible duplicate of [Is there a way to detect if a debugger is attached to another process from C#?](https://stackoverflow.com/questions/2188201/is-there-a-way-to-detect-if-a-debugger-is-attached-to-another-process-from-c) –  Oct 24 '19 at 09:17
  • @MarcGravell thanks for the link, feels like a "no". But you are right, if it does not work anyway, it can be a method as well. My preference for properties mainly comes from being able to quickly get a picture of the state of things using the debugger anyway. – Timbo Oct 24 '19 at 09:23
  • "My preference for properties mainly comes from being able to quickly get a picture of the state of things using the debugger anyway." - which is also exactly the thing you're trying to prevent here, so... – Marc Gravell Oct 24 '19 at 09:25
  • Is this happening when you try to step into the Serial Port Library while debugging? Then do not step into the methods that give error. I suspect in this case the debugger has it own version of serial port that is different from the one the device is using and causes a conflict. – jdweng Oct 24 '19 at 09:26

0 Answers0