Coder Social home page Coder Social logo

Comments (15)

alistairjevans avatar alistairjevans commented on August 29, 2024

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.

cervengoc avatar cervengoc commented on August 29, 2024

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.

cervengoc avatar cervengoc commented on August 29, 2024

FYI I tried removing the OWIN-based two lines

app.UseAutofacMiddleware(container);
app.UseAutofacMvc();

The issue is still the same.

from autofac.mvc.

alistairjevans avatar alistairjevans commented on August 29, 2024

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.

cervengoc avatar cervengoc commented on August 29, 2024

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.

alistairjevans avatar alistairjevans commented on August 29, 2024

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.

cervengoc avatar cervengoc commented on August 29, 2024

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.

alistairjevans avatar alistairjevans commented on August 29, 2024

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.

alistairjevans avatar alistairjevans commented on August 29, 2024

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.

cervengoc avatar cervengoc commented on August 29, 2024

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.

alistairjevans avatar alistairjevans commented on August 29, 2024

Thanks @cervengoc, I appreciate the effort.

from autofac.mvc.

lars-nielsen avatar lars-nielsen commented on August 29, 2024

@cervengoc

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.

cervengoc avatar cervengoc commented on August 29, 2024

@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.

tillig avatar tillig commented on August 29, 2024

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.

dwillbarron avatar dwillbarron commented on August 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.