none
Mobile Service Web API Error - Attempted to access an element as a type incompatible with the array RRS feed

  • Question

  • Hi,

    My mobile service works locally but when I publish to Azure, I get the following error:

    error:Exception=System.InvalidOperationException: Boot strapping failed: executing 'WebApiConfig.Register' caused an exception: 'Attempted to access an element as a type incompatible with the array.'. ---> System.ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array. at System.Collections.Generic.List`1.Add(T item) at Autofac.ContainerBuilder.RegisterCallback(Action`1 configurationCallback) at Autofac.RegistrationExtensions.Register[T](ContainerBuilder builder, Func`3 delegate) at Autofac.RegistrationExtensions.Register[T](ContainerBuilder builder, Func`2 delegate) at CurrencyConverter.Server.WebApiConfig.OnRegisterTypes(ContainerBuilder containerBuilder) at CurrencyConverter.Server.WebApiConfig.<Register>b__0(HttpConfiguration httpConfiguration, ContainerBuilder containerBuilder) at Microsoft.WindowsAzure.Mobile.Service.ConfigBuilder.ConfigureServiceDependencies(HttpConfiguration config, ContainerBuilder containerBuilder) at Microsoft.WindowsAzure.Mobile.Service.ConfigBuilder.ConfigureWebApiDependencyResolver(HttpConfiguration config, IDictionary`2 serviceInstances) at Microsoft.WindowsAzure.Mobile.Service.ConfigBuilder.ConfigureWebApi(HttpConfiguration config, IDictionary`2 serviceInstances) at Microsoft.WindowsAzure.Mobile.Service.Config.WebHostConfigProvider.ConfigureWebApi(IConfigBuilder configBuilder, HttpConfiguration config) at Microsoft.WindowsAzure.Mobile.Service.Config.HostConfigProvider.Initialize(IConfigBuilder configBuilder) at Microsoft.WindowsAzure.Mobile.Service.ServiceConfig.InvokeHostConfigProvider(HostConfigProviderAttribute attribute, IConfigBuilder configBuilder) --- End of inner exception stack trace --- at Microsoft.WindowsAzure.Mobile.Service.Config.WebHostBootstrapper.InvokeStaticBootStrapper(IEnumerable`1 loadedAssemblies) at Microsoft.WindowsAzure.Mobile.Service.Config.WebHostBootstrapper.Initialize(IEnumerable`1 loadedAssemblies) at Microsoft.WindowsAzure.Mobile.Service.Config.WebHostBootstrapper.Boot() at Microsoft.WindowsAzure.Mobile.Service.MvcApplication.Application_Start(), Id=00000000-0000-0000-0000-000000000000, Category='Service.Hosting'


    My projects are all .NET 4.5 and these are my assembly bindings:

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:bcl="urn:schemas-microsoft-com:bcl">
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.ServiceBus" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.3.0.0" newVersion="2.3.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.3.0.0" newVersion="3.3.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>


    Friday, April 11, 2014 6:38 AM

Answers

  • For anyone else who has this problem. Do not update all the Nuget packages. Autofac has to be version 3.0.0. Adding an assembly binding for Autofac seems to have no effect.

    Blacklight

    • Marked as answer by Rehan SaeedMVP Thursday, April 17, 2014 11:04 AM
    Tuesday, April 15, 2014 1:14 PM

All replies

  • I tried downloading the published website via FTP and running it on my machine and it all works. I only get the error when it is running in Azure.

    Any help is much appreciated.


    Blacklight

    Friday, April 11, 2014 11:02 AM
  • The error is thrown when the service is starting up as shown below:

    public static void Register()
    {
        ConfigOptions configOptions = new ConfigOptions();
        ConfigBuilder configBuilder = new ConfigBuilder(
            configOptions,
            (httpConfiguration, containerBuilder) => RegisterTypes(containerBuilder));
    
        HttpConfiguration config = ServiceConfig.Initialize(configBuilder);
    #if DEBUG
        config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
    #endif
        config.Filters.Add(new LoggingFilter(new LogService()));
    }
    
    private static void RegisterTypes(ContainerBuilder containerBuilder)
    {
    
        // THIS CODE ERRORS WHEN RUNNING IN AZURE. IT WORKS LOCALLY.
        containerBuilder.RegisterType<MyService>().As<IMyService>().SingleInstance();
    }
    
    
    Furthermore, I had updated all NuGet packages, so I should have all the latest bits.

    Blacklight

    Tuesday, April 15, 2014 11:57 AM
  • For anyone else who has this problem. Do not update all the Nuget packages. Autofac has to be version 3.0.0. Adding an assembly binding for Autofac seems to have no effect.

    Blacklight

    • Marked as answer by Rehan SaeedMVP Thursday, April 17, 2014 11:04 AM
    Tuesday, April 15, 2014 1:14 PM