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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:45:28+00:00 2026-06-09T19:45:28+00:00

I started a new project and for this project i wanted to use BasicSample

  • 0

I started a new project and for this project i wanted to use BasicSample (NHibernate best practise, http://www.codeproject.com/Articles/13390/NHibernate-Best-Practices-with-ASP-NET-1-2nd-Ed) i haven´t used this before and now i get problems. In this project i use NHibernate 3.3.1 and modified the source code from BasicSample to use my entieties. I get this error for every class model (just showing for the class “Month”):

System.TypeInitializationException was unhandled by user code

Message=The type initializer for ‘Nested’ threw an exception.
Source=Project.Data
TypeName=Nested
StackTrace:
at Project.Data.NHibernateSessionManager.get_Instance() in Project.Data\NHibernateSessionManager.cs:line 28
at Project.Web.NHibernateSessionModule.BeginTransaction(Object sender, EventArgs e) in App_Code\NHibernateSessionModule.cs:line 27
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
InnerException: NHibernate.InvalidProxyTypeException
Message=The following types may not be used as proxies:
Project.Core.Domain.Calendar.Month: method Equals should be ‘public/protected virtual’ or ‘protected internal virtual’
Project.Core.Domain.Calendar.Month: method IsTransient should be ‘public/protected virtual’ or ‘protected internal virtual’
Project.Core.Domain.Calendar.Month: method get_Year should be ‘public/protected virtual’ or ‘protected internal virtual’
Project.Core.Domain.Calendar.Month: method set_Year should be ‘public/protected virtual’ or ‘protected internal virtual’
Blockquote

the class looks like:

public class Month : DomainObject<int>
{
    private Year _year;
    public Year Year
    {
        get { return _year; }
        set { _year = value; }
    }

    private string _monthName; 
    public string MonthName
    {
        get { return _monthName; }
        set { _monthName = value; }
    }

    private IList<Consumption> consumptions = new List<Consumption>();
    public IList<Consumption> Consumptions
    {
        get { return new List<Consumption>(consumptions).AsReadOnly(); }
        protected set { consumptions = value; }
    }

    public Month()
    { }

    public override int GetHashCode()
    {
        return (GetType().FullName + "|" +
                MonthName.GetHashCode()).GetHashCode();
    }

Does anoyone know what the problem could be? I have been crosschecking my project and the BasicSample project but i can´t find anything that missmatch.

2.Can someone explain for me how to use the GetHashCode from DaomainObject because i don´t know how to use this one in every class= Should every property in the class be added here?

I hope someone can help me.

  • 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-09T19:45:29+00:00Added an answer on June 9, 2026 at 7:45 pm
    1. NHibernate uses lazy loading by default. It performs it by creating proxy classes from your entities – inheriting from your entity and overriding it’s members. In order for this to work, you need to mark all of your entity members as virtual. That was what it complains about in exception message.

    2. As for GetHashCode, you should implement it in DomainObject and only use Id in GetHashCode overrides. You should also override Equals. Here you can find reasons why: NHibernate: Reasons for overriding Equals and GetHashCode.

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

Sidebar

Related Questions

I just started a new project and wanted to use HaskellDB in the beginning.
I have started a new mvc project and clicked on project\properties\web - use local
I've recently started a new web development project for an embedded device and wanted
So I started this new project, and I was trying to incorporate all the
I wanted to get some advice, I have started on a new project to
I've recently started a new project, and we plan to create this in Silverlight.
I started downloading the MVC Template, and created a new project using this template.
I recently started a small project in which I wanted to use zxing. I
I started a new project this morning and, after putting ~3 hours of work
We started a new project and the nature of the project is very interactive

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.