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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:23:36+00:00 2026-05-20T12:23:36+00:00

I have the following entities in my domain model. A group (an aggregate root)

  • 0

I have the following entities in my domain model. A group (an aggregate root) contains items (which are aggregate roots themselves) but an item can only be contained by one group at the time. The code below enforces this. The reason for the group to have an Items collection is that in the domain there are certain cases that are most logically solved by providing access items by means of a group.

When I add an item to my group however, I get this FatalExecutionEngineError:

The runtime has encountered a fatal
error. The address of the error was at
0x5f0b8442, on thread 0x99c. The error
code is 0xc0000005. This error may be
a bug in the CLR or in the unsafe or
non-verifiable portions of user code.
Common sources of this bug include
user marshaling errors for COM-interop
or PInvoke, which may corrupt the
stack.

Right after that, a System.ExecutionEngineException is thrown with no inner exception.

UPDATE

It seems that the _items.Contains(item) check in the Item.AssignTo method causes this exception to be thrown. I initially left this check out of the example but I have now added it. When I remove the check, I get an IndexOutOfRangeException at the _items.Add(item); statement.

This is my (simplified) domain model:

public class Group : Entity
{
    private List<Item> _items = new List<Item>();

    public virtual IEnumerable<Item> Items
    {
        get
        {
            return _items;
        }
    }

    public virtual void Assign(Item item)
    {
        if (_items.Contains(item))
        {
            throw new ArgumentException("Already assigned.", "item");
        }

        _items.Add(item);
    }
}

public class Item : Entity
{
    public virtual Group Group
    {
        get;
        protected set;
    }

    public virtual void AssignTo(Group group)
    {
        group.Assign(this);
        this.Group = group;
    }
}

The FluentNHibernate mapping overrides:

// AutoMapping<Group> 
mapping
    .HasMany(n => n.Documents)
    .Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore)
    .Cascade.Delete()
    .Inverse();

So, the exception is thrown when I call Item.AssignTo. When I remove the group.Assign(this); line from Item.AssignTo the exception is not raised. But ofcourse, in that case Document.Items stays empty until the document is retrieved from a repository sometime later.

What am I doing wrong or missing here?

  • 1 1 Answer
  • 1 View
  • 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-20T12:23:36+00:00Added an answer on May 20, 2026 at 12:23 pm

    Boy, I wonder what’s really going on here. I created a standalone testcase to reproduce the problem but somehow it ran just fine. While I was experimenting some more with the full project, I found that changing private List<Item> _items = new List<Item>(); to private IList<Item> _items = new List<Item>();, solved the problem!

    All of this makes me suspect there is bug in NHibernate somewhere but most of my former bug suspicions regarding external libraries turned out being bugs in my own code so I’m being a bit careful making such accusations.

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

Sidebar

Related Questions

I have the following Entities; Ticket contains a set of 0,N WorkOrder: @Entity public
Lets assume I have the following 3 entities: Customer,Order,Product which interact in the View
Assuming i have the following grail domain entities: class A { ... } class
Here is my problem: Domain: I have following Entities: [Sensor] that can be positioned
I have the following top-level (parent) domain entities: Customer Company Contact And the following
I have this partial view rendered multiple times on a page: @model POS.Domain.Entities.Category <div
I have the following domain entities: class Customer { // Customer properties... static belongsTo
Say, I have following entities: @Entity public class A { @Id @GeneratedValue private Long
I have the following entities in my system: COMPANY , POSITION , APPLICANTS .
I have the following entities: @Entity public class Owner{ @Id @Column(name = OWNER_ID) @OneToMany()

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.