3

我在启动网络角色时遇到了一个奇怪的问题。完整的复制非常复杂,但我设法找到了根本原因,所以我将简化步骤。

我的 webrole 项目依赖于 AssmeblyA,而后者又依赖于 AssemblyB,Version=1.0。webrole 也直接依赖于 AssemblyB,但 Version=2.0。(这一切都来自我无法控制的不同 NuGet 包)。

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

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

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

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

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

更新: 这是通过 IntelliTrace 获得的异常:

由于以下异常,无法加载角色入口点: -- System.IO.FileLoadException:

无法加载文件或程序集 'Microsoft.Owin, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(HRESULT 异常:0x80131040)文件名:'Microsoft.Owin,版本 = 3.0.0.0,文化 = 中性,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 复制的绑定重定向的 myassembly.dll.config 放入 E:\approot\bin,一切都会正确启动。

4

2 回答 2

1

你能澄清一下你到底在找什么吗?您在问题中提供答案(将重定向添加到 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)。

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

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

于 2015-03-29T06:34:53.753 回答
0

Azure 支持团队提供 AzureTools 来帮助解决此类问题。AzureTools 具有打开/关闭 Fusion Logging 功能,并且易于收集 azure 日志。

启用 Fusion Logging 后,您可以获得有关缺少程序集的更多信息。

http://blogs.msdn.com/b/kwill/archive/2013/08/26/azuretools-the-diagnostic-utility-used-by-the-windows-azure-developer-support-team.aspx

于 2015-03-29T08:36:45.387 回答