none
null reference in my code RRS feed

  • Question

  •  public class MYDB : Controller
        {

            private string MyString;

            public string MyProperty
            {
                get { return UserDataBaseInitalize(); }
            }


            public string UserDataBaseInitalize()
            {
                SchoolModels SH = new SchoolModels();

                if (Session["IndependentSchool"] != null)
                {
                    SH = (SchoolModels)Session["IndependentSchool"];
                  
                }
                else
                {
                    Response.Redirect("Welcome/Index");
                }

                return  SH.SchoolDataBase;
            }
        }


    when i call  got the null reference user code

            public AccountController(string db)
                : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext(new MYDB().MyProperty))))
            {

            }

                  
    • Edited by maha6242 Monday, September 17, 2018 5:57 PM
    • Moved by May Luo-MSFT Tuesday, September 25, 2018 6:16 AM MVC issue
    Monday, September 17, 2018 5:53 PM

All replies

  • looks like you did not instantiate the SH.SchoolDataBase in return

    provide more details to understand and answer better.

    Monday, September 17, 2018 5:59 PM
  • SH.SchoolDataBase return string but not my queston 

    my question is  why null reference

      public AccountController(string db)
                : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext(new MYDB().MyProperty))))
            {
            }

     public class MYDB : Controller
        {

            private string MyString;

            public string MyProperty
            {
                get { return UserDataBaseInitalize(); }
            }


            public string UserDataBaseInitalize()
            {
                SchoolModels SH = new SchoolModels();

                if (Session["IndependentSchool"] != null)
                {
                    SH = (SchoolModels)Session["IndependentSchool"];
                  
                }
                else
                {
                    Response.Redirect("Welcome/Index");
                }

                return  SH.SchoolDataBase;
            }
        }

    Monday, September 17, 2018 6:05 PM
  • Hi maha6242,

    Thank you for posting in MSDN forum!

    Refer to your description, it seems this issue is about ASP.NET MVC issue. Since our forum is to discuss the VS IDE issues, please redirect to MVC forum and start a new thread for a better support, thank you for your understanding.

    Best Regards,

    May


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, September 18, 2018 9:27 AM