I’m having a very strange occurrence in VS2010 C#. I’m using a WCF PubSub framework with callbacks over netTcpBinding. Strangely in one code block within my large solution an exception is being thrown (which I totally expect and am coding towards) but the debugger is stopping showing the exception being thrown as if there is no try or catch. Now when I run the application outside VS as just the .exe the program does not crash and the exceptions are being handled accordingly. What’s even stranger is when I created a lightweight version of this app inside a new blank solution, the exceptions are being caught in VS during debug mode, but when I added this same lightweight project to the original large project again the exceptions are not being caught. Here’s the block of code, although I think the issue is something to do with the settings in VS for this solution, that’s my only guess.
Basically, when a client closes unexpectedly and the service tries to send to a faulted client/subscriber the catch will handle this and just remove the subscriber from the list. The List of _subscribers is static readonly list. I’ve tried making the service singleton and not using a static keyword on the list, but it seems to make no difference. I can’t zip and post the entire solution which this resides in for obvious reasons.
public void UpdateData(Action<T> action)
{
_subscribers.ForEach(subscriber =>
{
var client = subscriber as ICommunicationObject;
try
{
if (client != null && client.State == CommunicationState.Opened)
action(subscriber);
else
Unsubscribe(subscriber);
}
catch
{
Unsubscribe(subscriber);
}
}
);
}
Heinzi’s answer above fixed the issue, it can be resolved here:
http://stevesmithblog.com/blog/visual-studio-break-when-exception-thrown/