简体   繁体   中英

StructureMap fails on IIS 7.5 with AppPoolIdentity

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM