unitycontainer / interception

Unity.Interception package
Apache License 2.0
22 stars 18 forks source link

NullReferenceException in Unity.Interception.Interceptors.GenericParameterMapper.Map #23

Closed mmulhearn closed 5 years ago

mmulhearn commented 5 years ago

We are currently finding an issue where we are testing a DC failover and are getting null exceptions when we fail over to another DC. The app recovers, but the first few hits give us this error:

problemId: System.NullReferenceException at Unity.Interception.Interceptors.GenericParameterMapper.Map method: Unity.Interception.Interceptors.GenericParameterMapper.Map outerType: Unity.Exceptions.ResolutionFailedException assembly: Unity.Interception, Version=5.5.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0 outerAssembly: Unity.Container, Version=5.8.6.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0

It's resolving a type that is clearly defined and works, but the initial hits fail and we don't know why.

Here is the stack trace:

[ { "parsedStack": [ { "assembly": "Unity.Container, Version=5.8.6.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0", "method": "Unity.UnityContainer.ThrowingBuildUp", "level": 0, "line": 0 }, { "assembly": "Unity.Container, Version=5.8.6.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0", "method": "Unity.UnityContainer.Resolve", "level": 1, "line": 0 }, { "assembly": "Unity.Abstractions, Version=3.3.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f", "method": "Unity.UnityContainerExtensions.Resolve", "level": 2, "line": 0 }, { "assembly": "Company.Cs.ObjectFactory.Unity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "method": "Company.Cs.ObjectFactory.Unity.ObjectFactory.Create", "level": 3, "line": 0 }, { "assembly": "Company.Cs.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "method": "Company.Cs.Web.Mvc.Filters.SingleSignOnAuthorizationFilter.get_TokenStore", "level": 4, "line": 0 }, { "assembly": "Company.Cs.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "method": "Company.Cs.Web.Mvc.Filters.SingleSignOnAuthorizationFilter.OnAuthorization", "level": 5, "line": 0 }, { "assembly": "Company.Cs.InternalChat.Web.Ui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "method": "Company.Cs.InternalChat.Web.Ui.Filters.SsoAuthorizationFilter.OnAuthorization", "level": 6, "line": 0 }, { "assembly": "System.Web.Mvc, Version=5.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", "method": "System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters", "level": 7, "line": 0 }, { "assembly": "System.Web.Mvc, Version=5.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", "method": "System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass3_1.b__0", "level": 8, "line": 0 } ], "outerId": "0", "message": "Resolution of the dependency failed, type = 'Company.Cs.Interfaces.TokenStores.ISingleSignOnTokenStore', name = '(none)'.\nException occurred while: while resolving.\nException is: NullReferenceException - Object reference not set to an instance of an object.\n-----------------------------------------------\nAt the time of the exception, the container was: \r\n Resolving Company.Cs.Interfaces.TokenStores.ISingleSignOnTokenStore,(none)\r\n", "type": "Unity.Exceptions.ResolutionFailedException", "id": "9781729" }, { "parsedStack": [ { "assembly": "Unity.Interception, Version=5.5.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0", "method": "Unity.Interception.Interceptors.GenericParameterMapper.Map", "level": 0, "line": 0 }, { "assembly": "Unity.Interception, Version=5.5.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0", "method": "Unity.Interception.Interceptors.InstanceInterceptors.InterfaceInterception.InterfaceMethodOverride.CreateDelegateImplementation", "level": 1, "line": 0 }, { "assembly": "Unity.Interception, Version=5.5.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0", "method": "Unity.Interception.Interceptors.InstanceInterceptors.InterfaceInterception.InterfaceImplementation.Implement", "level": 2, "line": 0 }, { "assembly": "Unity.Interception, Version=5.5.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0", "method": "Unity.Interception.Interceptors.InstanceInterceptors.InterfaceInterception.InterfaceImplementation.Implement", "level": 3, "line": 0 }, { "assembly": "Unity.Interception, Version=5.5.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0", "method": "Unity.Interception.Interceptors.InstanceInterceptors.InterfaceInterception.InterfaceInterceptorClassGenerator.CreateProxyType", "level": 4, "line": 0 }, { "assembly": "Unity.Interception, Version=5.5.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0", "method": "Unity.Interception.Interceptors.InstanceInterceptors.InterfaceInterception.InterfaceInterceptor.CreateProxy", "level": 5, "line": 0 }, { "assembly": "Unity.Interception, Version=5.5.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0", "method": "Unity.Interception.Intercept.ThroughProxyWithAdditionalInterfaces", "level": 6, "line": 0 }, { "assembly": "Unity.Interception, Version=5.5.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0", "method": "Unity.Interception.ContainerIntegration.ObjectBuilder.InstanceInterceptionStrategy.PostBuildUp", "level": 7, "line": 0 }, { "assembly": "Unity.Container, Version=5.8.6.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0", "method": "Unity.UnityContainer.ThrowingBuildUp", "level": 8, "line": 0 } ], "outerId": "9781729", "message": "Object reference not set to an instance of an object.", "type": "System.NullReferenceException", "id": "20687649" } ]

