3
votes

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.

2
Are you using installutil from %windir%\Microsoft.Net\Framework\vX.x.xxx or from %windir%\Microsoft.Net\Framework64\vX.x.xxx?Damien_The_Unbeliever
i have both %windir%\Microsoft.Net\Framework\vX.x.xxx and %windir%\Microsoft.Net\Framework64\vX.x.xxx. How can i use the Framework64 versionAneesh
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
it works successfully. I installed using the Framework64 path. But the uninstall fails.Aneesh
How to uninstall the service using %windir%\Microsoft.Net\Framework64\vX.x.xxx.Aneesh

2 Answers

0
votes

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

0
votes

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...).