0
votes

I am getting error like 'Method not found: 'Void Autofac.RegistrationExtensions.RegisterModule(Autofac.ContainerBuilder, Autofac.Core.IModule)' when I updated the latest version of Asp.net MVC Application.

My application are using

  1. Autofac.Mvc5
  2. Autofac.WebAPI
  3. WebAPI2.2 Help Page and other dlls are as well.

After installed Webapi2.2 help-page,I got security issue in Autofac so as per suggestions by google I have updated the latest version of Autofac.

After updating the AutoFac MVC5 and WebAPI versions, I got above error while trying to use RegisterModule more than one times. Please find my code as below

var builder = new ContainerBuilder();

builder.RegisterModule(new xyz());

builder.RegisterModule(new abc());

builder.Build();

My config file are as below

<?xml version="1.0" encoding="utf-8"?>
<packages xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <package id="Antlr" version="3.5.0.2" targetFramework="net45" xmlns="" />
  <package id="Autofac" version="4.0.0-beta6-110" targetFramework="net45" xmlns="" />
  <package id="Autofac.Mvc5" version="3.3.4" targetFramework="net45" xmlns="" />
  <package id="Autofac.WebApi" version="3.1.0" targetFramework="net45" xmlns="" />
  <package id="Autofac.WebApi2" version="3.4.0" targetFramework="net45" xmlns="" />
  <package id="Codaxy.CodeReports" version="0.1.6.4" targetFramework="net45" xmlns="" />
  <package id="Codaxy.CodeReports.Exporters.Html" version="0.1.3" targetFramework="net45" xmlns="" />
  <package id="Codaxy.CodeReports.Exporters.Xlio" version="0.1.5.1" targetFramework="net45" xmlns="" />
  <package id="Codaxy.Common" version="0.5.16.9" targetFramework="net45" xmlns="" />
  <package id="Codaxy.Common.Localization" version="0.5.9.2" targetFramework="net45" xmlns="" />
  <package id="Codaxy.Common.SqlServer" version="0.6.0.2" targetFramework="net45" xmlns="" />
  <package id="Codaxy.Dextop" version="1.2.0.25" targetFramework="net45" xmlns="" />
  <package id="Codaxy.Dextop.Core" version="1.2.0.40" targetFramework="net45" xmlns="" />
  <package id="Codaxy.Dextop.Preprocessor" version="1.1.0.5" targetFramework="net45" xmlns="" />
  <package id="Codaxy.Xlio" version="0.9.3.21" targetFramework="net45" xmlns="" />
  <package id="EntityFramework" version="6.1.3" targetFramework="net45" xmlns="" />
  <package id="Glimpse" version="1.8.6" targetFramework="net45" xmlns="" />
  <package id="Glimpse.Ado" version="1.7.3" targetFramework="net45" xmlns="" />
  <package id="Glimpse.AspNet" version="1.9.1" targetFramework="net45" xmlns="" />
  <package id="Glimpse.EF6" version="1.6.5" targetFramework="net45" xmlns="" />
  <package id="Glimpse.Mvc4" version="1.5.3" targetFramework="net45" xmlns="" />
  <package id="HtmlTags" version="2.0.0.181" targetFramework="net45" xmlns="" />
  <package id="Humanizer" version="1.25.4" targetFramework="net45" xmlns="" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" xmlns="" />
  <package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" xmlns="" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" xmlns="" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" xmlns="" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" xmlns="" />
  <package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.3" targetFramework="net45" xmlns="" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net45" xmlns="" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" xmlns="" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" xmlns="" />
  <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" xmlns="" />
  <package id="SharpZipLib" version="0.86.0" targetFramework="net45" xmlns="" />
  <package id="WebGrease" version="1.6.0" targetFramework="net45" xmlns="" />
</packages>

I tried multiple solution to resolve but not got a success. Could you please pass me the correct solution to resolve?

Thanks

1
The signature of RegisterModule changed. Go look for how to register modules in the latest version of autofac - user1228
Hi Will,Thanks for response. Actually RegisterModule is working fine if I registerd with only one module like var builder = new ContainerBuilder(); builder.RegisterModule(new xyz()); builder.Build(); I am gettting error while trying to add more than one module. - Rahul.R.Parmar
Can you show your packages.config so we can see the versions of things you have installed? Also, do any of your modules register other modules internally? - Travis Illig
Nope, that's not correct at all. Method not found: 'Void Autofac.RegistrationExtensions.RegisterModule(Autofac.ContainerBuilder, Autofac.Core.IModule) means the method is not found. You don't just lose a method between calls. You can't call it once, then have it fail the next time. The binder is locating what it thinks is the correct assembly, loading it into the appdomain, and when trying to find that method signature it is failing. What you believe or are assuming is happening is not. Stop Go look at the methods on the type. Use a disassembler if necessary. - user1228
Hi Travis, Please find packages.config file as below, let me know if you need more info <packages xmlns="schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <package id="Antlr" version="3.5.0.2" targetFramework="net45" xmlns="" /> <package id="Autofac" version="3.5.2" targetFramework="net45" xmlns="" /> <package id="Autofac.Mvc5" version="3.3.4" targetFramework="net45" xmlns="" /> <package id="Autofac.WebApi" version="3.1.0" targetFramework="net45" xmlns="" /> <package id="Autofac.WebApi2" version="3.4.0" targetFramework="net45" xmlns="" /> - Rahul.R.Parmar

1 Answers

2
votes

Remove the reference to Autofac.WebApi. You only need Autofac.WebApi2. We haven't supported Autofac.WebApi for quite some time and it's only for the 3.x and before versions of Web API. Autofac.WebApi wasn't updated when the signature on RegisterModule changed.

I'm guessing that everything goes swimmingly until you try to register something in a module that uses the old version of Autofac.WebApi.