Click to See Complete Forum and Search --> : Installing Windows service using the InstallUtil, 3.5 vs 4


dannystommen
May 14th, 2010, 03:19 AM
For installing Windows services on the server, I used the following batchfile

@ECHO OFF

REM The following directory is for .NET 2.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727
set PATH=%PATH%;%DOTNETFX2%

echo Installing MyService...
echo ---------------------------------------------------
InstallUtil /i MyService.exe
echo ---------------------------------------------------
echo Done.
pause

So far, always worked nice. All my services where .NET 3.5.

Now I created my first Windows service in .NET 4. Installing the service using this batchfile resulted in the following BadImageException: Could not load file or assembly '...' or one of its dependencies. This is assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded..

So I changed the batchfile to

@ECHO OFF

REM The following directory is for .NET 4
set DOTNETFX4=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX4%

echo Installing MyService...
echo ---------------------------------------------------
InstallUtil /i MyService.exe
echo ---------------------------------------------------
echo Done.
pause

Windows service is installed succesfully now :-)

But, why is the first batch file able to install services of .NET 3.5 (also newer than 2.0), but not .NET 4.

Is this because .NET 2.0, 3.0 and 3.5 are using the CLR 2.0 and .NET 4 is using the CLR 4?