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

时间:2019-08-16 04:02:16

标签: asp.net visual-studio asp.net-web-api macos-mojave

我正在macOS Mojave(10.14.6)上使用Visual Studio for Mac [Community]版本8.2.3。

我创建了一个ASP.NET Core 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

我想念/做错了什么? enter image description here

2 个答案:

答案 0 :(得分:1)

尝试清洁溶液并重建。有时重新启动Visual Studio也会清除此类问题。 如果您正在使用nuget之类的任何程序包管理器进行安装,请参阅packages.config文件中已添加程序集或在config中添加从属程序集文件。查看bin中的构建文件是否具有此dll。

答案 1 :(得分:0)

An attempt was made to load a program with an incorrect format.

用户错误。我的。

我应该一直在使用x64 DLL,而在使用x86 DLL。看来已经解决了。