【问题标题】:C# program can run on development laptop, but cannot on anotherC# 程序可以在开发笔记本电脑上运行,但不能在另一台笔记本电脑上运行
【发布时间】:2020-01-24 08:10:36
【问题描述】:

在过去的 6 个月里,我一直在为我的实习开发一个 Windows 应用程序。该程序可以在其编程的笔记本电脑上正常工作,但我需要在另一台笔记本电脑上设置该程序。我安装了相同的 dotnet 核心版本 (3.0.100) 并使用同一目录中的所有必需 DLL 启动 .exe(因为它已编译)。但是当我这样做时,我得到如下所示的错误。

[ERROR][1/23/2020 7:58:41 PM][Thread 0006][akka://ModulairVisionFramework/user/InterfaceCameraActor] Error while creating actor instance of type CameraSystem.InterfaceCameraActor with 0 args: ()
Cause: [akka://ModulairVisionFramework/user/InterfaceCameraActor#1923472091]: Akka.Actor.ActorInitializationException: Exception during creation
 ---> System.TypeLoadException: Error while creating actor instance of type CameraSystem.InterfaceCameraActor with 0 args: ()
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.BadImageFormatException: Could not load file or assembly 'VimbaNET, Version=1.8.0.27270, Culture=neutral, PublicKeyToken=96b729f24f119b9a'. An attempt was made to load a program with an incorrect format.
File name: 'VimbaNET, Version=1.8.0.27270, Culture=neutral, PublicKeyToken=96b729f24f119b9a'
   at CameraSystem.InterfaceCameraActor..ctor()

   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at Akka.Actor.Props.ActivatorProducer.Produce()
   at Akka.Actor.Props.NewActor()
   --- End of inner exception stack trace ---
   at Akka.Actor.Props.NewActor()
   at Akka.Actor.ActorCell.CreateNewActorInstance()
   at Akka.Actor.ActorCell.<>c__DisplayClass109_0.<NewActor>b__0()
   at Akka.Actor.ActorCell.UseThreadContext(Action action)
   at Akka.Actor.ActorCell.NewActor()
   at Akka.Actor.ActorCell.Create(Exception failure)
   --- End of inner exception stack trace ---
   at Akka.Actor.ActorCell.Create(Exception failure)
   at Akka.Actor.ActorCell.SysMsgInvokeAll(EarliestFirstSystemMessageList messages, Int32 currentState)

[INFO][1/23/2020 7:58:44 PM][Thread 0008][akka://ModulairVisionFramework/user/InterfaceCameraActor] Message Initialize from akka://ModulairVisionFramework/user/FrameworkActor to akka://ModulairVisionFramework/user/InterfaceCameraActor was not delivered. 1 dead letters encountered.

这个错误System.BadImageFormatException: Could not load file or assembly 让我想到我可能使用了VimbaNET 的错误DLL,但我100% 确定我使用了正确的DLL。如果我确实使用了错误的 DLL VimbaNET,那么我会得到与上面相同的错误,但如果我使用正确的 DLL,我也会得到错误。我也试过在新的笔记本电脑上用同样的IDE编译这个应用程序,但是结果是一样的。

两台笔记本电脑都是 64 位的。

有谁知道我该如何解决这个问题?

我的应用程序的 32 位版本给出了同样的错误。

我用来编译和运行 64 位程序的设置。

我用来编译和运行 32 位程序的设置。

问题中涉及的所有 3 个程序集的程序集信息。

VimbaNET 是导致问题的 DLL

CameraSystem 是我自己的使用 VimbaNET 的程序集

ModulairVisionFramework 是使用 CameraSystem 程序集的主要应用程序

【问题讨论】:

  • 是网页应用还是windows应用?
  • 您的开发者笔记本电脑是否安装了 32 位操作系统?
  • @ArunprasanthKV Windows 应用程序
  • @LasseV.Karlsen 64 位,两台笔记本电脑都是 64 位
  • 那么它应该在两台机器上都可以工作,即。他们应该以同样的方式行事。当 32 位进程尝试加载 64 位程序集时,会引发 BadImageFormat 异常,反之亦然。您确定它正在加载相同的文件吗?会不会是你复制了一个 32 位的副本到另一台机器上,但在开发者笔记本电脑上使用了一个 64 位的文件?

标签: c# dll .net-core akka.net


【解决方案1】:

安装 .NET 3.5 解决了这个问题,因为 Vimba SDK 依赖于 .NET 2(不,不是 .NET Standard 或 Core 2)(阅读 Vimba C# API 文档)。 .NET 3.5 包括 .NET 2 运行时。

【讨论】:

    猜你喜欢
    • 2018-06-20
    • 2011-01-18
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 2012-09-06
    • 2020-01-20
    相关资源
    最近更新 更多