locked
Parser Error. RRS feed

  • Question

  • User1421620300 posted

    Is their any single idea as to why i am receiving the following error? Markus

    public partial class Employee
    {
    public int EmployeeId { get; set; }
    public string Name { get; set; }
    public Nullable<int> DepartmentId { get; set; }
    public string Address { get; set; }
    public virtual Department Department { get; set; }     //Error in bold.
    }
    }

    Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'Department' could not be found (are you missing a using directive or an assembly reference?) MVCTutorial C:\Users\Andrew\Documents\Visual Studio 2015\Projects_Interview\MVCTutorial\MVCTutorial\Models\Employee.cs 22 Active

    Server Error in '/' Application.


    Parser Error

    Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

    Parser Error Message: Could not load type 'MVCTutorial.MvcApplication'.

    Source Error: 

    Line 1:  <%@ Application Codebehind="Global.asax.cs" Inherits="MVCTutorial.MvcApplication" Language="C#" %>
    


    Source File: /global.asax    Line: 1 


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3160.0

    Tuesday, December 4, 2018 11:52 PM

Answers

  • User-552477072 posted

    Hi Markus33,

    Actually, this kind of error happens if you mismatch between namespace and class name in Global.asax.cs.

    So, what you can do; just right click on Global.asax and then choose 'View Markup' to see it.

    Pls don't forget to mark as answer when it helps you. Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 5, 2018 7:13 AM
  • User-552477072 posted

    Hi Markus,

     just renamed the Global.asax or delete it as I stated in my last post that there is mismatch between namespace and class name in Global.asax.cs.  

    Some more you can do

    1. Right click (on the project within the solution that is failing)
    2. Unload Project
    3. Reload Project
    4. Build Project
    5. Re-build Solution

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 6, 2018 6:14 AM
  • User-552477072 posted

    Other known related issue for this error are:

    Global.asax.cs: must inherit from HttpApplication -> public class MvcApplication : HttpApplication

    or, Project output must be the bin folder and not Bin/Debug, etc. 

    or, IIS application pool is not in the correct .net version.

    Please don't forget to mark as answer when it helps you. Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 6, 2018 6:17 AM
  • User1520731567 posted

    Hi Markus33,

    public virtual Department Department { get; set; }     //Error in bold.

    Do you lack Department class?

    According to your description,It’s really hard to find out where the problem is.

    If you could,please post your project on oneDrive,so that I can get more details.

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 7, 2018 8:56 AM
  • User1520731567 posted

    Hi Markus33,

    Sorry for the late.

    I find your project report error message:'Error CS0246 The type or namespace name 'Department' could not be found (are you missing a using directive or an assembly reference?) MVCTutorial '.

    And I can't find your Department class.

    So ,I suggest you could add this,like:

    public partial class Employee
        {
            public int EmployeeId { get; set; }
            public string Name { get; set; }
            public Nullable<int> DepartmentId { get; set; }
            public string Address { get; set; }
            public virtual Department Department { get; set; }
    
    
        }
    
        public class Department
        {
            public int DepartmentId { get; set; }
            public string DepartmentName { get; set; }
    
        }

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 10, 2018 2:21 AM

All replies

  • User475983607 posted

    The first error is generally due to a missing "using" statement but it can also be due to a missing Department class.  There's not way to determine from the posted code.

    The second error is usually due to an incorrect Inherits or code behind page directive.  Like the previous error there is not way we provide assistance because there is not enough information. 

    What is a bit strange is most all of your posted errors are reference errors. I assume you are doing something out of the ordinary with project references or general design.

    Wednesday, December 5, 2018 12:02 AM
  • User-552477072 posted

    Hi Markus33,

    Actually, this kind of error happens if you mismatch between namespace and class name in Global.asax.cs.

    So, what you can do; just right click on Global.asax and then choose 'View Markup' to see it.

    Pls don't forget to mark as answer when it helps you. Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 5, 2018 7:13 AM
  • User1421620300 posted

    Mgebhard, here is additional code to see if indication of problems in solution! Markus,

    EmployeeModel:

    //------------------------------------------------------------------------------

    namespace MVCTutorial.Models
    {
    using System;
    using System.Collections.Generic;
    using MVCTutorial.Models;

    public partial class Employee
    {
    public int EmployeeId { get; set; }
    public string Name { get; set; }
    public Nullable<int> DepartmentId { get; set; }
    public string Address { get; set; }
    public virtual Department Department { get; set; }
    }
    }

    TestController:

    using MVCTutorial.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;

    namespace MVCTutorial.Controllers
    {
    public class TestController : Controller
    {
    // GET: Test
    public ActionResult Index()
    {
    MVCTutorialEntities db = new MVCTutorialEntities();

    List<Employee> employeelist = db.Employees.ToList();

    EmployeeViewModel employeeVM = new EmployeeViewModel();


    List<EmployeeViewModel> employeeVMList = employeelist.Select(x=> new EmployeeViewModel
    { Name=x.Name,
    EmployeeId = x.EmployeeId,
    Address = x.Address,
    DepartmentId = x.DepartmentId,
    DepartmentName = x.Department.DepartmentName }).ToList();

    return View(employeeVMList);
    }
    }
    }

    GLOBAL.asax

    <%@ Application Codebehind="Global.asax.cs" Inherits="MVCTutorial.MvcApplication" Language="C#" %>

    Wednesday, December 5, 2018 3:59 PM
  • User-552477072 posted

    Hi Markus,

     just renamed the Global.asax or delete it as I stated in my last post that there is mismatch between namespace and class name in Global.asax.cs.  

    Some more you can do

    1. Right click (on the project within the solution that is failing)
    2. Unload Project
    3. Reload Project
    4. Build Project
    5. Re-build Solution

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 6, 2018 6:14 AM
  • User-552477072 posted

    Other known related issue for this error are:

    Global.asax.cs: must inherit from HttpApplication -> public class MvcApplication : HttpApplication

    or, Project output must be the bin folder and not Bin/Debug, etc. 

    or, IIS application pool is not in the correct .net version.

    Please don't forget to mark as answer when it helps you. Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 6, 2018 6:17 AM
  • User1520731567 posted

    Hi Markus33,

    public virtual Department Department { get; set; }     //Error in bold.

    Do you lack Department class?

    According to your description,It’s really hard to find out where the problem is.

    If you could,please post your project on oneDrive,so that I can get more details.

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 7, 2018 8:56 AM
  • User1421620300 posted

    Yuki, How are you! here is the solution file on one drive. Thanks for the help." Markus

    https://1drv.ms/f/s!AgHKwOmKiJjLkXartPTkJeohNrMJ

    Saturday, December 8, 2018 1:04 AM
  • User1520731567 posted

    Hi Markus33,

    Sorry for the late.

    I find your project report error message:'Error CS0246 The type or namespace name 'Department' could not be found (are you missing a using directive or an assembly reference?) MVCTutorial '.

    And I can't find your Department class.

    So ,I suggest you could add this,like:

    public partial class Employee
        {
            public int EmployeeId { get; set; }
            public string Name { get; set; }
            public Nullable<int> DepartmentId { get; set; }
            public string Address { get; set; }
            public virtual Department Department { get; set; }
    
    
        }
    
        public class Department
        {
            public int DepartmentId { get; set; }
            public string DepartmentName { get; set; }
    
        }

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 10, 2018 2:21 AM
  • User1421620300 posted

    Yuki, how are you. I will try your instruction to see if i can fix issue. Thanks. Markus

    Monday, December 10, 2018 3:21 PM