Including Autofac.Module in custom module breaks Orchard

空扰寡人 提交于 2019-12-08 03:52:40

问题


See here & here for why I'm trying to do this.

I have a custom module that I'm building (and which is it's own .csproj in the Orchard .sln, as normal)

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.

I add a reference to Autofac to my project. -> All fine.

I add the following class:

using System;
using Autofac;

namespace MyCustom.Module.Namespace
{
  public class LoaderModule
  {}
}

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
  {}
}

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.

Help!?


回答1:


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"}

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.



来源:https://stackoverflow.com/questions/28700524/including-autofac-module-in-custom-module-breaks-orchard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!