iis .net 4.8:“”的类型初始值设定项< Module>引发异常

kb5ga3dv  于 2023-08-05  发布在  .NET
关注(0)|答案(3)|浏览(120)

我们的软件在调用Windows Workflow Foundation时出现问题。有趣的是,只有当客户端或服务器更新到.Net 4.8时才会出现这个问题。当两个环境都运行在旧版本的.Net上时,应用程序可以正常工作。这是我在日志中看到的。有趣的是,应用程序在自托管时工作正常。我们只在通过IIS时遇到此问题。
事件查看器详细信息:

2019-11-17 22:43:31.8065 | Error |
Message :Unable to find assembly 'Test.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Source : mscorlib
Stack Trace :
Server stack trace:
   at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
   at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
   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.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream stm)
   at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage.FixupForNewAppDomain()
   at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm)
   at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatchCallback(Object[] args)

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* )
TargetSite : System.Reflection.Assembly GetAssembly()
***************************************
Message :The C++ module failed to load while attempting to initialize the default appdomain.

Source : Microsoft.VisualBasic.Activities.Compiler
Stack Trace :    at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* )
   at .cctor()
TargetSite : Void <CrtImplementationDetails>.LanguageSupport.Initialize(<CrtImplementationDetails>.LanguageSupport*)
***************************************
Message :The type initializer for '<Module>' threw an exception.
Source : System.Activities
Stack Trace :    at Microsoft.VisualBasic.Activities.VisualBasicHelper.Compile[T](LocationReferenceEnvironment environment, Boolean isLocationReference)
   at System.Activities.CodeActivity`1.OnInternalCacheMetadataExceptResult(Boolean createEmptyBindings)
   at Microsoft.VisualBasic.Activities.VisualBasicHelper.Compile[T](CodeActivityPublicEnvironmentAccessor publicAccessor, Boolean isLocationReference)
   at System.Activities.Activity`1.OnInternalCacheMetadata(Boolean createEmptyBindings)
   at Microsoft.VisualBasic.Activities.VisualBasicHelper.Compile[T](String expressionText, CodeActivityPublicEnvironmentAccessor publicAccessor, Boolean isLocationExpression)
   at System.Activities.Activity.InternalCacheMetadata(Boolean createEmptyBindings, IList`1& validationErrors)
   at Microsoft.VisualBasic.Activities.VisualBasicValue`1.CacheMetadata(CodeActivityMetadata metadata)
   at System.Activities.ActivityUtilities.ProcessActivity(ChildActivity childActivity, ChildActivity& nextActivity, Stack`1& activitiesRemaining, ActivityCallStack parentChain, IList`1& validationErrors, ProcessActivityTreeOptions options, ProcessActivityCallback callback)
   at System.Activities.CodeActivity`1.OnInternalCacheMetadataExceptResult(Boolean createEmptyBindings)
   at System.Activities.Activity`1.OnInternalCacheMetadata(Boolean createEmptyBindings)
   at System.Activities.ActivityUtilities.ProcessActivityTreeCore(ChildActivity currentActivity, ActivityCallStack parentChain, ProcessActivityTreeOptions options, ProcessActivityCallback callback, IList`1& validationErrors)
   at System.Activities.Activity.InternalCacheMetadata(Boolean createEmptyBindings, 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.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.RunInstance(WorkflowApplication instance)
   at System.Activities.WorkflowApplication.RunInstance(WorkflowApplication instance)
   at System.Activities.WorkflowApplication.Invoke(Activity activity, IDictionary`2 inputs, WorkflowInstanceExtensionManager extensions, TimeSpan timeout)
   at System.Activities.WorkflowApplication.Invoke(Activity activity, IDictionary`2 inputs, WorkflowInstanceExtensionManager extensions, TimeSpan timeout)
   at System.Activities.WorkflowInvoker.Invoke(Activity workflow, IDictionary`2 inputs, TimeSpan timeout, WorkflowInstanceExtensionManager extensions)
   at System.Activities.WorkflowInvoker.Invoke(Activity workflow, IDictionary`2 inputs)
iis workflow-foundation

字符串

j91ykkif

j91ykkif1#

我不能添加评论,但我想添加一些更多的信息,这一问题。
问题似乎出在BinaryFormatter上:它在不同的AppDomain中运行,当您的应用程序托管在IIS上时,这将是一个问题。
我花了一些时间研究fuslogvw(记录所有绑定):
在.NET 4.7中,您可以获得webapp文件夹下的所有条目(例如/5577 f740/)中所示的值。
在.NET 4.8中,您会得到一个名为w3wp.exe的额外文件夹,在该文件夹下可以找到绑定错误的日志(例如,/5577 f740/和/w3wp.exe/中的文件)。
在我的情况下

=== Pre-bind state information ===
LOG: DisplayName = log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a
 (Fully-specified)
LOG: Appbase = file:///C:/WINDOWS/SysWOW64/inetsrv/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = w3wp.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/WINDOWS/SysWOW64/inetsrv/log4net.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/SysWOW64/inetsrv/log4net/log4net.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/SysWOW64/inetsrv/log4net.EXE.
LOG: Attempting download of new URL file:///C:/WINDOWS/SysWOW64/inetsrv/log4net/log4net.EXE.
LOG: All probing URLs attempted and failed.

字符串
最后,我们将框架版本恢复到了4.7。

swvgeqrz

swvgeqrz2#

我在.NET 4.8上遇到了同样的问题。在控制台应用程序中运行工作流时,没有错误。在IIS中运行工作流时,抛出了相同的ModuleLoadException。同样的代码在.NET 4.7或更早版本中运行得很好。似乎不是所有的工作流程(即.XAML文件)会触发此bug。我没有使用WorkflowInvoker.Invoke来运行工作流,而是使用ActivityXamlServices.Load()
看起来像是微软的bug。

utugiqy6

utugiqy63#

跟进这件事我们注意到这个问题只发生在具有VB表达式的C#工作流中。用C#表达式替换每个VB表达式解决了这个问题。

相关问题