开发者

StructureMap fails on IIS 7.5 with AppPoolIdentity

开发者 https://www.devze.com 2023-02-20 13:28 出处:网络
I have a problem with ASP.NET MVC application hosted on IIS 7.5 on separate application pool, configured with AppPoolIdentity and .NET 4.0 Framework.

I have a problem with ASP.NET MVC application hosted on IIS 7.5 on separate application pool, configured with AppPoolIdentity and .NET 4.0 Framework.

The application is working normally for some time and suddenly part of controllers start to throw an exception inside StructureMap:

开发者_StackOverflow

System.ArgumentNullException: Trying to find an Instance of type [MyType] Parameter name: instance

in StructureMap.InstanceCache.Get(Type pluginType, Instance instance) +376

The type requested was registered correctly (and was resolved properly just a minute before the exception occured). I can't verify it is still registered, as WhatDoIHave throws an exception, too:

NullReferenceException: Object reference not set to an instance of an object. in StructureMap.Diagnostics.WhatDoIHaveWriter.writeInstance(InstanceRef instance) +133

Looks like StructureMap's internal cache gets corrupted somehow.

The problem disappears when I change AppPoolIdentity to "real" local system user credentials. So it looks like the problem is somewhere between IIS and StructureMap. Maybe app pool recycling makes problems here? But it is configured to recycle every 1740 minutes and it fails sometimes after 5 minutes from its start...


Well, the problem appeared to be very different, I don't know how it may looked like connected to app pools and privileges.

The flaw is in GetNamedInstance<T> StructureMap's container method. I requesting a named instance, which is not registered, StructureMap tries to create the instance and add it to the container. Creation fails, but nevertheless, StructureMap registers null in the container. Each subsequent request for that named instance fails when encounter this null.

Our workaround is that we use GetAllInstances<T> instead of GetNamedInstance<T> and iterate manually through all instances of T to find matching one.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号