Exception Stack Trace Truncated When Using Resolved Class

Oct 20, 2010 at 8:06 PM


Suppose I have two methods Alpha and BetaAlpha uses Unity to resolve Betas's class from the container, then invokes BetaBeta throws an exception (i.e. a simple "throw new Exception("Ouch!");" ).  However, the stack trace of the exception does not show Alpha even though a call to Environment.StackTrace right before the exception shows Alpha in the call stack.  The call stack starts at the point of entry into Beta.  Is there anyway to get the stack trace to show the complete stack trace all the way up to Alpha?  I can shove the entire stack trace into the message, but this is not a very elegant solution.

I suspect that this is similar to this thread, but I'm not using Policy Injection.


Any help would be appreciated.


Oct 20, 2010 at 11:15 PM

I believe the related thread you posted has the same issue since the user was actually using VirtualMethodInterceptor.  It only mentioned that the same issue applies to Policy Injection.  This thread pertains to the same topic.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Oct 21, 2010 at 4:57 PM

Could you post a repro sample? I can't imagine how this would be happening right now, so I'd need to see an example.

Oct 21, 2010 at 6:37 PM


Since this is scrubbed code, but here's essentially what's happening.  Alpha is a singleton, but Beta is not.

public class BetasClass
    public void Beta()
        throw new Exception("I crash now");

public class AlphasClass
    public void Alpha()
          //I actually have a static class that acts as a wrapper for the container instance so I don't have to contantly reload
          IUnityContainer unityContainerInstance = new UnityContainer();

          BetasClass betaClass = unityContainerInstance.Resolve<BetasClass>();

          //Stacktrace only shows Beta() but not Alpha();
The configuration is


    <add alias="ContainerControlledLifetimeManager" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />   

<add alias="AlphasClass" type="App.AlphasClass, App" />

    <add alias="BetasClass" type="App.BetasClass, App" />

<register type="BetasClass" />
    <register type="AlphasClass" mapTo="AlphasClass" >
      <lifetime type="ContainerControlledLifetimeManager"/>