我需要以下绑定:
我的设置如下。
一个网站项目。 引用该网站的Cloud Service Webrole。 从webrole启动方法调用并启动Owin自主服务的类库。
var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["CompositeServiceEndpoint"];
string baseUri = string.Format("{0}://{1}",
endpoint.Protocol, endpoint.IPEndpoint);
Trace.TraceInformation(String.Format("Starting OWIN at {0}", baseUri));
_app = WebApp.Start(new StartOptions(url: baseUri), (appbuilder) => new Startup().Configuration(appbuilder, CompositeWebRole.DependencyResolver));
这是失败的,它试图加载4.0。
Plugin Initialization 'Composite.WindowsAzure.Management.Plugins.CompositeManagementPlugin': System.IO.FileLoadException: Could not load file or assembly 'System.Web.Http, Version=4.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: 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
我尝试在网站项目的app.config和web.config中添加程序集绑定。这不是我应该把文件放在哪里吗?
我已经验证了,登录到远程桌面,f:/ approot /有web.config,里面有绑定。
完整错误是:
Plugin Initialization 'Composite.WindowsAzure.Management.Plugins.CompositeManagementPlugin': System.IO.FileLoadException: Could not load file or assembly 'System.Web.Http, Version=4.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: 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at Composite.WindowsAzure.Management.Startup.Configuration(IAppBuilder app, IWebroleDependencyResolver dpr)
at Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveApp(StartContext context)
at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context)
at Composite.WindowsAzure.Management.Plugins.CompositeManagementPlugin.InitializePlugin()
at Composite.WindowsAzure.WebRole.Websites.WebsiteManager.InitializeManager()
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
; TraceSource 'WaIISHost.exe' event
当我在模拟器中运行它时没有问题。
答案 0 :(得分:2)
根据您使用的SDK,我使用Azure SDK 2.3时遇到了这个问题。
由于现在使用完整IIS,因此WebRole无法查看常规Web.config文件或app.config文件。 Visual Studio应该自动将文件放在bin文件夹中,但由于某些原因,这对我不起作用。 如果是这种情况,请执行以下操作:
创建一个新的.config文件,将其命名为
"yourprojectname".dll.config
放入项目的根目录并为所需的所有引用插入程序集绑定代码,例如:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
然后部署项目,角色将看到新的配置文件。 希望这有助于某人。
答案 1 :(得分:0)
我无法找到真正问题的解决方案。
我最终从Unity WebAPI boostrapper获取代码,因为这是依赖性,它引入了对webapi的一些4.0.0.0引用。踢出这个,只是在我自己的dll中实现并且不使用unity web api bootsrapper解决了我的问题。
// Generated by .NET Reflector from C:\dev\c1\Source\WindowsAzure\packages\Unity.AspNet.WebApi.3.0.1304.0\lib\Net45\Microsoft.Practices.Unity.WebApi.dll
namespace Microsoft.Practices.Unity.WebApi
{
using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Web.Http.Dependencies;
public sealed class UnityDependencyResolver : IDependencyResolver, IDependencyScope, IDisposable
{
private IUnityContainer container;
private SharedDependencyScope sharedScope;
public UnityDependencyResolver(IUnityContainer container)
{
if (container == null)
{
throw new ArgumentNullException("container");
}
this.container = container;
this.sharedScope = new SharedDependencyScope(container);
}
public IDependencyScope BeginScope()
{
return this.sharedScope;
}
public void Dispose()
{
this.container.Dispose();
this.sharedScope.Dispose();
}
public object GetService(Type serviceType)
{
try
{
return this.container.Resolve(serviceType, new ResolverOverride[0]);
}
catch (ResolutionFailedException)
{
return null;
}
}
public IEnumerable<object> GetServices(Type serviceType)
{
try
{
return this.container.ResolveAll(serviceType, new ResolverOverride[0]);
}
catch (ResolutionFailedException)
{
return null;
}
}
private sealed class SharedDependencyScope : IDependencyScope, IDisposable
{
private IUnityContainer container;
public SharedDependencyScope(IUnityContainer container)
{
this.container = container;
}
public void Dispose()
{
}
public object GetService(Type serviceType)
{
return this.container.Resolve(serviceType, new ResolverOverride[0]);
}
public IEnumerable<object> GetServices(Type serviceType)
{
return this.container.ResolveAll(serviceType, new ResolverOverride[0]);
}
}
}
}