Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

BadImageFormatException

Posted on 2009-07-14
2
Medium Priority
?
555 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

782 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