azure - 由于无法加载依赖程序集,Web 角色无法启动

标签 azure azure-web-roles webrole

我在启动 Web 角色时遇到了一个奇怪的问题。 完整的重现相当复杂,但我设法找到了根本原因,所以我将给出简化的步骤。

我的webrole项目依赖于AssmeblyA,而AssmeblyA又依赖于AssemblyB,版本=1.0。 webrole也直接依赖于AssemblyB,但Version=2.0。 (这一切都来自不同的 NuGet 包,我无法对其进行任何控制)。

最后,AssemblyB,Version=2.0 被复制到\Bin 文件夹。 网站本身工作正常,因为在 Web.config 中有一个将 AssemblyB 绑定(bind)重定向到 Version=2.0(由 nuget 客户端自动放置在那里)。

但是,当webrole部署到Azure时,由于无法加载AssemblyB,Version=1.0而无法启动。

我怀疑这是因为Web角色首先从Approot目录加载,而web.config在该目录中不起作用。我还发现我可以通过为 Web 角色生成 app.config 并在那里复制所有绑定(bind)重定向来解决此问题。虽然这可行,但维护这样的设置不是很方便。

有谁知道这是否是 Azure Web 角色的已知问题?

尝试使用 Azure SDk 2.4 和 2.5.1,所有 azure nuget 包都是最新的,没有任何自定义启动代码。

更新: 以下是通过 IntelliTrace 获取的异常:

Unable to load the role entry point due to the following exceptions: -- System.IO.FileLoadException:

Could not load file or assembly 'Microsoft.Owin, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'Microsoft.Owin, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

这是堆栈跟踪:

CommonLanguageRuntimeLibrary!System.Reflection.RuntimeModule.GetTypes() 
CommonLanguageRuntimeLibrary!System.Reflection.Assembly.GetTypes()  
Microsoft.WindowsAzure.ServiceRuntime.dll!Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetRoleEntryPoint(System.Reflection.Assembly entryPointAssembly = {System.Reflection.RuntimeAssembly})  
Microsoft.WindowsAzure.ServiceRuntime.dll!Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CreateRoleEntryPoint(Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleType roleTypeEnum = IISWeb)    
Microsoft.WindowsAzure.ServiceRuntime.dll!Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleType roleTypeEnum = IISWeb)  
Microsoft.WindowsAzure.ServiceRuntime.dll!Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRole(Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleType roleType = IISWeb)  
Microsoft.WindowsAzure.ServiceRuntime.dll!Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.AnonymousMethod()   
CommonLanguageRuntimeLibrary!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext = {unknown}, System.Threading.ContextCallback callback = {unknown}, object state = {unknown}, bool preserveSyncCtx = {unknown})   
CommonLanguageRuntimeLibrary!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext = {unknown}, System.Threading.ContextCallback callback = {unknown}, object state = {unknown}, bool preserveSyncCtx = {unknown})   
CommonLanguageRuntimeLibrary!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext = {unknown}, System.Threading.ContextCallback callback = {unknown}, object state = {unknown}) 
CommonLanguageRuntimeLibrary!System.Threading.ThreadHelper.ThreadStart()

发生错误是因为我的Web角色项目依赖于Owin Version = 3.0.1.0,但另一个DLL(我通过nuget获取)依赖于Owin Version = 3.0.0.0。因此明显不匹配。

因此,服务运行时似乎仍在 WaIISHost.exe 中加载我的程序集,只是为了检查我是否有 RoleEntryPoint(我没有)。 就像以前一样,一旦我将从 web.config 复制的带有绑定(bind)重定向的 my assembly.dll.config 放入 E:\approot\bin 中,一切都会正确启动。

最佳答案

您能澄清一下您到底在寻找什么吗?您在问题中提供了答案(将重定向添加到 app.config),并在您的评论之一中提供了说明的链接 ( http://blogs.msdn.com/b/avkashchauhan/archive/2011/01/24/dissection-of-a-windows-azure-sdk-1-3-based-asp-net-web-role-in-full-iis-mode-amp-hwc.aspx )。

我可以确认您所看到的是预期的行为,并且您将绑定(bind)重定向添加到 app.config 的解决方案是正确的。

另一个可能的解决方案是更改 RoleEntrypoint 代码(即 WebRole.cs),使其不依赖于 AssemblyB,版本=1.0。无论您在 RoleEntrypoint 类中做什么,都可以从 Application_Start 中完成,以便它在 IIS 中运行吗?

关于azure - 由于无法加载依赖程序集,Web 角色无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29318683/

相关文章:

azure - 在Worker角色中模仿Webjob中的Schedule功能

windows - 我如何知道为什么我的 Azure 实例无法启动?

部署后 Azure Web 角色预热

database - Azure Cosmos Document DB,可能有关系链接吗?

c# - 使用图形的 Azure 函数我得到 "Could not load file or assembly ' System.Text.Json”

c# - 在 GoDaddy 上托管 selenium 应用程序。 "This program is blocked by group policy"

c# - 如何在 azure 中设置安全 Web 套接字

asp.net-mvc - IIS8中最佳的 "Dynamic IP Restriction Settings"是多少

asp.net - 在 ASP.NET Azure 托管网站和 Web 角色之间发出 AJAX 请求?

Azure LoadBalancerProbe 响应被忽略