ENikS commented 5 years ago

You might want to run newer version of Unity. A lot has changed since Container 5.8.6 Please feel free to reopen if you find the same issue with 5.9 version.

mmulhearn commented 5 years ago

@ENikS i'm in the process of updating to the latest nugets and found that System.ValueTuple is included in the Unity nuget package (the one with Unity.Container and Unity.Abstractions). Is there a reason the DLL is directly included rather than referencing the System.ValueTuple nuget? I reference the System.ValueTuple nuget and I'm afraid this is going to cause issues in the long run.

ENikS commented 5 years ago

I am not sure what is the best approach here. I am including the latest package NuGet manager suggesting but perhaps there is a better way of doing it.

I am open to suggestions if you know better way of doing it.

mmulhearn commented 5 years ago

Looking at your nuspec file, it looks like you have the System.ValueTuple dependency specified:

<dependencies>
      <group targetFramework=".NETFramework4.0">
        <dependency id="System.ValueTuple" version="4.5.0" exclude="Build,Analyzers" />
      </group>
      <group targetFramework=".NETFramework4.5">
        <dependency id="System.ValueTuple" version="4.5.0" exclude="Build,Analyzers" />
      </group>
      <group targetFramework=".NETFramework4.6">
        <dependency id="System.ValueTuple" version="4.5.0" exclude="Build,Analyzers" />
      </group>
      <group targetFramework=".NETCoreApp1.0">
        <dependency id="System.ValueTuple" version="4.5.0" exclude="Build,Analyzers" />
      </group>
      <group targetFramework=".NETStandard1.0">
        <dependency id="System.ValueTuple" version="4.5.0" exclude="Build,Analyzers" />
      </group>
    </dependencies>

Which means you don't need to include System.ValueTuple in the lib folder. By doing that you, you confuse references between the System.ValueTuple nuget package you're referencing and the System.ValueTuple DLL you include in the lib folder.

ENikS commented 5 years ago

I am not explicitly including these in the lib folder. Package manager does it by itself. Am I missing something?

mmulhearn commented 5 years ago

Package manage should not be doing that. I generate nugets to be shared around my teams and that does not happen. I'm not sure how you're generating your nugets, either in your CI/CD pipeline or manually, but something is afoot. Dependencies should not be included in your lib folder.

ENikS commented 5 years ago

If you are that experienced with package management, could you suggest what am I doing wrong? Here is the configuration for the build https://github.com/unitycontainer/unity/tree/v5.x

mmulhearn commented 5 years ago

So, I'm not sure what mechanism you're using to trigger your package creation/publishing. Looking at Package.nuspec, you're including everything in a lib folder, but I'm not sure how that lib folder is being generated, nor what files are included in that lib folder. From what I can tell, you are probably copying your dependency DLLs into the lib folder and then packaging it all up.

ENikS commented 5 years ago

You are right. Lib folder is where I am storing output files during build and this is why these extra files are getting there. Thank you for the pointer, I've got it now.

Will fix it in the next release.

mmulhearn commented 5 years ago

Cool. Glad I could help. Keep up the good work. Glad someone picked up the framework and is keeping it going!