3

This error appear just when I publish on Azure server:
Sequence contains no elements

I'm not sure this error is because of Ninject. I've tried all the tips with similar errors, but it seems that is a generic error.
I tried to run the same code on several machines and this error does not happen only when the public Azure.
If you have gone through something and can help, thank you very much.

Stack Trace:

[InvalidOperationException: Sequence contains no elements] 
   System.Linq.Enumerable.Single(IEnumerable`1 source) +311
   Ninject.Web.Mvc.NinjectMvcHttpApplicationPlugin.Start() +44
   Ninject.Web.Common.Bootstrapper.<Initialize>b__0(INinjectHttpApplicationPlugin c) +8
   Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable`1 series, Action`1 action) +130
   Ninject.Web.Common.Bootstrapper.Initialize(Func`1 createKernelCallback) +140
   Splora.SploraV1.UI.Web.NinjectWebCommon.Start() +102

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +192
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +136
   WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +73
   WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +350
   WebActivatorEx.ActivationManager.Run() +78

[InvalidOperationException: The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +613
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +141
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +159
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +656

[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +4531288
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +94
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +191   



NinjectWebCommon.cs:

private static readonly Bootstrapper bootstrapper = new Bootstrapper();

    /// <summary>
    /// Starts the application
    /// </summary>
    public static void Start() 
    {
        DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
        DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
       bootstrapper.Initialize(CreateKernel);
    }

    /// <summary>
    /// Stops the application.
    /// </summary>
    public static void Stop()
    {
        bootstrapper.ShutDown();
    }

    /// <summary>
    /// Creates the kernel that will manage your application.
    /// </summary>
    /// <returns>The created kernel.</returns>
    private static IKernel CreateKernel()
    {
        var kernel = RegisterServices();
        try
        {
            kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

            return kernel;
        }
        catch
        {
            kernel.Dispose();
            throw;
        }
    }


    private static StandardKernel RegisterServices()
    {
        return new Container().GetModules();
    } 
Marcus Braga
  • 41
  • 1
  • 7
  • but where is your code ? –  Sep 09 '15 at 13:07
  • What's the code performing the `Enumerable.Single` call? What's it performing `Single` on? – BatteryBackupUnit Sep 09 '15 at 13:43
  • I do not know where he's going to throw the error. I can not debug because this cloud. – Marcus Braga Sep 09 '15 at 13:49
  • Yes but at least you can have a look into the source code of `Ninject.Web.Mvc.NinjectMvcHttpApplicationPlugin.Start()` and see where it's calling `Single`! – BatteryBackupUnit Sep 09 '15 at 13:59
  • Questions for debugging help must provide [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve), also see [here](http://stackoverflow.com/help/on-topic) – BatteryBackupUnit Sep 09 '15 at 14:01
  • What *exactly* have you already tried in order to fix the issue? Have you had a look at [these](http://stackoverflow.com/questions/24776799/sequence-contains-no-elements-exception-when-initializing-ninject?rq=1)? – BatteryBackupUnit Sep 09 '15 at 14:02
  • Yes I try it, but it's not the case! I don't know how reproduce the erro becouse I don't know where is the problem. Sorry I'm new here and I don't know well how to ask for help. – Marcus Braga Sep 09 '15 at 14:09
  • did you have a look at [this](https://github.com/ninject/ninject.web.mvc/issues/24)? – BatteryBackupUnit Sep 09 '15 at 15:16
  • Yes man! But I don't have duplicate ninject in my projects. In local machine work fine the problem is when I publish the project on Azure. If whas the problem it's not work on in local machine. – Marcus Braga Sep 09 '15 at 16:55

2 Answers2

1

I found the problem, on Azure when I published I didn't select the option "Remove additional files at destination" on publish screen's Settings tab.

Consequently the publish didn't remove old DLLs that I didn't use anymore. I cleared all files on Azure and published again and it worked.

After that, I selected the option "Remove additional files at destination" when publishing and it didn't happen again.

Marcos Dimitrio
  • 6,651
  • 5
  • 38
  • 62
Marcus Braga
  • 41
  • 1
  • 7
  • Thanks Marcus. That helped me. I (foolishly) tried the continuous integration option from Bitbucket to Azure, and that royally messed things up for me. I got the same error as you when I went back to publishing manually. – oflahero Sep 21 '15 at 14:04
0

In my case this issue was happening in UAT but not on my machine.

The reason for that is I changed namespace and as result in release folder there were two libraries with the same class.

I had to clean up release folder and publish it again. All good now

szadrutsky
  • 493
  • 4
  • 8