首页 > 解决方案 > 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。

我试图广泛地找到原因和解决方案。

但是,我仍然每次都收到此错误,并且 Web 角色不断重新启动尝试从此异常中恢复。

标签: c#.netazureazure-web-roles

解决方案


仔细阅读您的问题描述,我认为问题应该出在加载程序集的问题上,例如MyApi.dll.

首先,由于Azure云环境的限制,可能无法加载一些第三方程序集。你可以参考这篇文章

Azure 云服务服务创建完成后,可以得到一个虚拟机,可以使用RDP. 所以我建议你先创建你的应用程序,不要包含引用第三方的代码.dll,以确保成功部署。然后用RDP方法登录虚拟机,打开cmd,使用regsvr32 xxx.dll相关命令在注册表中注册第三方.dll文件,然后现在重新部署你的完整项目。检查问题是否已解决。


推荐阅读