access method 'System.Web.Http.HttpConfiguration.DefaultFormatters()' failed

后端 未结 3 618
生来不讨喜
生来不讨喜 2020-12-18 19:02

I have problem with unit testing my WEB API controller, I\'m using moq to mock up my repository, do the setup and response for it. Then initiate the controller with mocked r

相关标签:
3条回答
  • 2020-12-18 19:19

    Check your packages.config , Make sure that the following Nuget packaged libraries are at the same version:

    <package id="Microsoft.AspNet.WebApi" version="x.x.x" targetFramework="net45" />
    <package id="Microsoft.AspNet.WebApi.Client" version="x.x.x" targetFramework="net45" />
    <package id="Microsoft.AspNet.WebApi.Core" version="x.x.x" targetFramework="net45" />
    <package id="Microsoft.AspNet.WebApi.WebHost" version="x.x.x" targetFramework="net45" />
    

    Uninstall-package from WebApi, WebApiWebhost, WebApi.Core, WebApi.Client

    PM> uninstall-package Microsoft.AspNet.WebApi
    PM> uninstall-package Microsoft.AspNet.WebApi.WebHost
    PM> uninstall-package Microsoft.AspNet.WebApi.Core
    PM> uninstall-package Microsoft.AspNet.WebApi.Client
    

    Reinstall-package,

    PM> install-package Microsoft.AspNet.WebApi -version x.x.x
    
    0 讨论(0)
  • 2020-12-18 19:31

    Try ensuring that Microsoft.AspNet.WebApi.Client is installed.

    My app wasn't working because I'd removed that for other reasons.

    Open Package Manager Console and execute:

    Install-Package Microsoft.AspNet.WebApi.Client

    0 讨论(0)
  • 2020-12-18 19:32

    Make sure that the following Nuget packaged libraries are at the same version:

    Microsoft.AspNet.WebApi
    Microsoft.AspNet.WebApi.Client
    Microsoft.AspNet.WebApi.Core
    Microsoft.AspNet.WebApi.WebHost
    
    0 讨论(0)
提交回复
热议问题