Solved

BadImageFormatException

Posted on 2009-07-14
2
545 Views
Last Modified: 2013-12-17
I am creating a c# program using a dll called GlobalVariable.dll in windows\system32.
I gave me an exception when I using a function within a dll. Can anyone tell me if there is more I need to setup the environment or tips how to resolve this problem. The code is the wrapper code the dll. The attachment is the snapshot during debugging.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
 
namespace TSGlobalVariables
{
    public class TS
    {
        [DllImport("GlobalVariable.dll", EntryPoint = "GV_SetInteger")]
        public static extern int GV_SetInteger(int iLocation, int iVal);
        [DllImport("GlobalVariable.dll", EntryPoint = "GV_GetInteger")]
        public static extern int GV_GetInteger(int iLocation);
        [DllImport("GlobalVariable.dll", EntryPoint = "GV_SetDouble")]
        public static extern int GV_SetDouble(int iLocation, double dVal);
        [DllImport("GlobalVariable.dll", EntryPoint = "GV_GetDouble")]
        public static extern double GV_GetDouble(int iLocation);
    }
}

Open in new window

BadImageFormatException.jpg
0
Comment
Question by:xewoox
2 Comments
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 total points
ID: 24849317
The error message would seem to suggest your DLL is not really a DLL (or is a 64-bit DLL on a 32-bit system, or vice versa).

I Googled "BadImageFormatException" and first on the results list:

http://msdn.microsoft.com/en-us/library/system.badimageformatexception.aspx
This exception is thrown when the file format of a dynamic link library (.dll file) or an executable (.exe file) does not conform to the format that is expected by the common language runtime.
0
 

Author Closing Comment

by:xewoox
ID: 31603239
Good answer, right to the point.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question