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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:44:44+00:00 2026-05-18T05:44:44+00:00

In delving into Fluent nHibernate, I discovered a potential breaker for using it… Given

  • 0

In delving into Fluent nHibernate, I discovered a potential breaker for using it…

Given the following POCO code.

public class Customer
{
   public virtual int Id { get; set; }
   public virtual string Name { get; set; }
   public virtual Details Details { get; set; }
}

public class Details
{
  public virtual int Id { get; set; }
  public virtual IList<Orders> Orders { get; set; }
}

public class CustomerMap : ClassMap<Customer>
{
 // perform mapping
}
public class DetailsMap : ClassMap<Details>
{
 // perform mapping
}

I loaded up ASP.NET MVC and attempted to use Json Serialization.

using System.Web.Script.Serialization;

    public static partial class JsonExtensions
    {
        public static string ToJson(this object item)
        {
            return new JavaScriptSerializer().Serialize(item);
        }
    }

And Lo, when I passed a query from my nHibernate context to the ToJson method, I got an error!

A circular reference was detected while serializing an object of type ‘System.Reflection.RuntimeModule’.

It seems to do this whether I pull a single object, or a list of objects ..or anything for that matter. I’ve even tried marking my classes as [Serializable] with the same result. This doesn’t happen with the exact same classes using the Microsoft Entity Framework Code-Only approach.

Can I not deserialize nHibernate DTOs into JSON?

Adding more code for examination.

        using (var session = sessionFactory.OpenSession())
        {
            using (var transaction = session.BeginTransaction())
            {
                var customers= session.CreateCriteria(typeof(Customer)).List<Customer>();

                foreach (var customer in customers)
                {
                    Console.WriteLine(customer.ToJson());
                }
                Console.ReadLine();
            }
        }
  • 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-18T05:44:45+00:00Added an answer on May 18, 2026 at 5:44 am

    This is just a hunch but you might like to investigate what type it is really trying to serialize- nHibernate generates proxies for each POCO at runtime (so it can do stuff like lazy loading of foreign key entities, etc.). This may be why you are getting this error.

    Try specifying the exact type to be serialized or perhaps create a brand new object to serialize, populating its properties with that of the nHibernate POCO.

    EDIT:
    This seems to be much more likley the answer to your problems:

    http://www.west-wind.com/WebLog/posts/147218.aspx

    Basically, check all of your POCO’s for any circular references (e.g. a Customer POCO that has an Order POCO as a property while the Order POCO has a list of Customer’s as a property)

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

Sidebar

Related Questions

I am delving into the EntityFramework 4 code first of entities approach and I
So I am delving into MVVM using C# with WPF (using Expression Blend) and
I am just delving into using jQuery and I want to start off by
While delving into some old code I've stumbled upon a function which is used
I am interested in delving into Erlang's C source code and try to understand
I have lately been delving into F# and the new DSL stuff as in
I have recently begun delving into the world that is database programming with C++
I'm working on delving into more complex WordPress theme options pages. Right now, I
Im not sure if this can be done, im just delving into templates so
I'm just delving into Objective C and Cocoa Touch and I'm trying to build

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.