Problem with Exception Handling in WCF, try catch not work
i have a wcf service (nettcpbinding, duplex) wich works very well. today i hit a very wierd problem. the following code runs fine and if "new A("123");" throws an exception, its catched.
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single)]
public class Service: ITestService
{
// the interface is defined as [OperationContract(IsOneWay = true)], so fire and forget
开发者_JAVA技巧public void Test()
{
try
{
var t = new A("123");
}
catch(Exception ex)
{}
}
}
BUT if i change the A.dll and change the method parameters, i expect to get a MissingMethodException. What i get is nothing from WCF:( the WCF Service just abort and on client side i get the Faulted event for my WCF channel.
So why does my catch does not work? Does WCF handle such xceptions on another way?
thx for help
The failure doesn't happen at the point when you create A, it fails at JIT compilation of the method Test which is outside of your try/catch block.
If you move the creation of A to another method and call that from your try block you will catch the exception
Something like this
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single)]
public class Service: ITestService
{
// the interface is defined as [OperationContract(IsOneWay = true)], so fire and forget
public void Test()
{
try
{
var t = GetA("123");
}
catch(Exception ex)
{}
}
private A GetA(string s)
{
return new A(s);
}
}
Try enabling logging on the WCF Service and look in the log. Some exceptions are not possible to catch in the WCF method or WCF client code but are rather caught by the WCF framework and can only be found through logging.
精彩评论