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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:34:07+00:00 2026-05-20T12:34:07+00:00

I am adding unit testing to the NerdDinner solution, and ran across this. I

  • 0

I am adding unit testing to the NerdDinner solution, and ran across this. I am testing the Edit POST method, given here:

    [AcceptVerbs(HttpVerbs.Post), Authorize]
    public virtual ActionResult Edit(int id, FormCollection formValues)
    {
        Dinner dinner = dinnerRepository.GetDinner( id );
        if (!dinner.IsHostedBy(User.Identity.Name))
        {
            return View(Views.InvalidOwner);
        }
        try
        {
            UpdateModel(dinner);
            dinnerRepository.Save();

            //return RedirectToAction("Details", new { id = dinner.DinnerID });
            return RedirectToAction(Actions.Details(dinner.DinnerID));
        }
        catch (Exception ex)
        {
            foreach (var issue in dinner.GetRuleViolations())
            {
                ModelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
            }
            return View(new DinnerFormViewModel(dinner));
        }
    }

The System.TypeInitializationException is thrown on the “return RedirectToAction…” line, and says “The type initializer for ‘MVC’ threw an exception.”

When I replace the T4MVC-encoded line with the original line (commented out above), I do not get the exception.

Here is the unit test code:

    [TestMethod]
    public void EditAction_Should_Redirect_When_Update_Successful()
    {
        // Arrange
        var controller = CreateDinnersControllerAs("Some User");
        var formValues = new FormCollection
                             {
                                 { "Title", "Another Value" },
                                 { "Description", "Another Description" }
                             };
        controller.ValueProvider = formValues.ToValueProvider();

        // Act
        var result = controller.Edit(1, formValues) as RedirectToRouteResult;

        // Assert
        Assert.IsNotNull(result);
        Assert.AreEqual("Details", result.RouteValues["Action"]);
    }

I have a couple of ideas what may be causing this exception to be thrown, but I’m not sure enough to posit here. I’m totally unclear as to how to fix it.

Ideas?

Dave

  • 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-20T12:34:08+00:00Added an answer on May 20, 2026 at 12:34 pm

    MVC is a class generated by T4MVC. The error you are seeing simply means that an exception was thrown inside the constructor of this generated MVC class (note that “constructor” in this sense also means initialization of any fields that are assigned a value where declared).

    Open and save the T4MVC.tt file to ensure your code generated file is up to date. If that doesn’t help and you’re using the most recent version available, set a breakpoint in the constructor of the generated MVC class to find out what breaks it.

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

Sidebar

Related Questions

I am Unit Testing one of my functions. Here is my code: public void
Fo unit testing ASP.NET controls I need a stubbed Page. I can create an
Today I started adding unit tests to an ASP.NET MVC project we are developing
Folks, I've a large legacy .Net code base, and I'm trying to introduce Unit
I'm in the process of pushing my company towards having unit tests as a
My ASP.NET MVC 2 controllers are currently instantiating service objects in their constructors by
I am developing an AS3 application which uses a Singleton class to store Metrics
I am creating my first custom Delphi component. Its basically a custom Tpanel with
I am writing a class library to interact with a domain Active Directory. In
I am using NUnit asserts within a MSTest project like as follows ( NOTE:

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.