Hello,

We are on Sitefinity version 11.2.6929.

Once in a while, completely randomly, Sitefinity backend starts throwing the "The type initializer for '<Module>' threw an exception." error.

We cannot create any new entries, update any existing data or upload any images. Other than that we can browse the site normally.

Restarting the server, cleaning and rebuilding the project, signing out and in from the backend, or switching to an alternative database server does not solve the problem. After a while (after 15-20 minutes) the problem goes away without any explanation.

Can anyone help with this situation?  This issue has been happening for weeks and we couldn't find any way to solve it.

The resulting error in the log is:

----------------------------------------
ActivityId: 00000000-0000-0000-0000-000000000000

Timestamp: 7/16/2019 6:16:01 PM

Message: HandlingInstanceID: 2a194ecc-212c-4d07-a8e9-e27970b84d0c
An exception of type 'System.TypeInitializationException' occurred and was caught.
----------------------------------------------------------------------------------
07/16/2019 21:16:01
Type : System.TypeInitializationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : The type initializer for '<Module>' threw an exception.
Source : System.Activities
Help link :
TypeName : <Module>
Data : System.Collections.ListDictionaryInternal
TargetSite : System.Linq.Expressions.Expression`1[System.Func`2[System.Activities.ActivityContext,T]] Compile[T](System.Activities.LocationReferenceEnvironment, Boolean)
HResult : -2146233036
Stack Trace : at Microsoft.VisualBasic.Activities.VisualBasicHelper.Compile[T](LocationReferenceEnvironment environment, Boolean isLocationReference)
at Microsoft.VisualBasic.Activities.VisualBasicHelper.Compile[T](CodeActivityPublicEnvironmentAccessor publicAccessor, Boolean isLocationReference)
at Microsoft.VisualBasic.Activities.VisualBasicHelper.Compile[T](String expressionText, CodeActivityPublicEnvironmentAccessor publicAccessor, Boolean isLocationExpression)
at Microsoft.VisualBasic.Activities.VisualBasicValue`1.CacheMetadata(CodeActivityMetadata metadata)
at System.Activities.CodeActivity`1.OnInternalCacheMetadataExceptResult(Boolean createEmptyBindings)
at System.Activities.Activity`1.OnInternalCacheMetadata(Boolean createEmptyBindings)
at System.Activities.Activity.InternalCacheMetadata(Boolean createEmptyBindings, IList`1& validationErrors)
at System.Activities.ActivityUtilities.ProcessActivity(ChildActivity childActivity, ChildActivity& nextActivity, Stack`1& activitiesRemaining, ActivityCallStack parentChain, IList`1& validationErrors, ProcessActivityTreeOptions options, ProcessActivityCallback callback)
at System.Activities.ActivityUtilities.ProcessActivityTreeCore(ChildActivity currentActivity, ActivityCallStack parentChain, ProcessActivityTreeOptions options, ProcessActivityCallback callback, IList`1& validationErrors)
at System.Activities.ActivityUtilities.CacheRootMetadata(Activity activity, LocationReferenceEnvironment hostEnvironment, ProcessActivityTreeOptions options, ProcessActivityCallback callback, IList`1& validationErrors)
at System.Activities.Hosting.WorkflowInstance.ValidateWorkflow(WorkflowInstanceExtensionManager extensionManager)
at System.Activities.Hosting.WorkflowInstance.RegisterExtensionManager(WorkflowInstanceExtensionManager extensionManager)
at System.Activities.WorkflowApplication.EnsureInitialized()
at System.Activities.WorkflowApplication.Enqueue(InstanceOperation operation, Boolean push)
at System.Activities.WorkflowApplication.InternalRun(TimeSpan timeout, Boolean isUserRun)
at System.Activities.WorkflowApplication.Run()
at Telerik.Sitefinity.Workflow.WorkflowManager.MessageWorkflow(Guid itemId, Type itemType, String providerName, String operationName, Boolean isCheckedOut, Dictionary`2 contextBag)
at Telerik.Sitefinity.DynamicModules.Web.Services.DataService.SaveDataItemInternal(DynamicItemContext dataItem, String itemType, String provider, String workflowOperation, String parentId, String parentType, String newParentId)
at Telerik.Sitefinity.DynamicModules.Web.Services.DataService.SaveChildDataItem(DynamicItemContext dataItem, String parentId, String dataItemId, String provider, String itemType, String workflowOperation, String parentType, String newParentId)
at SyncInvokeSaveChildDataItem(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

Additional Info:

MachineName : *******************
TimeStamp : 7/16/2019 6:16:01 PM
FullName : Telerik.Sitefinity.Utilities, Version=11.2.6929.0, Culture=neutral, PublicKeyToken=b28c218413bdf563
AppDomainName : /LM/W3SVC/2/ROOT-3-132077736086738958
ThreadIdentity :
WindowsIdentity : *********************************
Requested URL : localhost:52052/.../
Inner Exception
---------------
Type : <CrtImplementationDetails>.ModuleLoadException, Microsoft.VisualBasic.Activities.Compiler, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Message : The C++ module failed to load while attempting to initialize the default appdomain.

Source : Microsoft.VisualBasic.Activities.Compiler
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void <CrtImplementationDetails>.LanguageSupport.Initialize(<CrtImplementationDetails>.LanguageSupport*)
HResult : -2146233088
Stack Trace : at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* )
at .cctor()

Inner Exception
---------------
Type : System.Runtime.Serialization.SerializationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Type 'Telerik.Sitefinity.Security.SitefinityIdentity' in Assembly 'Telerik.Sitefinity, Version=11.2.6929.0, Culture=neutral, PublicKeyToken=b28c218413bdf563' is not marked as serializable.
Source : mscorlib
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage)
HResult : -2146233076
Stack Trace :
Server stack trace:
at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.<>c__DisplayClass9_0.<GetSerializableMembers>b__0(MemberHolder _)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Security.Claims.ClaimsPrincipal.SerializeIdentities()
at System.Security.Claims.ClaimsPrincipal.OnSerializingMethod(StreamingContext context)
at System.Runtime.Serialization.SerializationEvents.InvokeOnSerializing(Object obj, StreamingContext context)
at System.Runtime.Serialization.SerializationObjectManager.RegisterObject(Object obj)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeMessageParts(ArrayList argsToSerialize)
at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage..ctor(IMethodCallMessage mcm)
at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage.SmuggleIfPossible(IMessage msg)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMessage reqMsg)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at System.AppDomain.get_Id()
at <CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr function, Void* cookie)
at <CrtImplementationDetails>.LanguageSupport.InitializeDefaultAppDomain(LanguageSupport* )
at <CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport* )
at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* )

Category: ErrorLog

Priority: 0

EventId: 90000

Severity: Error

Title:Enterprise Library Exception Handling

Machine: ***********************************

App Domain: /LM/W3SVC/2/ROOT-3-132077736086738958

ProcessId: 11688

Process Name: C:\Program Files (x86)\IIS Express\iisexpress.exe

Thread Name:

Win32 ThreadId:15344

Extended Properties:
----------------------------------------