首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mkbundle抛出“IKVM.Reflection.BadImageFormatException”

mkbundle抛出“IKVM.Reflection.BadImageFormatException”
EN

Stack Overflow用户
提问于 2014-11-19 15:13:52
回答 2查看 1.7K关注 0票数 7

我一直试图使用mkbundle编译或捆绑我的应用程序。这是我正在执行的脚本:

代码语言:javascript
复制
set -o errexit
set -o nounset

mono_version="3.2.3"
export MONO=/cygdrive/c/progra~2/Mono-$mono_version

machineconfig=$PROGRAMFILES\\Mono-$mono_version\\etc\\mono\\4.0\\machine.config

export PATH=$PATH:$MONO/bin

export PKG_CONFIG_PATH=$MONO/lib/pkgconfig

icon_name='"icon.ico"'

echo "1 ICON $icon_name" > icon.rc

export CC="i686-pc-mingw32-gcc icon.o -U _WIN32"

output_name=Output.exe

mkbundle JiraTempoApp.exe MonoPosixHelper.dll gtk-sharp.dll glib-sharp.dll atk-sharp.dll gdk-sharp.dll glade-sharp.dll glib-sharp.dll pango-sharp.dll RestSharp.dll JiraRestLib.dll --deps --machine-config "$machineconfig" -o $output_name -z

rm icon.rc 
rm icon.o

cp $MONO/bin/mono-2.0.dll .
cp $MONO/bin/zlib1.dll .

./$output_name

我不得不添加MonoPosixHelper.dll,因为我得到了一个EntryPoint未找到的错误。现在我发现了一个奇怪的错误:

代码语言:javascript
复制
$ ./mkbundle_cygwin.sh
OS is: Windows
WARNING:
  Check that the machine.config file you are bundling
  doesn't contain sensitive information specific to this machine.
Sources: 11 Auto-dependencies: True

Unhandled Exception:
IKVM.Reflection.BadImageFormatException: Exception of type 'IKVM.Reflection.BadImageFormatException' was thrown.
  at IKVM.Reflection.Reader.PEReader.RvaToFileOffset (UInt32 rva) [0x00000] in <filename unknown>:0
  at IKVM.Reflection.Reader.ModuleReader.Read (System.IO.Stream stream) [0x00000] in <filename unknown>:0
  at IKVM.Reflection.Reader.ModuleReader..ctor (IKVM.Reflection.Reader.AssemblyReader assembly, IKVM.Reflection.Universe universe, System.IO.Stream stream, System.String location) [0x00000] in <filename unknown>:0
  at IKVM.Reflection.Universe.OpenRawModule (System.IO.Stream stream, System.String location) [0x00000] in <filename unknown>:0
  at IKVM.Reflection.Universe.OpenRawModule (System.String path) [0x00000] in <filename unknown>:0
  at IKVM.Reflection.Universe.LoadFile (System.String path) [0x00000] in <filename unknown>:0
  at MakeBundle.LoadAssembly (System.String assembly) [0x00000] in <filename unknown>:0
  at MakeBundle.LoadAssemblies (System.Collections.Generic.List`1 sources) [0x00000] in <filename unknown>:0
  at MakeBundle.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: IKVM.Reflection.BadImageFormatException: Exception of type 'IKVM.Reflection.BadImageFormatException' was thrown.
  at IKVM.Reflection.Reader.PEReader.RvaToFileOffset (UInt32 rva) [0x00000] in <filename unknown>:0
  at IKVM.Reflection.Reader.ModuleReader.Read (System.IO.Stream stream) [0x00000] in <filename unknown>:0
  at IKVM.Reflection.Reader.ModuleReader..ctor (IKVM.Reflection.Reader.AssemblyReader assembly, IKVM.Reflection.Universe universe, System.IO.Stream stream, System.String location) [0x00000] in <filename unknown>:0
  at IKVM.Reflection.Universe.OpenRawModule (System.IO.Stream stream, System.String location) [0x00000] in <filename unknown>:0
  at IKVM.Reflection.Universe.OpenRawModule (System.String path) [0x00000] in <filename unknown>:0
  at IKVM.Reflection.Universe.LoadFile (System.String path) [0x00000] in <filename unknown>:0
  at MakeBundle.LoadAssembly (System.String assembly) [0x00000] in <filename unknown>:0
  at MakeBundle.LoadAssemblies (System.Collections.Generic.List`1 sources) [0x00000] in <filename unknown>:0
  at MakeBundle.Main (System.String[] args) [0x00000] in <filename unknown>:0

我的.exe成功地在Windows和Ubuntu上运行,但是我试图将它捆绑在一起,这样用户就不必下载mono了。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-12-10 14:30:58

mkbundle不能像MonoPosixHelper.dll那样处理动态链接库。如果希望不使用mono运行应用程序,则需要将此库(和其他库)与应用程序一起部署到目标系统上。

如果您想在Ubuntu上运行您的应用程序,并且不希望用户安装libgtk2.0- libatksharpglue-2.so libgdksharpglue-2.so libglibsharpglue-2.so libgtksharpglue-2.so libpangosharpglue-2.so,那么您还必须根据*-sharp.dll的需要部署它们。

然后确保目标系统能够找到这些库。无论是通过定义LD_LIBRARY_PATH,还是通过在构建系统上创建DLL映射(这很棘手,可能会变得有些乏味)。

您还可以将--static参数传递给mkbundle,以便将所有所需的mono库直接包含在包中(有关详细信息,请参阅手册)。另外,只使用MyApp.exe执行最后的包,而不是使用mono MyApp.exe

下面是一些用于Linux目标的选项。我还没有在Windows上使用mkbundle和mono,但是只使用msbuild对.NET进行编译,后者也会创建.msi文件。

备选案文1:

代码语言:javascript
复制
$DEPS = "gtk-sharp.dll glib-sharp.dll atk-sharp.dll gdk-sharp.dll glade-sharp.dll glib-sharp.dll pango-sharp.dll RestSharp.dll JiraRestLib.dll"
mkbundle --static -o JiraTempoApp JiraTempoApp.exe --deps $DEPS --machine-config "$machineconfig" -z

然后确保部署MonoPosixHelper.dll。以及上面描述给您的系统的其他.so文件。若要启动应用程序,请执行

代码语言:javascript
复制
LD_LIBRARY_PATH=/path/to/deployed/libs:$LD_LIBRARY_PATH JiraTempoApp

但是,我无法验证这个设置LD_LIBRARY_PATH的方法目前是否有效。

备选案文2:

使用与选项1相同的命令构建,但从部署的libs目录执行:

代码语言:javascript
复制
cd /path/to/deployed/libs; /path/to/JiraTempoApp

备选方案3:

这有点复杂:您需要在构建系统上找到依赖.dll及其.dll.config文件。将它们复制到构建目录和配置文件中的dll映射,其中包含到.so目标系统上文件位置的相对路径。通过这种方式,dll映射将由mkbundle打包,打包后的可执行文件将能够在目标系统上找到已部署的.so。我曾经为一个使用此选项的应用程序编写了一个Makefile,也许它会对您有所帮助。

票数 1
EN

Stack Overflow用户

发布于 2014-11-26 17:12:56

您确定MonoPosixHelper.dll是一个托管库吗?只能在托管代码上工作。您仍然应该使用这个DLL (将它放在加载它的文件夹中,就像在您用LD_LIBRARY_PATH定义的文件夹中那样),以避免EntryNotFound异常,但不应该将它用作mkbundle命令的参数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27020297

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档