Solved

BadImageFormatException

Posted on 2009-07-14
2
548 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

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.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

820 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