Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6071421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:02:43+00:00 2026-05-23T10:02:43+00:00

I have an MVC2 app that’s based on the Tekpub Starter Site , so

  • 0

I have an MVC2 app that’s based on the Tekpub Starter Site, so it uses Ninject for dependency injection, NLog for logging, and a bunch of other libraries in various places. As far as I can tell though, it’s these that are causing my problem.

Everything works beautifully on my PC using the ASP.NET dev server (Cassini) but when I deploy to the server (it’s a cheap shared hosting deal), I get a NullReferenceException that seems to be related to Ninject instantiating the logger.

Here’s the relevant bits of my Global.asax.cs

protected override void OnApplicationStarted() {
    Logger.Info("App is starting"); // <-- I think this is what's causing the problem

    RegisterRoutes(RouteTable.Routes);
    //MvcContrib.Routing.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
    RegisterAllControllersIn(Assembly.GetExecutingAssembly());
    SetEngines();
}

protected override IKernel CreateKernel() {
    return Container;
}

internal class SiteModule : NinjectModule {
    public override void Load() {
        Bind<ILogger>().To<NLogLogger>();
        // and a couple of others...
    }
}

protected void Application_End() {
    Logger.Info("App is shutting down");
}

protected void Application_Error() {
    Exception lastException = Server.GetLastError();
    Logger.Fatal(lastException);
}

public ILogger Logger {
    get {
        return Container.Get<ILogger>();
        }
    }
    static IKernel _container;
    public static IKernel Container {
        get {
            if (_container == null) {
                _container = new StandardKernel(new SiteModule());
            }
            return _container;
        }
    }

The nlog.config

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

    <targets>
        <!--Useful for debugging-->
        <target name="console" xsi:type="ColoredConsole"
         layout="${date:format=HH\:mm\:ss}|${level}|${stacktrace}|${message}" />

        <target name="file" xsi:type="File" fileName="${basedir}/App_Data/Site.log"
         layout="${date}: ${message}" />

        <target name="eventlog" xsi:type="EventLog" source="My App" log="Application"
        layout="${date}: ${message} ${stacktrace}" />

    </targets>

    <rules>
        <logger name="*" minlevel="Info" writeTo="file" />
        <!-- <logger name="*" minlevel="Fatal" writeTo="eventlog" /> -->
    </rules>
</nlog>

The NLogLogger class:

public class NLogLogger:ILogger {

    private Logger _logger;

    public NLogLogger() {
        _logger = LogManager.GetCurrentClassLogger();
    }

    public void Info(string message) {
        _logger.Info(message);
    }

