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 3667670
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:01:48+00:00 2026-05-19T02:01:48+00:00

I have a sample ASP.NET MVC 3 web application that is following Jonathan McCracken’s

  • 0

I have a sample ASP.NET MVC 3 web application that is following Jonathan McCracken’s Test-Drive Asp.NET MVC (great book , by the way) and I have stumbled upon a problem. Note that I’m using MVCContrib, Rhino and NUnit.

    [Test]
    public void ShouldSetLoggedInUserToViewBag() {
        var todoController = new TodoController();
        var builder = new TestControllerBuilder();
        builder.InitializeController(todoController);

        builder.HttpContext.User = new GenericPrincipal(new GenericIdentity("John Doe"), null);

        Assert.That(todoController.Index().AssertViewRendered().ViewData["UserName"], Is.EqualTo("John Doe"));
    }

The code above always throws this error:

System.AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

The controller action code is the following:

[HttpGet]
    public ActionResult Index() {
        ViewData.Model = Todo.ThingsToBeDone;
        ViewBag.UserName = HttpContext.User.Identity.Name;

        return View();
    }

From what I have figured out, the app seems to crash because of the two assignements in the controller action. However, I cannot see how there are wrong!?

Can anyone help me pinpoint the solution to this problem.

Thank you.

Edit 1

I’ve done some experiments to see what the problem is.
When removing the ViewData,Model assignment the problem transcends in Expected result to be of type ViewResult. It is actually of type ViewResult.. The ViewData assignment is so basic that I do not think that it is the problem so I think there is something wrong with either Rhino or MVCcontrib in conjunction with MVC 3.

I also have the following test written earlier for the same controller action:

        [Test]
    public void ShouldDisplayAListOfTodoItems() {
        Assert.That(((ViewResult)new TodoController().Index()).ViewData.Model, Is.EqualTo(Todo.ThingsToBeDone));
    }

This one fails now with System.NullReferenceException : Object reference not set to an instance of an object probably becuase there’s no HttpContext set up for this particular test. When removing the ViewBag assignment, everything is ok.

Hope that makes the problem more clear.

Edit 2

When debugging the code after removing the ViewData.Model assignment, it throws a different error: System.NullReferenceException : Object reference not set to an instance of an object. on the ViewBag assignment.

  • 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-19T02:01:48+00:00Added an answer on May 19, 2026 at 2:01 am

    Well, I’ve knocked this one down. As I have suspected, it was because of MVCContrib. Mind that I am using MVC 3 Beta which is not yet officially supported by MVCContrib. With that in mind, I have downloaded the latest MVCContrib sources for MVC 3 branch.

    Go to MVCContrib Sources, switch to the mvc3 branch, download, and build the binaries with the attached bat. Then, include the needed files into your solution.

    Well, this will probably get fixed in a future stable release, but I guess it might be useful to others. Thank you Darin for your interest.

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

Sidebar

Related Questions

I have a simple ASP.NET MVC web application that uses NHibernate with FluentNHibernate's auto
I have created a sample project using ASP.NET MVC 3 Web Application (Razor) template.
I have a really simple ASP.NET web application and a web setup project that
I am building a multi-layered application that has an ASP.NET MVC web application. It
Let's say I have a simple ASP.NET MVC blog application and I want to
Hi I am developing a simple application based upon ASP.NET MVC. I have altered
I have a ASP.NET MVC 2.0 application using Entity Framework. All my views use
I am writing a Asp.net MVC 2 application that uses Forms Authentication and currently
I'm working on a sample project built from the ASP.NET Web Application template (web
I have a problem with a sample routing with the preview 5 of asp.net

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.