我在启动网络角色时遇到了一个奇怪的问题。完整的复制非常复杂,但我设法找到了根本原因,所以我将简化步骤。
我的 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,一切都会正确启动。