Note that there are some explanatory texts on larger screens.

plurals
  1. POWill Entity Framework fail when running on a high volumn IIS web site
    primarykey
    data
    text
    <p>We have been trying to analyse this exception:</p> <blockquote> <p>Message: Error: Object reference not set to an instance of an object.. Stacktrace: at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) at System.Activator.CreateInstanceT at Z.Services.ObjectContextManagement.ScopedObjectContextManager<code>1.get_ObjectContext() at Z.Services.DatabaseAccess.DatabaseAccess</code>2.Manage() at Z.Services.DatabaseAccess.DatabaseAccess`2.get_ObjectContext()</p> </blockquote> <p>Basically we get an error when getting the ObjectContext.</p> <p>From this question: <a href="https://stackoverflow.com/questions/2575990/entity-framework-lazy-loading-doesnt-work-from-other-thread">Entity Framework lazy loading doesn&#39;t work from other thread</a> we see that EF is dependent upon staying on the same thread.</p> <p>From this Jon Skeet's answer to this question: <a href="https://stackoverflow.com/questions/1643987/will-a-request-in-iis-run-on-a-single-thread">Will a request in IIS run on a single thread?</a> we see that IIS has thread agility.</p> <p>When there is a lower traffic volumn we do not see this error, but when the load increases we see the error.</p> <p>So the question: If EF is dependent upon staying on a single thread, and IIS does not keep the request on a single thread, can EF be used on an application that is deployed on IIS?</p> <p><strong>Edit</strong></p> <pre><code>var frameworkAssembly = Assembly.GetAssembly(typeof(ObjectContextManager&lt;&gt;)); var managerType = frameworkAssembly.GetType(managerTypeName + "`1", true, true); managerType = managerType.MakeGenericType(typeof(TObjectContext)); ObjectContextManager = Activator.CreateInstance(managerType) as ObjectContextManager&lt;TObjectContext&gt;; </code></pre> <p>It appears that the error occurs on the last line of the above code. The error only occurs in production under heavy load.</p> <p><strong>Edit 2</strong></p> <p>The ObjectContextManager inherits from ObjectContext which is an EF class.</p> <pre><code> public abstract class ObjectContextManager&lt;T&gt; where T : ObjectContext </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload