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

  • Home
  • SEARCH
  • 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 8077377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:27:40+00:00 2026-06-05T15:27:40+00:00

So I just implemented a base controller on my MVC3 site in order to

  • 0

So I just implemented a base controller on my MVC3 site in order to have some things execute before every view is loaded. Particularly I wanted something that would act as a kind of master page code behind. Once I rolled this and made all my controllers inherit from my base controller I get this error:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.



[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.Mvc.Controller.PossiblyLoadTempData() +11
System.Web.Mvc.Controller.ExecuteCore() +38
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8970061
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

I read a few places that you need to override CreateTempDataProvider() and return something or other, but I can’t quite figure out the code to do so. I am relatively new with .NET and have yet to override anything before, so I am not sure how to go about this. IF you have run into this before, or know what to do, please help!

Here is my base controller and the attempt at overriding that I have done so far to no avail:

 public class BaseController : Controller
{
    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {

        string document = Path.Combine(HttpRuntime.AppDomainAppPath, "quote.xml");
        string _quote = "";
        string _author = "";
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(document);

        XmlNode Quote = xmlDoc.SelectSingleNode("quote/text");
        XmlNode Author = xmlDoc.SelectSingleNode("quote/author");

        _quote = Quote.InnerText;
        _author = Author.InnerText;

        ViewData["Quote"] = _quote;
    }

    protected override ITempDataProvider CreateTempDataProvider()
    {
        return base.CreateTempDataProvider();
    }
}

And here is the controller that is trying to run when I start debugging (dunno if you need it):

public class BlogController : BaseController
{
    private DarkRobotEntities1 db = new DarkRobotEntities1();

    //
    // GET: /Blog/

    public ViewResult Index()
    {
        var posts = db.Posts.Include(p => p.Blog).Include(p => p.Comments);
        return View(posts.ToList());
    }
...
}
  • 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-06-05T15:27:42+00:00Added an answer on June 5, 2026 at 3:27 pm

    You need to call base.Initialize() at the top of your overridden Initialize() method to initialize the base Controller class.

    Otherwise, the properties used by PossiblyLoadTempData() will never be set.

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

Sidebar

Related Questions

I have just implemented WMD for my editor in an ASP.NET app. The problem
I am developing a Silverlight app using VS2008 Express. I have just implemented a
We're just getting into MVVM in WPF. We have implemented our ViewModels with 'strongly
I was just trying out some code, not a experienced coder. I implemented(at least
I have implemented workflow persistence participant promotion, just as it shown here on Microsoft's
Just a small question about c++/cli. Abstract classes have abstract methods to be implemented
I've just implemented Elmah for logging in my MVC3 app, and of course all
I just implemented a remember me feature for a user login on a website.
I just implemented uploadify in my project, and I noticed what seems like an
We just implemented SVN usage at our office and the other dev and myself

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.