2

I'm fairly new at C#, so bear with me if I misunderstand something.

I have an fairly old application at my job that allows you to import dll's to do certain automated tasks. All the old programmers left years ago and I have no support to contact for this application. I created a dll in visual studio 2013 using .NET 2.0 framework and I get this error message when trying to import it:

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()

I looked up this error online and the basic consensious is that I am using the wrong .NET framework version. I have used .NET Reflector to see what version an older dll that works was using, and it comes up as version 1.1.12.30886 . Now my question is is there another way round this error, or can only dll .NET versions 1.1 be imported? And if so is there any way to change my dll's to the 1.1 framework, as I see its past its life cycle and is no longer supported and I don't see a way to install it in visual studio.

3
  • 4
    Possibly a 64/32 bit issue. Commented Jul 10, 2015 at 15:18
  • 1
    I thought that too, but i have it set to any cpu. Just for giggles i tried switching to just 64/32 and it gave the same error. Commented Jul 10, 2015 at 15:24
  • 1
    Are you sure this is the target framework's version and not the dll's? Anyway, .NET 1.1 is extremely old. The change from 1.1 to 2.0 affected the IL and the runtime itself. Commented Jul 10, 2015 at 15:24

1 Answer 1

2

If you have the sources for the application, you can just recompile it for the latest .NET framework. The .NET and C# teams work very hard to make the versions compatible, so you probably won't have a single error.

Sticking with the 1.1 (or 2.0) framework is probably a bad idea - it's very restrictive compared to modern versions, and as you've noted, it's unsupported. If you really want to, you'd have to download an old version of Visual Studio / SharpDevelop / MonoDevelop / whatever. 1.1 was still in a time when each .NET framework had its own Visual Studio version - you'd need Visual Studio 2003.NET to work with 1.1.

That said, I didn't really have trouble with interop between different .NET framework versions. However, you need to make sure both versions of the framework are installed - newer versions of the framework do not contain the old versions (so 2.0 doesn't include 1.1, and 4.0 doesn't include 2.0 or 3.5). Sometimes you can fix this with an application manifest (assembly rebinding), but it can get tricky.

Another common source of BadImageFormatException is the bit-ness. By default, .NET uses AnyCPU nowadays, which means it will use 64-bit if available, and 32-bit otherwise. It's possible that one of the projects uses 32-bit while the other uses 64-bit, for example.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried switching to 32-bit and 64-bit and it gave the same result. I will try to see if I can recompile the sources the old programmers left ino the newest framework.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.