系统.badmageformatexception使用.net 2.0

本文关键字:net 使用 badmageformatexception 系统 | 更新日期: 2023-09-27 18:02:18

我对c#相当陌生,所以如果我误解了什么,请原谅我。

我有一个相当老的应用程序在我的工作,允许您导入dll的执行某些自动任务。所有的老程序员几年前就离开了,我也找不到支持这个应用程序的人。我使用。net 2.0框架在visual studio 2013中创建了一个dll,当我试图导入它时,我得到了这个错误信息:

The format of the file 'MyDll.dll' is invalid.  Type:System.BadImageFormatException
Source: mscorlib Stack Trace: at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Boolean isStringized, Evidence assemblySecurity, Boolean throwOnFileNotFound, Assembly locationHint, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Boolean stringized, Evidence assemblySecurity, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) 
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Applications.frmApplications.loadFields()
   at Applications.frmApplications.fillMenuItem()
   at Applications.frmApplications.ugApplications_AfterSelectChange(Object sender, AfterSelectChangeEventArgs e) 
   at Infragistics.Win.UltraWinGrid.UltraGrid.OnAfterSelectChange(AfterSelectChangeEventArgs e)
   at Infragistics.Win.UltraWinGrid.UltraGrid.FireEvent(GridEventIds id, EventArgs e)
   at Infragistics.Win.UltraWinGrid.UltraGrid.SelectNewSelection(Type type, Selected selected)
 at Infragistics.Win.UltraWinGrid.UltraGrid.InternalSelectItem(ISelectableItem     item, Boolean clearExistingSelection, Boolean select)
   at Infragistics.Win.UltraWinGrid.UltraGridRow.set_Selected(Boolean value)
   at Applications.frmApplications.searchForApplication()

我在网上查了这个错误,基本的意识是我使用了错误的。net框架版本。我已经使用。net Reflector来查看工作的旧dll正在使用的版本,它的版本为1.1.12.30886. 现在我的问题是,是否有另一种方法来解决这个错误,或者只能导入。net 1.1版本?如果是这样,是否有办法将我的dll更改为1.1框架,因为我看到它的生命周期已经过去,不再支持,而且我没有看到在visual studio中安装它的方法。

系统.badmageformatexception使用.net 2.0

如果您有应用程序的源代码,您可以为最新的。net框架重新编译它。. net和c#团队非常努力地使版本兼容,所以你可能不会有一个错误。

坚持使用1.1(或2.0)框架可能是一个坏主意——与现代版本相比,它的限制很大,而且正如您所注意到的,它不受支持。如果你真的想要,你必须下载旧版本的Visual Studio/SharpDevelop/MonoDevelop/等等。1.1还处在每个。net框架都有自己的Visual Studio版本的时代——你需要Visual Studio 2003。. NET使用1.1.

也就是说,我对不同。net框架版本之间的互操作并没有什么问题。但是,您需要确保安装了两个版本的框架——新版本的框架不包含旧版本(因此2.0不包括1.1,4.0不包括2.0或3.5)。有时您可以使用应用程序清单(程序集重新绑定)来修复此问题,但它可能会变得棘手。

BadImageFormatException的另一个常见来源是比特性。默认情况下,. net现在使用AnyCPU,这意味着如果可用,它将使用64位,否则使用32位。例如,可能其中一个项目使用32位,而另一个项目使用64位。