C# 合并的可执行程序崩溃

C# 合并的可执行程序崩溃,c#,deployment,.net-4.0,ilmerge,C#,Deployment,.net 4.0,Ilmerge,我在.NET4.0上用c#开发了我的第一个winform应用程序。编译后的输出有一个.exe和一个.dll文件。在合并之前,我检查了可执行文件是否运行良好。我使用ILMerge合并了这两个文件。我第一次使用ILmerge。所以我一定是在什么地方犯了错误,但我无法解决这个问题。我得到了一个没有任何错误的可执行文件。但是在打开结果文件时,它会崩溃 Windows在应用程序崩溃时生成以下错误详细信息: Description: Stopped working Problem signature

我在.NET4.0上用c#开发了我的第一个winform应用程序。编译后的输出有一个.exe和一个.dll文件。在合并之前,我检查了可执行文件是否运行良好。我使用ILMerge合并了这两个文件。我第一次使用ILmerge。所以我一定是在什么地方犯了错误,但我无法解决这个问题。我得到了一个没有任何错误的可执行文件。但是在打开结果文件时,它会崩溃

Windows在应用程序崩溃时生成以下错误详细信息:

Description:
   Stopped working

Problem signature:
   Problem Event Name:  CLR20r3
   Problem Signature 01:    mywinapp.exe
   Problem Signature 02:    1.0.0.0
   Problem Signature 03:    52383768
   Problem Signature 04:    mscorlib
   Problem Signature 05:    2.0.0.0
   Problem Signature 06:    4ca2b851
   Problem Signature 07:    f99
   Problem Signature 08:    14e
   Problem Signature 09:    System.TypeLoadException
   OS Version:  6.1.7601.2.1.0.256.1
   Locale ID:   16393
我安装了ILMerge,并在ILMerge位置的cmd中使用以下命令来创建合并的.exe文件

 ilmerge D:\abc\RemittanceForm.exe D:\abc\PdfFileWriter.dll  /out:D:\out\MyWinApp.exe      /target:winexe /ndebug /log:D:\out\aaa.txt
日志文件内容如下:

