Instance Failure using ContextManager

Instance Failure using ContextManager

Old forum URL: forums.lhotka.net/forums/t/7087.aspx


jrule posted on Thursday, June 11, 2009

When using ContextManager, the first use of the DataContext object throws an "Instance Failure" error.  I can create a DataContext object directly (without using ContextManager).

Anyone have a clue what might be going on?

 

RockfordLhotka replied on Friday, June 12, 2009

ContextManager creates the DataContext using a parameterless constructor (if I recall correctly), and so only works if the DataContext can be created in that manner. Perhaps your context is somehow different?

My recommendation is to use the debugger, step through the code in ContextManager to where it creates the instance of the DataContext and see exactly what exception occurs. Or look at the stack trace and find the underlying exception.

jrule replied on Friday, June 12, 2009

Looking at the code in debug, the ContextManager appears to get setup properly.  But the first time it's accessed, the first code executed in ContextManager is Dispose(), which resets the refcount to 0.  Here's the code I'm executing:

Using (ContextManager<MyDataContext> ctx = ContextManager<MyDataContext>.GetManager(MyDal.Database.MyDbName, true))

{

// The following line of code causes ContextManager Dispose() to run.

var data = (from g in ctx.DataContext.Groups where g.Id == criteria.value select g).Single();

LoadProperty(IdProperty, data.Id);

.....

}

I'm not sure I understand why the ContextManager hits the Dispose() method while still in the Using block.  I thought it could be due to running in the IDE, but I get the same error executing outside the IDE.

Copyright (c) Marimer LLC