3

I created a simple windows service,the platform of the project is Any CPU and i installed my service using installutil.exe command. Then I uninstalled the service and set the platform to X64. But after this, i cannot install the service. I got the following error

Exception occured while initializing the installation: System.BadImageFormatException:Could not load file or assembly -- or one of its dependencies. An attempt was made to load a program with an incorrect format.

I want to change the platform to X64 for using some dlls. Please help me.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Aneesh
  • 848
  • 1
  • 9
  • 22
  • Are you using `installutil` from `%windir%\Microsoft.Net\Framework\vX.x.xxx` or from `%windir%\Microsoft.Net\Framework64\vX.x.xxx`? – Damien_The_Unbeliever May 29 '14 at 06:29
  • i have both %windir%\Microsoft.Net\Framework\vX.x.xxx and %windir%\Microsoft.Net\Framework64\vX.x.xxx. How can i use the Framework64 version – Aneesh May 29 '14 at 06:57
  • 1
    By specifying the full path to the one you want to use? (Which is pretty well the standard answer to any question about how to select which version of a command line tool will be used) – Damien_The_Unbeliever May 29 '14 at 07:00
  • it works successfully. I installed using the Framework64 path. But the uninstall fails. – Aneesh May 29 '14 at 07:23
  • How to uninstall the service using %windir%\Microsoft.Net\Framework64\vX.x.xxx. – Aneesh May 29 '14 at 07:28

2 Answers2

0

You must select the x86 platform, the dll run in mixed mode and will work with your service

daniele3004
  • 13,072
  • 12
  • 67
  • 75
0

The InstallUtill.exe is platform-speciffic

check this out: https://stackoverflow.com/a/2160932/891715

also, this will get you the correct path to the correct version:

 string InstallUtilPath = Path.Combine(
     System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(),
     "installutil.exe");

Also a little warning: be especially carefull if you're using the setup project to install your serveces. It embedes installutil into itself (and usually it isn't the correct version...).

Community
  • 1
  • 1
Arie
  • 5,251
  • 2
  • 33
  • 54
  • SetupProject is crap - which is why it was retired. WIX to go. SetupProject is not even able to make a standard compliant installer when you just add a text file, pretty much. – TomTom May 29 '14 at 06:40
  • @TomTom - regrettably, some people pushed for it, and it's [coming back](http://blogs.msdn.com/b/visualstudio/archive/2014/04/17/visual-studio-installer-projects-extension.aspx) – Damien_The_Unbeliever May 29 '14 at 06:49
  • F***, I hoped that one dies for good. WIX is all you really need. – TomTom May 29 '14 at 06:50