BreezeControllerAttribute exception: Could not load file or assembly 'System.Net.Http

限于喜欢 提交于 2019-12-11 05:43:10

问题


When I make a call to an API an error is displayed:

"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.",

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();
    }

    // ..
}

And implementation:

[BreezeController, Authorize]
public class usuariosController : baseApiController<User>
{
    public usuariosController(IUserRepository repositorio)
        : base(repositorio)
    { }
}

Url: GET /api/usuarios throw a exeption!

But my DDL is in reference:

Full response errror:

{
    "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()"
    }
}

Attempts

In the package manger console, run the command Add-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>

Found strange is not pointing to the 4.0. Can it be the problem? If yes, why Add-BindingRedirect did not work?


回答1:


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.



来源:https://stackoverflow.com/questions/17426306/breezecontrollerattribute-exception-could-not-load-file-or-assembly-system-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!