New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register mvc controllers with autofac 4 beta fails #10
Comments
Are you using the right version of Autofac MVC integration? If you're using the latest standard ASP.NET MVC (not the new ASP.NET Core stuff) you should be referencing Autofac.Mvc5 as noted in the docs.We usually see this if someone is using ASP.NET MVC 5 but trying to reference an older version of Autofac MVC integration, like Autofac.Mvc3. We also sometimes find folks accidentally including multiple versions of Autofac MVC integration in their project - you should only have the one version. |
I'm using Autofac.Mvc5 integration 3.3.4 and Autofac.Mvc5.Owin integration 3.1.0 |
You will probably have to post a reproduction. We do have several users of the MVC integration who don't see this. For example, issue #459 had almost the same question and it turned out to be some version mismatch problems. Same thing on the Web API side: issue #3 on the Web API integration also has the same error and the same cause - version mismatch problems. Can you post your packages.config? That may help shed light here. |
Also, if your application has any assembly-level security attributes, can you post those? |
I really need to see the packages.config file with the list of NuGet packages. Thanks! |
It appears you have a lot of interesting combinations of things that may cause challenges.
What I'm guessing right now is that it's the Autofac 4 with the older integration that hasn't been updated yet to work with Autofac 4. What I'd try: upgrade everything in your project as far as it can go (on released/stable versions, not beta). See if you still have the issue. If you do... well, you'll have to wait until RC2 is out so we can start looking at getting Autofac core more stable and worth updating the classic integration for. Let me know how it goes. |
(Sorry I missed the thing about you using the new xml/JSON config in the first post. It didn't click until just now.) |
Thanks for the suggestions, will have a go at that. I'll post here if I have any success (or not) |
Hello again, Looking back at my post I've now realise that I've posted the wrong package.config info so I'll add the correct one here. It's a shame but I think I'll have to give on having xml/json configuration (I really liked it!) or alternatively not implementing mvc controller injection for now. Is there another way to read configuration in Autofac 3.5.2? e.g. from app/web.config |
Yeah, unfortunately you may be stuck until we can get the .NET Core stuff ironed out a bit more in the Autofac main library and then pushed through to some of these other integrations. However, if you stick to the non-beta version of Autofac.Configuration, you can still use XML configuration. Look further down the documentation page at the legacy configuration section to see how that works. It's not as pretty as JSON but it gets the job done. I'll leave this open so we can track it against the .NET Core releases and make sure things are working together. |
I pushed Autofac.Mvc5 4.0.0-rc3-219 with compatibility for Autofac 4. Note there are some breaking changes in Autofac 4 that require a minimum of Autofac 4 now, so if you have other third-party assemblies that use Autofac requirements, you may have challenges with NuGet allowing you to upgrade. |
Hi,
I'm currently working on an application that use autofac xml/json integration in its latest form. However If I try and inject into MVC Controllers (using the latest Autofac.Integration.Mvc and the normal registration process for Mvc controllers as defined in the documentation) it doesn't work. Actually, it throws this exception:
Attempt by security transparent method 'Autofac.Integration.Mvc.RequestLifetimeScopeProvider..ctor(Autofac.ILifetimeScope)' to access security critical type 'Autofac.ILifetimeScope' failed.
Assembly 'Autofac.Integration.Mvc, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.
I also use api controllers injection and that works fine.
Is it occurring because of versioning issues? Or perhaps there might be another issue?
I'm currently using VS2013 .NET 4.5. It worth to mention that the mvc controllers are located in a different assembly than the one i'm using to configure autofac. Furthermore, each assembly has it's own autofac's module to register specific component such as controllers.
The text was updated successfully, but these errors were encountered: