Visual studio breaks into an exception that is handled by IS with an unhandled exception dialog

My code calls the WCF service, which is not working. Therefore, we must expect EndPointNotFoundException. The using statement attempts a Close()damaged connection that calls CommunicationObjectFaultedException, which is thrown. This exception falls into the catch try block surrounding the use block:

class Program
{
    static void Main()
    {
        try
        {
            using (ChannelFactory<IDummyService> unexistingSvc = new ChannelFactory<IDummyService>(new NetNamedPipeBinding(), "net.pipe://localhost/UnexistingService-" + Guid.NewGuid().ToString()))
            {
                using (IClientChannel chan = (unexistingSvc.CreateChannel() as IClientChannel))
                {
                    (chan as IDummyService)?.Echo("Hello");
                }
            }
        }
        catch (EndpointNotFoundException ex)
        {
            Console.WriteLine("Expected");
        }
        catch (CommunicationObjectFaultedException ex)
        {
            Console.WriteLine("Expected: caused by closing channel that has thrown EndPointNotFoundException");
        }
    }
}

Please note that the EndPoint service uses the new Guid, so it will never listen to the service.

IDummyService:

[ServiceContract]
interface IDummyService
{
    [OperationContract]
    string Echo(string e);
}

This causes the Visual Studio debugger (Visual Studio Professional 2017 15.4.1) to crash into the Excluded Unhandled popup: The Screenshot: Debugging debugging with Exception Unhandled popup exception that Visual Studio breaks System.ServiceModel.CommunicationObjectFaultedExceptioninto is where gets into the code.

, catch(CommunicationObjectFaultedException ex). LinqPad , , .

() using -block:

class Program
{
    static void Main()
    {
        try
        {
            using (ChannelFactory<IDummyService> unexistingSvc = new ChannelFactory<IDummyService>(new NetNamedPipeBinding(), "net.pipe://localhost/UnexistingService-" + Guid.NewGuid().ToString()))
            {
                IDummyService chan = null;
                try
                {
                    chan = unexistingSvc.CreateChannel();
                    chan.Echo("Hello");
                }
                catch (EndpointNotFoundException ex)
                {
                    Console.WriteLine($"Expected: {ex.Message}");
                }
                finally
                {
                    try
                    {
                        (chan as IClientChannel)?.Close();
                    }
                    catch (CommunicationObjectFaultedException ex)
                    {
                        Console.WriteLine($"Caused by Close: {ex.Message}");
                    }
                }
            }
        }
        catch (EndpointNotFoundException ex)
        {
            Console.WriteLine("Expected");
        }
        catch (CommunicationObjectFaultedException ex)
        {
            Console.WriteLine("Expected: caused by closing channel that has thrown EndPointNotFoundException");
        }
    }
}

Close.

System.ServiceModel.CommunicationObjectFaultedException . ( , Visual Studio , , " " " " ).

"" \ "" \ "" \ " ", . , async, , , await Task. " "; . .

" " ( Jack Zhai-MSFT) Visual Studio Screen Encryption Dialog Box When :

, /.

, , , / .

CommunicationObjectFaultedException async ?

+4
2

Close() -ing a Faulted IClientChannel CommunicationObjectFaultedException:

public void Close(TimeSpan timeout)
{
    ...
    switch (originalState)
    {
        case CommunicationState.Created:
        case CommunicationState.Opening:
        case CommunicationState.Faulted:
            this.Abort();
            if (originalState == CommunicationState.Faulted)
            {
                throw TraceUtility.ThrowHelperError(this.CreateFaultedException(), Guid.Empty, this);
            }
            break;
        ...
    }
    ...
}

- (. CommunicationObject.Close(TimeSpan) # 299 .NET framework 4.7 ).

using -block try { ... } finally { Dispose(); } Dispose() Close(), . -, CreateChannel() RealProxy (src) RemotingServices.CreateTransparentProxy() , , .

( TOOLS- > OPTIONS- > Debugger- > General):

  • ☑ , AppDomain /

Visual Studio : " ": : Visual Studio:   (  ) : :  Visual Studio  ,  AppDomain  /

CommunicationObjectFaultedException 'Not My Code'; / AppDomain, "Not My Code"; , , " ", catch -block ( Visual Studio ).
"Not My Code" , " " Visual Studio , AppDomain / .
"break, AppDomain / " Visual Studio .

/

+1

Exception VS2017, " " TOOLS- > OPTION- > Debugging- > General, , .

, / : ,

", AppDomain / " TOOLS- > OPTION- > Debugging- > General. ", AppDomain / ", Visual Studio OP ( , , AppDomain /).

+2

Source: https://habr.com/ru/post/1687882/


All Articles