ASP.NET Web API–;FileNotFoundException:无法加载文件或程序集

ASP.NET Web API–;FileNotFoundException:无法加载文件或程序集,asp.net,visual-studio,asp.net-web-api,macos-mojave,Asp.net,Visual Studio,Asp.net Web Api,Macos Mojave,我正在macOS Mojave(10.14.6)上使用Visual Studio for Mac[社区]8.2.3版 我创建了一个ASP.NET核心API解决方案。我需要访问第三方DLL并将其添加到我的项目中——它显示在“依赖项/程序集”下。我正在通过POST方法访问它 项目建设良好。在调试模式下运行并访问POST URL时,出现以下错误: $ dotnet run Using launch settings from /Users/vishal/Projects/Triceratops/Pro

我正在macOS Mojave(10.14.6)上使用Visual Studio for Mac[社区]8.2.3版

我创建了一个ASP.NET核心API解决方案。我需要访问第三方DLL并将其添加到我的项目中——它显示在“依赖项/程序集”下。我正在通过
POST
方法访问它

项目建设良好。在调试模式下运行并访问POST URL时,出现以下错误:

$ dotnet run
Using launch settings from /Users/vishal/Projects/Triceratops/Properties/launchSettings.json...
: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using '/Users/vishal/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Hosting environment: Development
Content root path: /Users/vishal/Projects/Triceratops
Now listening on: https://localhost:8080
Now listening on: http://localhost:8000
Application started. Press Ctrl+C to shut down.
dbug: HttpsConnectionAdapter[1]
      Failed to authenticate HTTPS connection.
System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest)
--- End of stack trace from previous location where exception was thrown ---
   at System.Net.Security.SslState.ThrowIfExceptional()
   at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
   at System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult asyncResult)
   at System.Net.Security.SslStream.<>c.<AuthenticateAsServerAsync>b__51_1(IAsyncResult iar)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionAdapter.InnerOnConnectionAsync(ConnectionAdapterContext context)
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 POST https://localhost:8080/api/battery application/json 10432
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[3]
      Route matched with {action = "Post", controller = "Battery"}. Executing controller action with signature Double[,] Post(BatteryParamModel) on controller Triceratops.Controllers.BatteryController (Triceratops).
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
      Executing action method Triceratops.Controllers.BatteryController.Post (Triceratops) - Validation state: Valid
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Executed action Triceratops.Controllers.BatteryController.Post (Triceratops) in 109.7701ms
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
System.BadImageFormatException: Could not load file or assembly 'RenewablesLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. An attempt was made to load a program with an incorrect format.

File name: 'RenewablesLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
   at Triceratops.Controllers.BatteryController.Post(BatteryParamModel data)
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)


info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 285.122ms 500 text/html; charset=utf-8
$dotnet运行
使用/Users/vishal/Projects/Triceratops/Properties/launchSettings.json中的启动设置。。。
:Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
用户配置文件可用。使用“/Users/vishal/.aspnet/DataProtection Keys”作为密钥存储库;密钥在静止时不会被加密。
托管环境:开发
内容根路径:/Users/vishal/Projects/Triceratops
现在收听:https://localhost:8080
现在收听:http://localhost:8000
应用程序已启动。按Ctrl+C组合键关闭。
dbug:HttpsConnectionAdapter[1]
无法验证HTTPS连接。
System.IO.IOException:身份验证失败,因为远程方已关闭传输流。
位于System.Net.Security.SslState.StartReadFrame(字节[]缓冲区,Int32 readBytes,AsyncProtocolRequest asyncRequest)
位于System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest)
---来自引发异常的上一个位置的堆栈结束跟踪---
位于System.Net.Security.SslState.ThrowifeException()处
位于System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult-lazyResult)
位于System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult结果)
位于System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult asyncResult)

在System.Net.Security.SslStream.c.

尝试清理解决方案并重建。有时重新启动Visual Studio也会清除此类问题。
如果您正在使用任何包管理器(如nuget)进行安装,请参阅packages.config文件添加了程序集或在config中添加依赖程序集文件。查看bin中的生成文件是否具有此dll。

尝试清理解决方案并重新生成。有时重新启动Visual Studio也会清除此类问题。
如果您正在使用任何包管理器(如nuget)进行安装,请参阅packages.config文件添加了程序集或在config中添加依赖程序集文件。查看bin中的生成文件是否有此dll。

试图加载格式不正确的程序。

用户错误。我的


我应该使用x64 DLL,而不是x86 DLL。似乎已修复。

试图加载格式不正确的程序。

用户错误。我的


我应该使用x64 DLL,而不是x86 DLL。这似乎已经解决了问题。

尝试了几次,但都没有成功。请查看dll是否支持项目的框架。。我以前也遇到过这样的问题,我不知道怎么做,希望能有一个逐步检查的指南。对我来说很好。重新启动VS对我来说很有效。节省了我很多时间(和头发)尝试了几次,但都没有成功。请查看dll是否支持项目的框架。。我以前也遇到过这样的问题,我不知道怎么做,希望能有一个逐步检查的指南。对我来说很好。重新启动VS对我来说很有效。节省了我很多时间(和头发)