Question

I am trying to user Autofac in my Web Form application, using vb.net, I was following the examples in the Autofac site, but I am getting this error:

An exception of type 'System.MissingMemberException' occurred in Microsoft.VisualBasic.dll but was not handled in user code. Additional information: Public member 'RegisterType' on type 'ContainerBuilder' not found.

this is what I have defined in my Global.asax.vb:

Shared _containerProvider As IContainerProvider

Public ReadOnly Property ContainerProvider() As IContainerProvider Implements IContainerProviderAccessor.ContainerProvider
        Get
            Return _containerProvider
        End Get
    End Property

....

' Build up your application container and register your dependencies.
Dim builder = New ContainerBuilder()
builder.RegisterType(Of CustomerService)().As(Of ICustomerService)()
builder.RegisterType(Of CustomerContactService)().As(Of ICustomerContactService)()
builder.RegisterType(Of UnitOfWork)().As(Of IUnitOfWork)()


' Once you're done registering things, set the container
' provider up with your registrations.
_containerProvider = New ContainerProvider(builder.Build())

this is what I have in my web.config:

<system.webServer>
    <modules>
      <add name="ContainerDisposal" type="Autofac.Integration.Web.ContainerDisposalModule, Autofac.Integration.Web" preCondition="managedHandler"/>
      <add name="PropertyInjection" type="Autofac.Integration.Web.Forms.PropertyInjectionModule, Autofac.Integration.Web" preCondition="managedHandler"/>
      <add name="AttributedInjection" type="Autofac.Integration.Web.Forms.AttributedInjectionModule, Autofac.Integration.Web" preCondition="managedHandler"/>
    </modules>
</system.webServer>

and

<httpModules>
  <!-- This section is used for IIS6 -->
  <add name="ContainerDisposal" type="Autofac.Integration.Web.ContainerDisposalModule, Autofac.Integration.Web"/>
  <add name="PropertyInjection" type="Autofac.Integration.Web.Forms.PropertyInjectionModule, Autofac.Integration.Web"/>
  <add name="AttributeInjection" type="Autofac.Integration.Web.Forms.AttributedInjectionModule, Autofac.Integration.Web"/>
</httpModules>

I added all the references via nuget Autofac.Web

What am I doing wrong?

Was it helpful?

Solution

Try changing Dim builder = New ContainerBuilder() to Dim builder As ContainerBuilder = New ContainerBuilder().

The compiler does not recognize that your are calling an extension method without a strong type.

Extension methods are not considered in late binding.

MSDN: Extension Methods (Visual Basic)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top