c# - Azure 云服务 Web 角色未启动 - 未处理的异常 - 找不到程序集
问题描述
我有一个托管在云服务 Web 角色中的 ASP.NET Web API。我添加了一个扩展 RoleEntryPoint 的 WebRole 类,它试图检索一个 IoC 城堡 Windsor 容器,该容器在我的 Web API 的 StartUp.cs 中设置了依赖项。然后我想检索我注册的记录器实例并在我的 WebRole 中使用它。
public class WebRole : RoleEntryPoint
{
private ICancellationTokenSourceProvider _cancellationTokenSourceProvider;
public override bool OnStart()
{
try
{
var container = IoC.GetContainer();
_cancellationTokenSourceProvider = container.Resolve<ICancellationTokenSourceProvider>();
}
catch (Exception)
{
throw;
}
return base.OnStart();
}
但是,当我尝试将其部署到云服务时,出现以下异常:
未处理的异常:找不到程序集“Castle.Windsor,版本=3.2.0.0,文化=中性,PublicKeyToken=407dd0808d44fbdc”。在 System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() 在 System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo,字符串名称) 在 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) 在 System.Runtime.Serialization.Formatters.Binary.__BinaryParser .ReadObjectWithMapTyped(BinaryObjectWithMapTyped 记录) 在 System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run() 在 System.Runtime。System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) 在 System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream stm) 在 System.AppDomain.Deserialize(Byte[] blob) 在 System.AppDomain.UnmarshalObject(Byte[] blob) ' [2020-06 -19T16:48:01Z] 上次退出时间:[2020/06/19, 16:48:05.617]。最后退出代码:0。IMethodCallMessage methodCallMessage) 在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) 在 System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream stm) 在System.AppDomain.Deserialize(Byte[] blob) at System.AppDomain.UnmarshalObject(Byte[] blob) ' [2020-06-19T16:48:01Z] 最后退出时间: [2020/06/19, 16:48: 05.617]。最后退出代码:0。IMethodCallMessage methodCallMessage) 在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) 在 System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream stm) 在System.AppDomain.Deserialize(Byte[] blob) at System.AppDomain.UnmarshalObject(Byte[] blob) ' [2020-06-19T16:48:01Z] 最后退出时间: [2020/06/19, 16:48: 05.617]。最后退出代码:0。Deserialize(Byte[] blob) at System.AppDomain.UnmarshalObject(Byte[] blob) ' [2020-06-19T16:48:01Z] 最后退出时间:[2020/06/19, 16:48:05.617]。最后退出代码:0。Deserialize(Byte[] blob) at System.AppDomain.UnmarshalObject(Byte[] blob) ' [2020-06-19T16:48:01Z] 最后退出时间:[2020/06/19, 16:48:05.617]。最后退出代码:0。
我试图广泛地找到原因和解决方案。
- 我尝试将绑定重定向添加到 MyApi.dll.config 中缺少的程序集,并确保将其设置为始终复制。
- 我还确保程序集也将 Copy Local设置为 true。
但是,我仍然每次都收到此错误,并且 Web 角色不断重新启动尝试从此异常中恢复。
解决方案
仔细阅读您的问题描述,我认为问题应该出在加载程序集的问题上,例如MyApi.dll
.
首先,由于Azure云环境的限制,可能无法加载一些第三方程序集。你可以参考这篇文章。
Azure 云服务服务创建完成后,可以得到一个虚拟机,可以使用RDP
. 所以我建议你先创建你的应用程序,不要包含引用第三方的代码.dll
,以确保成功部署。然后用RDP
方法登录虚拟机,打开cmd
,使用regsvr32 xxx.dll
相关命令在注册表中注册第三方.dll
文件,然后现在重新部署你的完整项目。检查问题是否已解决。
推荐阅读
- wordpress - header.php 中的透明导航
- javascript - 在 React 中使用绑定到来自 LitElement 的属性
- xslt - xslt 通过子字符串删除重复值
- java - setCellValue(String value) throws java: cannot access java.time.LocalDate class file for java.time.LocalDate not found
- c# - 自定义窗口镶边时是否可以保留普通按钮?
- leaflet - 如何更改 bindPopup 的行为
- reactjs - 两个反应应用程序的入口未加载 css
- routes - Svetle 路由在应用内工作,但不能直接在浏览器中工作
- python - 使用 keras api 导出的 .pb 模型进行预测
- javascript - 为什么我不能用 getOptionLabel 呈现我想要的东西?