1

WCF のサービス層の FirstChangeException イベント ハンドラーを試しています。目的は、任意のメソッドから例外をキャプチャし、それを新しい FaultException としてスローして、クライアントに戻せるようにすることです。

たとえば、以下はテストサーバークラスです

private static bool thrown;
public class EchoService : _BaseService, IEchoService
{
    public EchoService()
    {
        AppDomain.CurrentDomain.FirstChanceException += HandleFirstChanceException;
    }

    private void HandleFirstChanceException(object sender, FirstChanceExceptionEventArgs e)
    {
        if (thrown == false)
        {
            thrown = true;
            throw new FaultException<Exception>(e.Exception);
        } 
    }

    public DTO_Echo_Response SendEcho(DTO_Echo_Request request)
    {
        DTO_Echo_Response response = new DTO_Echo_Response();

        //SO note: AppError inherits from Exception.
        if (request.ThrowTestException) throw new AppError("Throwing test exception");

        return response;
    }
}

ただし、return前の呼び出しが新しい例外のスローによるものであったため、行の関数を終了すると、次のエラーが発生します。

The runtime has encountered a fatal error. The address of the error was at 0x750916ed, on thread 0x1d5c. The error code is 0x80131506. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

私は愚かなことをしているに違いない。すべての例外ハンドラーをキャッチするという目的を達成するにはどうすればよいですか?

4

1 に答える 1