locked
When calling “context.AttachTo” - The ObjectContext instance has been disposed and can no longer be used for operations that require a connection RRS feed

  • Question

  • Got a question over on stackoverflow that I could really use some help with. Basically, getting an object disposed exception on an entity because the context it used to be fetched is disposed. The thing is, though, that the exception is happening while trying to attach the entity to a new context.
    Tuesday, April 9, 2013 12:14 PM

Answers

  • Hi PbCraig;

    Please read this article, Attaching and Detaching Objects, it tell you what you need to do.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by Chester Hong Sunday, April 28, 2013 5:44 PM
    Wednesday, April 10, 2013 4:07 AM

All replies

  • Hi PbCraig;

    It sounds like you have not detached the entity from the old ObjectContect before attaching it to the new ObjectContext.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, April 9, 2013 1:46 PM
  • Hi Fernando

    Yeah, I tried that before I saw this post. It fixes the issue but causes a new one because of the entity losing all it's loaded navigation properties. It's so strange that IO don't have to detach in the test environment but I do here. This is causing me a huge headache.

    Tuesday, April 9, 2013 11:00 PM
  • Hi PbCraig;

    Please read this article, Attaching and Detaching Objects, it tell you what you need to do.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by Chester Hong Sunday, April 28, 2013 5:44 PM
    Wednesday, April 10, 2013 4:07 AM