I am facing below issue on production application and not able to found any specific location or code as a cause of the error can anyone having any idea then please suggest a solution.
message="Object cannot be stored in an array of this type."
source="mscorlib"
detail="System.InvalidCastException: Object cannot be stored in an array of this type.

at System.Array.InternalSetValue(Void* target, Object value)

at System.Array.SetValue(Object value, Int32[] indices)

at System.Runtime.Serialization.ObjectManager.CompleteObject(ObjectHolder holder, Boolean bObjectFullyComplete)

at System.Runtime.Serialization.ObjectManager.DoNewlyRegisteredObjectFixups(ObjectHolder holder)

at System.Runtime.Serialization.ObjectManager.RegisterObject(Object obj, Int64 objectID, SerializationInfo info, Int64 idOfContainingObj, MemberInfo member, Int32[] arrayIndex)

at System.Runtime.Serialization.Formatters.Binary.ObjectReader.RegisterObject(Object obj, ParseRecord pr, ParseRecord objectPr, Boolean bIsString)

at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObjectEnd(ParseRecord pr)

at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()

at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)

at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)

at System.Web.Util.AltSerialization.ReadValueFromStream(BinaryReader reader)

at System.Web.SessionState.SessionStateItemCollection.ReadValueFromStreamWithAssert()

at System.Web.SessionState.SessionStateItemCollection.DeserializeItem(String name, Boolean check)

at System.Web.SessionState.SessionStateItemCollection.get_Item(String name)

at System.Web.HttpSessionStateWrapper.get_Item(String name)

at System.Web.Mvc.SessionStateTempDataProvider.LoadTempData(ControllerContext controllerContext)

at System.Web.Mvc.TempDataDictionary.Load(ControllerContext controllerContext, ITempDataProvider tempDataProvider)

at System.Web.Mvc.Controller.PossiblyLoadTempData()

at System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state)

at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout)

at System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state)

at System.Web.Mvc.MvcHandler.<>c.<BeginProcessRequest>b__20_0(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState)

at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState)

at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout)

at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)

at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)

at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)" user="extranet\0031O00003QP1nTQAT"
time="2020-06-10T13:54:03.7681729Z">
I know its late, but I am curious if there was any development on this.
The "System.Web.Mvc.TempDataDictionary.Load" in the error definitely gives the clue that, this is something do with data stored in TempData. I also experienced the problem, but I could not exactly identify what data created the problem, because the code was abusing temp data a lot. Good news is that, I removed the code that uses TempData to store complex types. Its been 30 days and the exception is not happening again. Voila..!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.