none
Bad Image format RRS feed

  • Question

  • Hi guyz

    When I compiled ILASM Code to exe file My code is

    .method static void main()
    {
        .entrypoint
        .maxstack 1

        ldstr "Hello world!"
        call void [mscorlib]System.Console::WriteLine(string)

        ret
    }

    I used commandline from Visual Studio Command Prompt "ilasm myfile"

    It generates EXE file but when I execute it i get this error


    Unhandled Exception: System.BadImageFormatException: Could not load file or asse
    mbly 'code.exe' or one of its dependencies. The module was expected to contain a
    n assembly manifest.

    Can you please help me why i am getting this error. Because i am new to ILASM


    ---------------------Do the Impossible--------------------- Great Software at http://atosoft.webs.com/

    Friday, May 24, 2013 6:12 AM

Answers

  • Ohh.. I am sorry. I overlooked your question :)

    Ok. There are  two things missing in your IL. One is reference to mscorlib.dll & the manifest. So, adding those two information to the IL will solve your problem. I have added those two info as below which runs successfully,

    .assembly extern mscorlib {}
    .assembly SampleIL {
        .ver 1:0:1:0
    }
    .module SampleIL.exe
    
    .method static void main()
     {
         .entrypoint
         .maxstack 1
    
        ldstr "Hello world!"
        call void [mscorlib]System.Console::WriteLine(string)
    
        ret
     }

    I hope this helps.

    Please mark this post as answer if it solved your problem. Happy Programming!

    • Marked as answer by NaxAlpha Monday, May 27, 2013 4:04 AM
    Monday, May 27, 2013 3:23 AM

All replies

  • Looks like you have set the Target Platform of assembly as x64. Change it to x86. You can change the Target Platform in Project settings.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Friday, May 24, 2013 12:52 PM
  • I am not using VB or C# i have used ILASM to compile my code into an exe file but it is still same error

    My system is x64 Although i have used both x86 and x64 Visual studio command prompts to compile code the error is same

    Can you please help me!


    ---------------------Do the Impossible--------------------- Great Software at http://atosoft.webs.com/

    Friday, May 24, 2013 3:45 PM
  • Ohh.. I am sorry. I overlooked your question :)

    Ok. There are  two things missing in your IL. One is reference to mscorlib.dll & the manifest. So, adding those two information to the IL will solve your problem. I have added those two info as below which runs successfully,

    .assembly extern mscorlib {}
    .assembly SampleIL {
        .ver 1:0:1:0
    }
    .module SampleIL.exe
    
    .method static void main()
     {
         .entrypoint
         .maxstack 1
    
        ldstr "Hello world!"
        call void [mscorlib]System.Console::WriteLine(string)
    
        ret
     }

    I hope this helps.

    Please mark this post as answer if it solved your problem. Happy Programming!

    • Marked as answer by NaxAlpha Monday, May 27, 2013 4:04 AM
    Monday, May 27, 2013 3:23 AM
  • Thnx for helping i got it

    When i added .assembly MyAssembly line only in the start of my code it worked well but u game me code better


    ---------------------Do the Impossible--------------------- Great Software at http://atosoft.webs.com/

    Monday, May 27, 2013 3:58 AM