BreezeControllerAttribute例外:无法加载文件或程序集“System.Net.

2019-10-18 07:54发布

当我打电话给API显示的错误:

“无法加载文件或程序集‘System.Net.Http,版本= 2.0.0.0,文化=中性公钥= b03f5f7f11d50a3a’或它的一个依赖,系统不能找到指定的文件。”,

我有我的API基本控制器

[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!

但我的DDL是在参考:

全响应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()"
    }
}

尝试

在包管理器控制台,运行命令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>

发现了奇怪的是没有指向4.0。 它可以是问题吗? 如果是的话,为什么Add-BindingRedirect没有工作?

Answer 1:

这是最肯定的绑定重定向问题。 我建议你整个复制<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">从一个新的ASP.NET MVC 4项目内容,以你的web.config文件。 这发生在我身上偶尔和刷新搞砸绑定修复该问题。



文章来源: BreezeControllerAttribute exception: Could not load file or assembly 'System.Net.Http