c# 4.0 - Exception.GetBaseException() returning exception with not null InnerException -
i've exception of type system.aggregateexception:
message = "one or more errors occurred." source = null stacktrace = null it's innerexception system.reflection.targetinvocationexception:
message = "exception has been thrown target of invocation." source = "mscorlib" stacktrace = @ system.runtimemethodhandle.invokemethod(object target, object[] arguments, signature sig, boolean constructor) @ system.reflection.runtimemethodinfo.unsafeinvokeinternal(object obj, object[] parameters, object[] arguments) @ system.reflection.runtimemethodinfo.invoke(object obj, bindingflags invokeattr, binder binder, object[] parameters, cultureinfo culture) @ system.reflection.methodbase.invoke(object obj, object[] parameters) @ microsoft.aspnet.signalr.hubs.hubdispatcher.incoming(ihubincominginvokercontext context) it's innerexception exception created me extends applicationexception:
message = "some error writen me @ hub" source = "chat" stacktrace = @ chat.hubs.chathub.sendmessage(string text, string clientconnid) in d:\...chat\chat\hubs\chathub.cs:line 48 when run this:
exception excpetion = ex.getbaseexception(); where ex system.aggregateexception system.reflection.targetinvocationexceptionat excpetion. how can happen?
scenario
i don't know how reproduce in simple project. in case found signalr project. hub method throwing exception handle errors @ global.asax:
globalhost.hubpipeline.addmodule(new myhubpipelinemodule()); and myhubpipelinemodule should this:
public class myhubpipelinemodule : hubpipelinemodule { protected override void onincomingerror(exception ex, ihubincominginvokercontext context) { exception excpetion = ex.getbaseexception(); context.hub.clients.caller.exceptionhandler(excpetion.message); } } note: should done signalr 1.0.1. in 1.1.0 exception simpler (smaller chain) works well. make sure have packages versions:
<package id="microsoft.aspnet.signalr" version="1.0.1" targetframework="net40" /> <package id="microsoft.aspnet.signalr.core" version="1.0.1" targetframework="net40" /> <package id="microsoft.aspnet.signalr.js" version="1.0.1" targetframework="net40" /> <package id="microsoft.aspnet.signalr.owin" version="1.0.1" targetframework="net40" /> <package id="microsoft.aspnet.signalr.systemweb" version="1.0.1" targetframework="net40" />
according msdn getbaseexception should behave like
public exception getbaseexception() { exception result = this; while (result.innerexception != null) result = result.innerexception; return result; } and states
for exceptions in chain of exceptions, getbaseexception method must return same object (the base exception).
which begs question, why method virtual? seem override match implementation or violate contract.
according msdn aggregateexception.getbaseexception
returns aggregateexception root cause of exception.
by op's statement (and inspection of source), "returns aggregateexception" can violated because result not always aggregateexception.
frankly, find whole statement non-sequitur consider 'first' non-aggregateexception "the root cause of exception" insofar 1 can identify singular ("the") root cause. since "regular" exceptions wrapped in aggregateexceptions 1 moves toward root of parallel processing 'fan out'.
my best interpretation aggregateexception.getbaseexception intended "unwrap" pointlessly non-parallel nested aggregateexceptions until reaching level 'fan out' occurs.
the problem here appear happens when there no 'fan out', i.e. aggregateexception 1 (non-aggregate) innerexception(s). in case returns (non-aggregate) exception. .... has different getbaseexception implementation/interpretation.
Comments
Post a Comment