Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8668815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:18:27+00:00 2026-06-12T18:18:27+00:00

We have been trying to analyse this exception: Message: Error: Object reference not set

  • 0

We have been trying to analyse this exception:

Message: Error: Object reference not set to an instance of an object..
Stacktrace: at System.RuntimeTypeHandle.CreateInstance(RuntimeType
type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached,
RuntimeMethodHandleInternal& ctor, Boolean& 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.ScopedObjectContextManager1.get_ObjectContext()
at Z.Services.DatabaseAccess.DatabaseAccess
2.Manage() at
Z.Services.DatabaseAccess.DatabaseAccess`2.get_ObjectContext()

Basically we get an error when getting the ObjectContext.

From this question: Entity Framework lazy loading doesn't work from other thread we see that EF is dependent upon staying on the same thread.

From this Jon Skeet’s answer to this question: Will a request in IIS run on a single thread? we see that IIS has thread agility.

When there is a lower traffic volumn we do not see this error, but when the load increases we see the error.

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?

Edit

var frameworkAssembly = Assembly.GetAssembly(typeof(ObjectContextManager<>));
var managerType = frameworkAssembly.GetType(managerTypeName + "`1", true, true);
managerType = managerType.MakeGenericType(typeof(TObjectContext));
ObjectContextManager = Activator.CreateInstance(managerType) as ObjectContextManager<TObjectContext>;

It appears that the error occurs on the last line of the above code. The error only occurs in production under heavy load.

Edit 2

The ObjectContextManager inherits from ObjectContext which is an EF class.

 public abstract class ObjectContextManager<T> where T : ObjectContext
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:18:28+00:00Added an answer on June 12, 2026 at 6:18 pm

    I’ve hit some issues with thread agility and IIS recently. IIS can shift the thread of a request as it goes through the pipeline. This doesn’t mean you have to be more aware of concurrency; what is important is the way context data is attached to the thread.

    In an ASP.NET environment, this storage is done via the HttpContent.Current variable, which holds details for the current request being handled on the current thread. It does this via the System.Runtime.Remoting.Messaging.CallContext.HostContext variable.

    Many solutions for keeping data per thread make use of the ThreadStatic attribute, however this fails in an ASP environment because of the thread switch. The thread static starts off valued, then appears to become null midway through the processing pipeline.

    ASP.NET will keep track of the HttpContext, the CurrentPrincipal, and possibly the locale as well. CallContext data and data stored in ThreadStatic variables is not copied.

    The answer, while irritating, is to change the strategy and use HttpContext.Current.Items instead of CallContext or thread statics.

    In your case, check the strategy in use for EF, and see if the implementation is pluggable.

    As Jon Skeet points out, more information is available on Cup(Of T), but use this more as a launchpad for your discovery rather than an end in itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to test this but have as of yet been unsuccessful.
Have been trying to fix this problem I have here. Basically I have a
I have been trying to figure out how all this validation works, but I
I have been trying to get this working for a while now and am
Have been trying to find the error in one line of code. Return expected
Have been trying to fix this for the past hour. Here goes: <script type=text/javascript>
I have been trying to get this to work. Basically I have a search
I have been trying to get this to work for most of the day
Have been trying to encrypt an xml file to a string so that I
Have have been trying to make a validator for my xml files. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.