In our application we have a class called ModelContext. In this class we create a new Domain, Configuration and Session (with DisconnectedState attached).

All this is done in a method call OpenSession(). In the constructor of that class the OpenSession() is called. So far everything works fine.

When we close the application we get an exception with text 'Scope can't be disposed' and a hint that it could be another thread closing the scope.

I've changed the Application so that we explicitly Dispose the Session, Configuration and Domain just before we end the Application. Now we don't get the exception anymore.

Our suspect is that the Session formerly was closed by the GC which runs in a different thread. Can you confirm this theory?

Regards Paul Sinnema Diartis AG

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Jul 01 '10 at 11:56

Paul%20Sinnema's gravatar image

Paul Sinnema

One Answer:

There is no finalizer in Domain and Session - as far as I remember, we didn't create them for any of other objects as well, since implicit finalization isn't necessary in our case. All allocated resources are already managed, i.e. if they need such finalizers, they must already have them.

So this might happen because of GC only if you have your own finalizers somewhere.

Other probable causes:

  • Wrong order of scope disposal. When outer scope is disposed before inner, our framework disposes inner scope in this case as well. But if inner scope is attempted to be disposed later, this exception is thrown. Probably, we must fix this, since any number of subsequent calls to Dispose must be allowed by IDisposable contract (only first one must lead to actual effects).
  • Passing a reference to scope to a different thread, and its subsequent disposal there. Everything is obvious here.

answered Jul 01 '10 at 22:43

Alex%20Yakunin's gravatar image

Alex Yakunin

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA