Visual Studio doesn't understand proxied code?
-
So I've been working on a personal project, and it's come to the point where I'm sitting back, looking at it, and thinking "hey, let's maybe make this a little more versatile". So I've been working on a small library whose only function is to proxy some of the classes I've made, to automate their behaviour. One of these modifications is adding a
[Suppress]
attribute (C#) to a method, property or constructor, and having the method bodies encapsulated in atry..catch
block to suppress exceptions which aren't necessarily important (for some optional methods where execution can continue regardless) So I generated the code using theTypeBuilder
class, and created an override method for the virtual method, add thetry
block, call the base method, add thecatch
block, and do any returns as necessary. The exception is caught by this proxied method (I added aDebug.WriteLine
to confirm thecatch
block is working), however Visual Studio still breaks in the method which raised the exception! I'm guessing that because Visual Studio doesn't have visibility/understanding of what the proxied class is doing, it just processes the base method as usual and breaks. Is there a way, at all, to stop this behaviour from happening? I mean, it's great for situations where I don't want the exceptions suppressed, but the whole point of adding the[Suppress]
attribute was to specifically signal that I don't care if an exception is thrown!MQ / Tor.NET / Angry Potato
-
So I've been working on a personal project, and it's come to the point where I'm sitting back, looking at it, and thinking "hey, let's maybe make this a little more versatile". So I've been working on a small library whose only function is to proxy some of the classes I've made, to automate their behaviour. One of these modifications is adding a
[Suppress]
attribute (C#) to a method, property or constructor, and having the method bodies encapsulated in atry..catch
block to suppress exceptions which aren't necessarily important (for some optional methods where execution can continue regardless) So I generated the code using theTypeBuilder
class, and created an override method for the virtual method, add thetry
block, call the base method, add thecatch
block, and do any returns as necessary. The exception is caught by this proxied method (I added aDebug.WriteLine
to confirm thecatch
block is working), however Visual Studio still breaks in the method which raised the exception! I'm guessing that because Visual Studio doesn't have visibility/understanding of what the proxied class is doing, it just processes the base method as usual and breaks. Is there a way, at all, to stop this behaviour from happening? I mean, it's great for situations where I don't want the exceptions suppressed, but the whole point of adding the[Suppress]
attribute was to specifically signal that I don't care if an exception is thrown!MQ / Tor.NET / Angry Potato
And just like that, I found the cause of the problem almost as soon as I posted this message. It turns out there's a Visual Studio setting called "Just My Code" under the Tools > Options > Debugging > General window. Turning this off means that Visual Studio accounts for externally generated code, and therefore factors in the
try..catch
which I added in the proxied type. This message seems like a bit of a waste, but I suppose it's here if anyone else needs it.MQ / Tor.NET / Angry Potato