locked
Unusual exception working with Entity Framework in Multithreding environment RRS feed

  • Question

  • I have a database model which I have imported in my code using Entity Framework(EF). There are some entities that are created by EF. I retrieve x no of entities using Function import and then my business logic works directly on those retrieved entities and updates certain properties based on some logic. what I am doing is, for each entity i am creating a new thread and applying my business logic on them using an action chain that I have built. So, there is one entity passed to a thread and all of them are being processed asynchronously. The problem now is that I keep on getting this weird exception every now and then (the exception is not consistent, it comes from any action in the action chain for any property), "EntityMemberChanged or EntityComplexMemberChanged was called without first calling EntityMemberChanging or EntityComplexMemberChanging on the same change tracker with the same property name. For information about properly reporting changes, see the Entity Framework documentation". 
    • Moved by Paul Zhou Friday, December 9, 2011 9:00 AM move for better support (From:.NET Base Class Library)
    Thursday, December 8, 2011 10:14 AM

Answers

  • Hi Helge25,

    Welcome to MSDN Forum!

    I think the root cause is an instance of ObjectContext was shared in many threads. Any instance members of this class are not guaranteed to be thread safe. More information about ObjectContext, please refer here.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    • Proposed as answer by Tyler_A Monday, December 12, 2011 4:44 PM
    • Marked as answer by Allen_MSDN Thursday, December 15, 2011 1:52 AM
    Monday, December 12, 2011 8:01 AM

All replies

  • I'm moving this thread to ADO.NET Entity Framework and LINQ to Entities forum to get better support.

    Have a nice day.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Friday, December 9, 2011 8:59 AM
  • Hi Helge25,

    Welcome to MSDN Forum!

    I think the root cause is an instance of ObjectContext was shared in many threads. Any instance members of this class are not guaranteed to be thread safe. More information about ObjectContext, please refer here.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    • Proposed as answer by Tyler_A Monday, December 12, 2011 4:44 PM
    • Marked as answer by Allen_MSDN Thursday, December 15, 2011 1:52 AM
    Monday, December 12, 2011 8:01 AM