BreezeControllerAttribute异常:无法加载文件或程序集“System.Net.Http [英] BreezeControllerAttribute exception: Could not load file or assembly 'System.Net.Http
问题描述
当我打电话给API则显示错误:
When I make a call to an API an error is displayed:
无法加载文件或程序集System.Net.Http,版本= 2.0.0.0,文化=中性公钥= b03f5f7f11d50a3a'或其依赖项之一。该系统找不到指定的文件。
"Could not load file or assembly 'System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.",
我有一个基本的控制器为我的API
Code
I have a base controller for my APIs
[BreezeNHController]
public class baseApiController<T> : ApiController
where T : class, IEntity
{
public IRepository<T> Repositorio { get; private set; }
[HttpGet, BreezeNHQueryable(AllowedQueryOptions = AllowedQueryOptions.All, PageSize = 20)]
public IQueryable<T> Get()
{
return Repositorio.All();
}
// ..
}
和实施
[BreezeController, Authorize]
public class usuariosController : baseApiController<User>
{
public usuariosController(IUserRepository repositorio)
: base(repositorio)
{ }
}
!网址:GET / API / USUARIOS
抛出一个exeption
Url: GET /api/usuarios
throw a exeption!
但我的DDL是在参考:
But my DDL is in reference:
{
"Message": "An error has occurred.",
"ExceptionMessage": "The type initializer for 'Breeze.WebApi.BreezeControllerAttribute' threw an exception.",
"ExceptionType": "System.TypeInitializationException",
"StackTrace": " at Breeze.WebApi.BreezeControllerAttribute.Initialize(HttpControllerSettings settings, HttpControllerDescriptor descriptor)\r\n at System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type)\r\n at System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type)\r\n at System.Web.Http.Controllers.HttpControllerDescriptor..ctor(HttpConfiguration configuration, String controllerName, Type controllerType)\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.InitializeControllerInfoCache()\r\n at System.Lazy`1.CreateValue()\r\n at System.Lazy`1.LazyInitValue()\r\n at System.Lazy`1.get_Value()\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(HttpRequestMessage request)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()",
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Could not load file or assembly 'System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.",
"ExceptionType": "System.IO.FileNotFoundException",
"StackTrace": " at Breeze.WebApi.JsonFormatter.Create()\r\n at Breeze.WebApi.BreezeControllerAttribute..cctor()"
}
}
尝试
在包管理器控制台,运行命令添加-BindingRedirect
。
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
发现了奇怪的是没有指向4.0。它可以是问题吗?如果是的话,为什么添加-BindingRedirect
没有工作?
推荐答案
这是最肯定的绑定重定向问题。我建议你复制整个&LT; assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1&GT;
从一个新的ASP.NET MVC 4项目内容你的web.config文件。这发生在我身上偶尔刷新搞砸绑定修复该问题。
This is most definitely a binding redirect issue. I advice you copy the entire <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
content from a fresh ASP.NET MVC 4 project to your web.config file. This happens to me occasionally and refreshing the messed up bindings fixes the issue.
这篇关于BreezeControllerAttribute异常:无法加载文件或程序集“System.Net.Http的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!