    // similar for Warn, Debug, etc

Stack trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   NLog.LogManager.GetCurrentClassLogger() +84
   DynamicInjector8cdfc2eb02f8497596a4704e379a4bb4(Object[] ) +40
   Ninject.Activation.Providers.StandardProvider.Create(IContext context) +319
   Ninject.Activation.Context.Resolve() +182
   Ninject.KernelBase.<Resolve>b__4(IContext context) +8
   System.Linq.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x) +32
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +151
   System.Linq.<CastIterator>d__b1`1.MoveNext() +92
   System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +4187840
   Ninject.ResolutionExtensions.Get(IResolutionRoot root, IParameter[] parameters) +149
   Web.Application.get_Logger() in C:\mvcstarter\Web\Global.asax.cs:159
   Web.Application.OnApplicationStarted() in C:\mvcstarter\Web\Global.asax.cs:80
   Ninject.Web.Mvc.NinjectHttpApplication.Application_Start() +535

[HttpException (0x80004005): Object reference not set to an instance of an object.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9024793
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +131
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253

[HttpException (0x80004005): Object reference not set to an instance of an object.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8946484
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256

If I comment out the logging in OnApplicationStarted, I get a different exception. I’m not sure why it’s happening, because there shouldn’t be any logging happening so I’m not sure why it’s trying to instantiate the logger.

[NullReferenceException: Object reference not set to an instance of an object.]
   NLog.LogManager.GetCurrentClassLogger() +84
   DynamicInjector5ca7d21cf56b4732957e22cb1bfd8bdd(Object[] ) +40
   Ninject.Activation.Providers.StandardProvider.Create(IContext context) +319
   Ninject.Activation.Context.Resolve() +182
   Ninject.KernelBase.<Resolve>b__4(IContext context) +8
   System.Linq.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x) +32
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +151
   System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +4187840
   Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent) +347
   Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) +138
   Ninject.Activation.Providers.<>c__DisplayClass2.<Create>b__1(ITarget target) +17
   System.Linq.WhereSelectArrayIterator`2.MoveNext() +85
   System.Linq.Buffer`1..ctor(IEnumerable`1 source) +325
   System.Linq.Enumerable.ToArray(IEnumerable`1 source) +78
   Ninject.Activation.Providers.StandardProvider.Create(IContext context) +306
   Ninject.Activation.Context.Resolve() +182
   Ninject.KernelBase.<Resolve>b__4(IContext context) +8
   System.Linq.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x) +32
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +151
   System.Linq.<CastIterator>d__b1`1.MoveNext() +92
   System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +4187840
   Ninject.ResolutionExtensions.TryGet(IResolutionRoot root, String name, IParameter[] parameters) +261
   Ninject.Web.Mvc.NinjectControllerFactory.CreateController(RequestContext requestContext, String controllerName) +108
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +124
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
   System.Web.Mvc.<>c__DisplayClass7.<BeginProcessRequest>b__6() +29
   System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +38
   System.Web.Mvc.ServerExecuteHttpHandlerAsyncWrapper.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +97
   System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1508
   System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +77
   System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +28
   System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +22
   System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +372
   System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, String controllerName) +35
   ASP.views_home_index_aspx.__RenderContent2(HtmlTextWriter __w, Control parameterContainer) in c:\HostingSpaces\<snip>\wwwroot\Views\Home\Index.aspx:8
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\HostingSpaces\<snip>\wwwroot\Views\Shared\Site.Master:48
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +55
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3060

The only way I can get the site to work at all is to fake out the logger entirely, which I’m not at all happy with. This is my first time playing with ASP.NET shared hosting, so I’m a bit at a loss. Anyone have any helpful suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:02:43+00:00Added an answer on May 23, 2026 at 10:02 am

    You could avoid using LogManager.GetCurrentClassLogger() and let Ninject resolve the current class name for you:

    Change the constructor of your NLogLogger class into this:

    public NLogLogger(string currentClassName) 
    {
      _logger = LogManager.GetLogger(currentClassName);
    }
    

    And change the ninject binding to resolve the current classname:

    Bind<ILogger>().To<NLogLogger>()
      .WithConstructorArgument("currentClassName", x => x.Request.ParentContext.Request.Service.FullName);
    

    Additional benefit: your log file now also includes the class name from where the log directive was issued.

    I know my answer is a little bit late to the party, but I was struggling with this myself today and couldn’t find the answer anywhere. Maybe this helps someone else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple MVC2 app that doesn't seem to Redirect correctly. The code
I have a situation with my MVC2 app where I have multiple pages that
I have an ASP.NET MVC 2 app that uses URLS such as: /rsvp/33c4cf68-a2fe-4c0f-9834-08838e0532c3 /rsvp/4f28dad7-b05c-4887-818f-b4ae664b7192
My MVC2 app uses a component that makes subsequent AJAX calls back to the
In my MVC2 app that uses the Service - Repository pattern, how can I
I have an MVC2 app that utilizes MySql.Web ver. 6.2.2.0, on my dev machine
I have a MVC2 web app without a database that is being hosted by
I have an MVC2 app where I am starting to use the STE 's.
I have an MVC2 app I developed with the VS2010 RC and the .NET
I have user control in my MVC2 app placed in the Content folder (it's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.