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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:23:26+00:00 2026-06-12T05:23:26+00:00

Here is my MVC Controller and everything is fine: private UnitOfWork UOW; public InventoryController()

  • 0

Here is my MVC Controller and everything is fine:

    private UnitOfWork UOW;
    public InventoryController()
    {
        UOW = new UnitOfWork();
    }

    // GET: /Inventory/
    public ActionResult Index()
    {
        var products = UOW.ProductRepository.GetAll().ToList();
        return View(products);
    }

Same method call in API Controller gives me an Http 500 Error:

    private UnitOfWork _unitOfWork;
    public TestController()
    {
        _unitOfWork = new UnitOfWork();
    }

    public IEnumerable<Product> Get()
    {
        var products = _unitOfWork.ProductRepository.GetAll().ToList();
        return products;
    }

Debugging shows that indeed there is data being returned in both controllers’ UOW calls. I then added a customer configuration in Global:

    public static void CustomizeConfig(HttpConfiguration config)
    {
        config.Formatters.Remove(config.Formatters.XmlFormatter);
        var json = config.Formatters.JsonFormatter;
        json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
    }

I am still receiving an Http 500 in API Controller ONLY and at a loss as to why. Any ideas?

UPDATE:

It appears using lazy loading caused the problem. When I set the associated properties to NON-VIRTUAL the Test API provided the necessary JSON string. However, whereas before I had the Vendor class included, I only have VendorId. I really wanted to included the associated classes. Any ideas? I know there are alot of smart people out there. Anyone?

  • 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-12T05:23:28+00:00Added an answer on June 12, 2026 at 5:23 am

    Problem Solved:

    The issue was not Lazy Loading after all. The issue was that while I correctly had an association of Vendor in product, I also had a collection of products in Vendor, presumably causing something circular:

    public class Product 
    {
        public int Id { get; set; }
        public string Name { get; set; }
    
        public int VendorId { get; set; }
        public virtual Vendor Vendor { get; set; }
    }
    
    public class Vendor 
    {
        public int Id { get; set; }
        //public Vendor()
        //{
        //    Products = new List<Product>();
        //}
    
        public string CompanyName { get; set; }
      //  public ICollection<Product> Products { get; set; }
    }
    

    Omitting the collection in Vendors and reinstating the virtual in Products did the trick.

                        "vendor": {
                            "id": 4,
                            "companyName": "Vendor 3"
                        },
                        "id": 1,
                        "name": "Product 1",
                        "vendorId": 4
                    },
                    {
                        "vendor": {
                            "id": 2,
                            "companyName": "Vendor 4"
                        },
                        "id": 2,
                        "name": "Product 2",
                        "vendorId": 2
                    },
                    {
                        "vendor": {
                            "id": 3,
                            "companyName": "Vendor 2"
                        },
                        "id": 3,
                        "name": "Product 3",
                        "vendorId": 3
                    },
                    {
                        "vendor": {
                            "id": 1,
                            "companyName": "Vendor 1"
                        },
                        "id": 4,
                        "name": "Product 4",
                        "vendorId": 1
                    }]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to moq and I was trying to test a controller (MVC)
I have the following action inside my Controller public ActionResult DownloadExcel() { //create and
I am having a similar as the user here: ASP.NET MVC 3.0 WebGrid -
Here is my problem in codeigniter MVC. Suppose I have 3 models: (users, email
Here is the subsonic asp.net mvc application http://subsonicproject.com/docs/MVC_Starter_Template but its for MVC 1.0. How
Here's an excerpt from a book I'm reading about application design with MVC: Ideally,
I just found the MVC was initially proposed in 88 [ here is the
Here's what I'm trying to do. I have an ASP.NET MVC web application, where
I'm using ASP.NET MVC 2 and here's the issue. My View Model looks something
I already check some of asp.net mvc hosting sites listed here: https://stackoverflow.com/questions/637567/affordable-stable-asp-net-mvc-hosting-exist I worry

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.