Asp.Net MVC 5 и Hottowel 2.01/Breeze - не удалось загрузить файл или сборку 'System.Web.Http, версия =4.0.0.0, ... или одна из ее зависимостей

Я создал новый проект Asp.net MVC 5 с использованием VS 2013, а затем добавил HotTowel 2.0.1 ( http://www.nuget.org/packages/HotTowel/). Сайт работает. Однако webapi с контроллером breeze выдает следующую ошибку, когда я пытаюсь получить контроллер WebApi Events, Бриз версия 1.4.2.

Код контроллера

[BreezeController]
public class BreezeController : ApiController
{
    readonly EFContextProvider<ApplicationDbContext> _contextProvider = new EFContextProvider<ApplicationDbContext>();

    [HttpGet]
    public string Metadata()
    {
        return _contextProvider.Metadata();
    }

    [HttpGet]
    public IQueryable<Event> Events()
    {
        return _contextProvider.Context.Events;
    }
}

Сообщение об ошибке

<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
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)
</ExceptionMessage>
<ExceptionType>System.IO.FileLoadException</ExceptionType>
<StackTrace>
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit) at System.RuntimeType.GetCustomAttributes(Boolean inherit) at System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type) at System.Web.Http.Controllers.HttpControllerDescriptor.Initialize() at System.Web.Http.Controllers.HttpControllerDescriptor..ctor(HttpConfiguration configuration, String controllerName, Type controllerType) at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.InitializeControllerInfoCache() at System.Lazy`1.CreateValue() at System.Lazy`1.LazyInitValue() at System.Lazy`1.get_Value() at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(HttpRequestMessage request) at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()
</StackTrace>
</Error>

1 ответ

Решение

Скорее всего, ваш код ссылается на system.web.http версии 4.0.0.0, а ваш проект ссылается на версию 5. Вы можете установить версию 4 или обновить код для использования версии 5.

Если код, относящийся к версии 4, находится в сторонней библиотеке (например, Breeze), то вам нужно будет получить новую версию из них или установить старую версию (4) из system.web.http lib.

Другие вопросы по тегам