ILMerge version 2.12.803.0 Copyright (C) Microsoft Corporation 2004-2006. All rights reserved. ILMerge D:\abc\RemittanceForm.exe D:\abc\PdfFileWriter.dll /out:D:\out\MyWinApp.exe /target:winexe /ndebug /log:D:\out\aaa.txt Set platform to 'v2', using directory 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\..\v2.0.50727' for mscorlib.dll Running on Microsoft (R) .NET Framework v2.0.50727 mscorlib.dll version = 2.0.0.0 The list of input assemblies is: D:\abc\RemittanceForm.exe D:\abc\PdfFileWriter.dll Trying to read assembly from the file 'D:\abc\RemittanceForm.exe'. Successfully read in assembly. There were no errors reported in Remittance Form's metadata. Trying to read assembly from the file 'D:\abc\PdfFileWriter.dll'. Successfully read in assembly. There were no errors reported in PdfFileWriter's metadata. Checking to see that all of the input assemblies have a compatible PeKind. Remittance Form.PeKind = ILonly PdfFileWriter.PeKind = ILonly All input assemblies have a compatible PeKind value. AssemblyResolver: Assembly 'Remittance Form' is referencing assembly 'System.Windows.Forms'. AssemblyResolver: Attempting referencing assembly's directory. AssemblyResolver: Did not find assembly in referencing assembly's directory. AssemblyResolver: Attempting input directory. AssemblyResolver: Did not find assembly in input directory. AssemblyResolver: Attempting user-supplied directories. AssemblyResolver: No user-supplied directories. AssemblyResolver: Attempting framework directory. Resolved assembly reference 'System.Windows.Forms' to 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\..\v2.0.50727\System.Windows.Forms.dll'. (Used framework directory.) AssemblyResolver: Assembly 'Remittance Form' is referencing assembly 'System'. AssemblyResolver: Attempting referencing assembly's directory. AssemblyResolver: Did not find assembly in referencing assembly's directory. AssemblyResolver: Attempting input directory. AssemblyResolver: Did not find assembly in input directory. AssemblyResolver: Attempting user-supplied directories. AssemblyResolver: No user-supplied directories. AssemblyResolver: Attempting framework directory. Resolved assembly reference 'System' to 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\..\v2.0.50727\System.dll'. (Used framework directory.) AssemblyResolver: Assembly 'Remittance Form' is referencing assembly 'System.Drawing'. AssemblyResolver: Attempting referencing assembly's directory. AssemblyResolver: Did not find assembly in referencing assembly's directory. AssemblyResolver: Attempting input directory. AssemblyResolver: Did not find assembly in input directory. AssemblyResolver: Attempting user-supplied directories. AssemblyResolver: No user-supplied directories. AssemblyResolver: Attempting framework directory. Resolved assembly reference 'System.Drawing' to 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\..\v2.0.50727\System.Drawing.dll'. (Used framework directory.) Using assembly 'Remittance Form' for assembly-level attributes for the target assembly. Merging assembly 'Remittance Form' into target assembly. Merging assembly 'PdfFileWriter' into target assembly. Copying 1 Win32 Resources from assembly 'Remittance Form' into target assembly. Transferring entry point 'Remittance_Form.Program.Main' from assembly 'Remittance Form' to assembly 'MyWinApp'. There were no errors reported in the target assembly's metadata. ILMerge: Writing target assembly 'D:\out\MyWinApp.exe'. AssemblyResolver: Assembly 'System' is referencing assembly 'System.Configuration'. AssemblyResolver: Attempting referencing assembly's directory. Resolved assembly reference 'System.Configuration' to 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Configuration.dll'. (Used referencing Module's directory.) Location for referenced module 'gdi32.dll' is '' Location for referenced module 'Kernel32.dll' is '' Location for referenced assembly 'System.Windows.Forms' is 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Windows.Forms.dll' There were no errors reported in System.Windows.Forms's metadata. Location for referenced assembly 'System' is 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\system.dll' There were no errors reported in System's metadata. Location for referenced assembly 'mscorlib' is 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorlib.dll' There were no errors reported in mscorlib's metadata. Location for referenced assembly 'System.Drawing' is 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Drawing.dll' There were no errors reported in System.Drawing's metadata. ILMerge: Done. ILMerge版本2.12.803.0 版权所有(C)微软公司2004-2006。版权所有。 ILMerge D:\abc\remitteanceform.exe D:\abc\PdfFileWriter.dll/out:D:\out\MyWinApp.exe/target:winexe/ndebug/log:D:\out\aaa.txt 使用mscorlib.dll的目录“C:\Windows\Microsoft.NET\Framework64\v2.0.50727\…\v2.0.50727”,将平台设置为“v2” 在Microsoft(R).NET Framework v2.0.50727上运行 mscorlib.dll版本=2.0.0.0 输入程序集的列表为: D:\abc\remittentanseform.exe D:\abc\PdfFileWriter.dll 正在尝试从文件“D:\abc\relmittanceform.exe”中读取程序集。 已成功读入程序集。 汇款表单元数据中未报告任何错误。 正在尝试从文件“D:\abc\PdfFileWriter.dll”读取程序集。 已成功读入程序集。 PdfielWriter的元数据中未报告任何错误。 检查所有输入程序集是否具有兼容的PeKind。 汇款表单.PeKind=ILonly PdfFileWriter.PeKind=ILonly 所有输入程序集都具有兼容的PeKind值。 AssemblyResolver:程序集“汇款表单”正在引用程序集“System.Windows.Forms”。 AssemblyResolver:正在尝试引用程序集的目录。 AssemblyResolver:在引用程序集的目录中找不到程序集。 AssemblyResolver:正在尝试输入目录。 AssemblyResolver:在输入目录中找不到程序集。 AssemblyResolver:正在尝试用户提供的目录。 AssemblyResolver:没有用户提供的目录。 AssemblyResolver:正在尝试框架目录。 已将程序集引用“System.Windows.Forms”解析为“C:\Windows\Microsoft.NET\Framework64\v2.0.50727\..\v2.0.50727\System.Windows.Forms.dll”。(使用框架目录。) AssemblyResolver:程序集“汇款表单”正在引用程序集“系统”。 AssemblyResolver:正在尝试引用程序集的目录。 AssemblyResolver:在引用程序集的目录中找不到程序集。 AssemblyResolver:正在尝试输入目录。 AssemblyResolver:在输入目录中找不到程序集。 AssemblyResolver:正在尝试用户提供的目录。 AssemblyResolver:没有用户提供的目录。 AssemblyResolver:正在尝试框架目录。 已将程序集引用“System”解析为“C:\Windows\Microsoft.NET\Framework64\v2.0.50727\..\v2.0.50727\System.dll”。(使用框架目录。) AssemblyResolver:程序集“汇款表单”正在引用程序集“System.Drawing”。 AssemblyResolver:正在尝试引用程序集的目录。 AssemblyResolver:在引用程序集的目录中找不到程序集。 AssemblyResolver:正在尝试输入目录。 AssemblyResolver:在输入目录中找不到程序集。 AssemblyResolver:正在尝试用户提供的目录。 AssemblyResolver:没有用户提供的目录。 AssemblyResolver:正在尝试框架目录。 已将程序集引用“System.Drawing”解析为“C:\Windows\Microsoft.NET\Framework64\v2.0.50727\..\v2.0.50727\System.Drawing.dll”。(使用框架目录。) 对目标程序集的程序集级属性使用程序集“汇款表单”。 正在将程序集“汇款表单”合并到目标程序集。 正在将程序集“PdfielWriter”合并到目标程序集。 正在将1个Win32资源从程序集“汇款表单”复制到目标程序集。 正在将入口点“汇款表单.Program.Main”从程序集“汇款表单”传输到程序集“MyWinApp”。 目标程序集的元数据中未报告任何错误。 ILMerge:正在写入目标程序集“D:\out\MyWinApp.exe”。 AssemblyResolver:程序集“System”正在引用程序集“System.Configuration”。 AssemblyResolver:正在尝试引用程序集的目录。 已将程序集引用“System.Configuration”解析为“C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Configuration.dll”。(用于引用模块的目录。) 引用模块“gdi32.dll”的位置为“” 引用模块“Kernel32.dll”的位置为“” 引用的程序集“System.Windows.Forms”的位置是“C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Windows.Forms.dll” System.Windows.Forms的元数据中未报告任何错误。 引用的程序集“System”的位置是“C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.dll” 系统元数据中未报告任何错误。 引用的程序集“mscorlib”的位置是“C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorlib.dll” mscorlib的元数据中未报告任何错误。 引用的程序集“System.Drawing”的位置是“C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Drawing.dll” System.Drawing的元数据中未报告任何错误。 伊尔梅:完成了。
请帮助我解决此问题。

我将ILMerge命令修改为以下内容:

ilmerge D:\abc\RemittanceForm.exe D:\abc\PdfFileWriter.dll  /out:D:\out\MyWinApp.exe /target:winexe /ndebug /log:D:\out\aaa.txt /targetplatform:"v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"
谢谢@Magnus Grindal Bakken

看看这个答案是否有用: