在自定义模块中包含Autofac.Module会破坏Orchard [英] Including Autofac.Module in custom module breaks Orchard
问题描述
See here & here for why I'm trying to do this.
我有一个正在构建的自定义模块(和往常一样,它是在Orchard .sln中是它自己的.csproj)
I have a custom module that I'm building (and which is it's own .csproj in the Orchard .sln, as normal)
我有一个(相对复杂的)依赖项,我希望将其注入到Orchard中. 目前,如果我构建并运行该代码,它会非常高兴,直到遇到我的依赖项,此时它会成为null引用(正如我期望的那样).我可以访问管理站点和任何未引用依赖项的页面.
I have a (relatively complex) dependency that I wish to inject into Orchard. Currently if I build and run the code it's perfectly happy until it hits my dependency at which point it null-refs (as I'd expect it to). I can access the admin site and any pages that don't reference the dependency.
我在项目中添加了对Autofac的引用. ->很好.
I add a reference to Autofac to my project. -> All fine.
我添加以下类:
using System;
using Autofac;
namespace MyCustom.Module.Namespace
{
public class LoaderModule
{}
}
一切仍然很好-我重建并仍然获得预期的行为.
然后按照其他地方的说明,使LoaderModule
从Autofac.Module
派生:
Everything is still fine - I rebuild and still get the expected behaviour.
Then I make my LoaderModule
derive from Autofac.Module
as instructed elsewhere:
using System;
using Autofac;
namespace MyCustom.Module.Namespace
{
public class LoaderModule : Autofac.Module
{}
}
突然我收到找不到资源".从IIS到整个Orchard网站的404代码-包括没有遇到依赖关系的管理网站和内容页面.
And suddenly I'm getting "The resource cannot be found." 404s from IIS for the entire Orchard site - including admin site and content pages which done't hit the dependency.
帮助!?
推荐答案
B!这是一个版本问题.
Bah! It was a versioning issue.
使用附加的调试器启动站点,并打破所有异常,结果如下:
Starting the site with debugger attached, and breaking on all exceptions revealed things like this:
{"Could not load file or assembly 'Autofac, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"Autofac, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da"}
我从nuget中添加了Autofac,但是Orchard本身使用的捆绑版本有所不同. 删除我对Autofac的nuget引用,然后通过查找Autofac.dll的捆绑副本进行重新添加,使问题消除了.
I'd added Autofac from nuget, but Orchard itself was using a bundled version that was different. Removing my nuget reference to Autofac and re-adding by locating the bundled copy of Autofac.dll made the problem go away.
这篇关于在自定义模块中包含Autofac.Module会破坏Orchard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!