Comments (15)
Is your entire project going through OWIN, or are you running OWIN on top of the normal ASP.NET stack just for SignalR?
I ask because you appear to have the normal Autofac MVC registration, as well as the OWIN registration.
from autofac.mvc.
I'm using Owin only for SignalR. As far as I know the classic MVC5 cannot work on top of Owin, and requires the classic System.Web
hosting environment and IIS.
I know this is not a fortunate setup, however I could not find a better way back then.
from autofac.mvc.
FYI I tried removing the OWIN-based two lines
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
The issue is still the same.
from autofac.mvc.
Does the error still happen if you comment out the view page property injection?
// OPTIONAL: Enable property injection in view pages.
builder.RegisterSource(new ViewRegistrationSource());
from autofac.mvc.
Yes, that was the point. After commenting it out, everything seems to work fine at first glance. And also, it seems like those two lines in my previous comment are really not needed in this setup.
from autofac.mvc.
I suspect you may still need the app.UseAutofacMiddleware
to allow SignalR hubs to be loaded from your container (or at least, I have it in my app that does the same thing as yours).
You shouldn't need the app.UseAutofacMvc
though, because you aren't serving MVC content over OWIN.
I still feel that there's something up here, adding the ViewRegistrationSource shouldn't cause everything to break like that.
Do your Views derive from a custom type, or directly from WebViewPage
?
from autofac.mvc.
I don't have anything special as far as I can tell. This is my Views\Web.config
.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="ZbOriflame.Web" />
<add namespace="Vertesz.Web"/>
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler" />
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler" />
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
from autofac.mvc.
Ok, thanks; I wonder if there may actually be a defect with the ViewRegistrationSource, in that it doesn't support AjaxHelper
properly.
Do you have a recreating project you can upload?
from autofac.mvc.
Just to update; I've had a go at re-creating this issue myself, but I can't get the error you're seeing when you have the ViewRegistrationSource in place.
If you are able to provide a sample project that would be great, because I still feel like there's something going on here; until then though I'm going to park this.
from autofac.mvc.
Sorry for the delay. Unfortunately I don't have too much time for creating a repro project. However, I can try to reduce this project and remove all private information to reproduce the issue. Give me a few days to prepare it.
from autofac.mvc.
Thanks @cervengoc, I appreciate the effort.
from autofac.mvc.
Do you by any chance use builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource())
I just ran into the same problem you described when migrating from Unity to Autofac and enabling AnyConcreteTypeNotAlreadyRegisteredSource
from autofac.mvc.
@lars-nielsen Yes indeed I do use this special source. Unfortunately I still don't have the time to prepare a repro project, so I hope this additional information can help investigating the issue.
from autofac.mvc.
It's been a little over two years and we don't have a repro here. Given the limited time of the owners team to address core Autofac and all the integration libraries, without a repro we won't be able to pursue this. I'm going to close the issue and if a repro becomes available we can investigate.
from autofac.mvc.
Hi all!
I'm two years late to the party, but I wanted to chime in since I also had this issue and found an appropriate workaround for it. Like some of the others here, I was migrating an MVC project from Unity to Autofac, and needed to use AnyConcreteTypeNotAlreadyRegisteredSource
due to the amount of code that depends on this behavior. I ran into the same exception as mentioned in the original issue.
While I don't fully understand the mechanisms involved here, it looks like the cause is that MVC is, for some reason, trying to use Autofac to resolve dependencies in some internal framework code. The workaround here is to provide a predicate that prevents Autofac from trying to resolve these objects:
_builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource(type => !type.IsInNamespace("System")));
// Alternatively, you can check to see if types *do* belong to your project's namespace--for us, this wasn't an option due to legacy spaghetti.
from autofac.mvc.
Related Issues (20)
- how can i implement autofac on mvc 5.2 and 4.5.2 framework ? HOT 1
- Get a can not load assembly "System.Web.Mvc, Version=5.1.0.0" error when i put project in a directory name contain "#" HOT 8
- Add .NET Framework 4.5 support to packaging HOT 9
- Update to support .NET 4.5
- How do you register a custom action invoker? HOT 7
- Different resolving from constructor injection and DependencyResolver.Current.GetService HOT 2
- The presence of concurrency issues HOT 2
- RequestLifetimeScopeProvider.EndLifetimeScope throws NullReferenceException when both OWIN middleware and MVC integration HOT 5
- Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0 HOT 3
- Project still under active development? HOT 3
- Update AutofacFilterProvider.GetFilters() to skip evaluation if the controller instance is null HOT 4
- Using AutofacServiceLocator on type with InstancePerRequest() causes error HOT 1
- System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection HOT 2
- Integration not compatible with Autofac 5.0 Release Candidate HOT 6
- can name injection be supported HOT 1
- Registering one filter type for multiple controllers doesn't work in one statement HOT 1
- Compatibility with Autofac v6 HOT 3
- Appveyor not pushing packages HOT 1
- Upgrade Microsoft.AspNet.Mvc version from 5.10 to a greater version HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autofac.mvc.