我有一个自定义 HttpModule 可以使用内置的 VS 服务器正常工作,但不会从我设置的 IIS 7.5 服务器运行。c# 文件甚至没有被调用。该模块包含在 system.web 中,但是当我在 中添加对该模块的另一个引用时system.webserver
,该项目将无法加载,并且出现结构映射 202 异常代码的错误。
我怀疑这个错误的原因与什么时候Structuremap
被初始化有关,但我似乎无法弄清楚。我从文件中的ObjectFactor
y初始化,它工作正常,直到我尝试加载这个模块。Application_Start
global.asax
任何帮助将不胜感激。
错误是:
StructureMap Exception Code: 202
No Default Instance defined for PluginFamily testproject.test.Core.DataAccess.IAccountRepository, testproject.test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1136
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +23
System.Web.HttpRuntime.CreateNonPublicInstance(Type type, Object[] args) +60
System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) +231
System.Web.HttpApplication.GetModuleCollection(IntPtr appContext) +1365
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +95
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253
[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9090876
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
更新 - 如果我在我试图调用的模块中初始化对象工厂,站点将再次加载并且处理程序工作。然后在每个加载的页面上调用以下内容时似乎效率低下且不必要。之前,我可以在全局文件的 application_start 中加载一次。
ObjectFactory.Initialize(x =>
{
x.UseDefaultStructureMapConfigFile = true;
});