CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Eric Wise

Business & .NET

Enterprise Library Registry Error (installservices.bat)

So, I've recently finished Beta 1 of the local install of Easy Assets .NET and I started passing it to some of the beta testers (thanks to those companies that graciously accepted to test it).  So far a few people have been into my code and I've received many compliments on how clean and nice the database and code is.  I'm glad that my refactoring seems to have paid big dividends.

Suddenly, mysteriously, I got two reports from beta testers that the application wasn't working as per my install instructions and was giving a mysterious registry error in the enterprise library.  How could this be?!  The Enterprise Library has worked fine for me in development for months.  I assembled the following information to start:

  • Problem occurs when deploying to Windows Server 2003
  • Registry error fires inside the database application block when logging tries to fire
  • Installing the enterprise library package from microsoft on the server does not fix the problem
  • Visual Studio is not installed on the server.

This was all very odd so I threw open my command window and tried to execute the InstallServices batch file (installservices.bat).  It threw an error that visual studio was not installed.  I boggled, why would you need visual studio to install the enterprise library services?  Come to find out it was just looking for a utility provided by the .NET Framework.  I leapt into action (with some help from Brenden Tompkins) and I modified the InstallServices.bat file to go right to the framework directory and grab the needed utility.

In addition, installing the enterprise library does not compile it without having visual studio installed.  The way I fixed this was to install the Enterprise Library then copy the /bin directory from another machine that I had successfully compiled the Enterprise Library on.  Then I replaced the installservices.bat file with my modified one and VOILA!  Errors gone and Easy Assets .NET works properly.

Without further ado, here is the installer script to use to get services running without visual studio, my modifications are highlighted:


@echo off
@REM  ---------------------------------------------------------------------------------
@REM  InstallServices.bat file
@REM
@REM  This batch file installs/uninstalls various services for the Enterprise Library
@REM  application blocks.
@REM 
@REM  Optional arguments for this batch file:
@REM    1 - /u to unstall. Otherwise it is installed.
@REM  ----------------------------------------------------------------------------------

echo.
echo ==========================================================================
echo   InstallServices.bat                                                   
echo      Installs/uninstalls services for the Enterprise Library 
echo ==========================================================================
echo.

set Frameworkdir=%SystemRoot%\Microsoft.NET\Framework\v1.1.4322\
set binDir="..\bin"
set pause=true

@REM  ---------------------------------------------------------------
@REM  User can override default directory containing the
@REM  the Enterprise Library assemblies by supplying
@REM  a parameter to batch file (e.g. InstallServices C:\bin).
@REM  ---------------------------------------------------------------

if "%1"=="/?" goto HELP

if "%1"=="" goto RUN

@REM  ----------------------------------------------------
@REM  If the first parameter is /q, do not pause
@REM  at the end of execution.
@REM  ----------------------------------------------------

if /i "%1"=="/q" (
 set pause=false
 SHIFT
)

@REM  ----------------------------------------------------
@REM  If the first parameter is /u, uninstall.
@REM  ----------------------------------------------------

if /i "%1"=="/u" goto RUN

goto HELP

:RUN

@REM  ------------------------------------------------
@REM  Shorten the command prompt for making the output
@REM  easier to read.
@REM  ------------------------------------------------
set savedPrompt=%prompt%
set prompt=*$g

@ECHO ----------------------------------------
@ECHO InstallServices.bat Started
@ECHO ----------------------------------------
@ECHO.

@REM -------------------------------------------------------
@REM Change to the directory where the assemblies reside
@REM -------------------------------------------------------

pushd %binDir%

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Installing Services for the Common Application Block
@ECHO -----------------------------------------------------------------
@ECHO.

if Exist Microsoft.Practices.EnterpriseLibrary.Common.dll %Frameworkdir%installutil %1 Microsoft.Practices.EnterpriseLibrary.Common.dll
@if errorlevel 1 goto :error

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Installing Services for the Caching Application Block
@ECHO -----------------------------------------------------------------
@ECHO.

if Exist Microsoft.Practices.EnterpriseLibrary.Caching.dll %Frameworkdir%installutil %1 Microsoft.Practices.EnterpriseLibrary.Caching.dll
@if errorlevel 1 goto :error

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Installing Services for the ConfigurationApplication Block
@ECHO -----------------------------------------------------------------
@ECHO.

if Exist Microsoft.Practices.EnterpriseLibrary.Configuration.dll %Frameworkdir%installutil %1 Microsoft.Practices.EnterpriseLibrary.Configuration.dll
@if errorlevel 1 goto :error

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Installing Services for the Cryptography Application Block
@ECHO -----------------------------------------------------------------
@ECHO.

if Exist Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll %Frameworkdir%installutil %1 Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
@if errorlevel 1 goto :error

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Installing Services for the Data Access Application Block
@ECHO -----------------------------------------------------------------
@ECHO.

if Exist Microsoft.Practices.EnterpriseLibrary.Data.dll %Frameworkdir%installutil %1 Microsoft.Practices.EnterpriseLibrary.Data.dll
@if errorlevel 1 goto :error

@ECHO.
@ECHO -----------------------------------------------------------------------
@ECHO Installing Services for the Exception Handling Application Block
@ECHO -----------------------------------------------------------------------
@ECHO.

if Exist Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll %Frameworkdir%installutil %1 Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
@if errorlevel 1 goto :error

@ECHO.
@ECHO ---------------------------------------------------------------------------------
@ECHO Installing Services for the Logging and Instrumentation Application Block
@ECHO ---------------------------------------------------------------------------------
@ECHO.

if Exist Microsoft.Practices.EnterpriseLibrary.Logging.dll %Frameworkdir%installutil %1 Microsoft.Practices.EnterpriseLibrary.Logging.dll
@if errorlevel 1 goto :error

@ECHO.
@ECHO -----------------------------------------------------------------
@ECHO Installing Services for the Security Application Block
@ECHO -----------------------------------------------------------------
@ECHO.

if Exist Microsoft.Practices.EnterpriseLibrary.Security.dll %Frameworkdir%installutil %1 Microsoft.Practices.EnterpriseLibrary.Security.dll
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO InstallServices.bat Completed
@ECHO ----------------------------------------
@ECHO.

@REM  ----------------------------------------
@REM  Restore the command prompt and exit
@REM  ----------------------------------------
@goto :exit

@REM  -------------------------------------------
@REM  Handle errors
@REM
@REM  Use the following after any call to exit
@REM  and return an error code when errors occur
@REM
@REM  if errorlevel 1 goto :error 
@REM  -------------------------------------------
:error
@ECHO An error occured in InstallServices.bat - %errorLevel%
if %pause%==true PAUSE
@exit errorLevel

:HELP
echo Usage: InstallServices.bat [/q] [/u]  
echo.
echo Examples:
echo.
echo    "InstallServices" - installs services for Enterprise Library assemblies      
echo    "InstallServices /u" - uninstalls services for Enterprise Library assemblies
echo    "InstallServices /q" - installs services, no pause when error occurs (quiet mode)    
echo.

@REM  ----------------------------------------
@REM  The exit label
@REM  ----------------------------------------
:exit

popd
set pause=
set binDir=
set prompt=%savedPrompt%
set savedPrompt=

echo on


I would wager that you don't need to install the enterprise library installer at all and could just xcopy the .dll's in with your project and point this script at your project's /bin directory.



Comments

Ben Miller said:

That is my experience. The IntallUtil is in the framework directory and it will run. So what you need is the dlls and the InstallServices.bat to make it easy.

I also ran the installutil.exe against the EntLib dlls directly and it worked as well.
# April 5, 2005 2:36 PM

Sanjay said:

Splendid. Copied this to ProjectName/Bin and ran it locally as admin via term services. Rebuilt the project and I was off and running.
# April 7, 2005 6:50 AM

Mike said:

I'm deploying an app which uses the caching app block. In order to run this modified install services from the application installer, won't the user installing the software need to be an administrator? If this is the case is there a workaround? Can I modify the app blocks so they don't use the perf counters or something? As it is the app log is getting filled up which stops the app working eventually.

This seems an huge oversight on MS's part!
# April 8, 2005 7:10 AM

sa said:

Thanks. Got me going after a lot of frustration. But my question is why do I have to install the Enterprise Library on the production server? Seems like I just need the dlls? Do you have any sugggestions?
Thanks again.
# May 4, 2005 12:01 PM

NSilverBullet said:

# August 11, 2005 10:32 AM

NSilverBullet said:

# August 11, 2005 10:35 AM

NSilverBullet said:

# August 11, 2005 10:36 AM

NSilverBullet said:

# August 11, 2005 10:36 AM

NSilverBullet said:

# August 11, 2005 10:38 AM

C# .Net Tales said:

I was just testing all my build scripts on our build server and hit the IIS app (created using NantContrib...
# November 27, 2005 11:33 PM

Kjetil Klaussen said:

Great! This saved my day!

Had to do some minor changes to make it work with the EntLib December Community Drop (.NET 2.0);

set Frameworkdir=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\

Other than that it all run smoothly. And yes, you we're right; there's no need to install the EntLib on the deployment server. All you need to do is set binDir to point to the location where you're EntLib dll's resides (e.g. you're websites bin directory)
# January 13, 2006 3:06 AM

zeroth said:

Thanks - i was having the similar problem and you helped provide the solution! it was so obvious that i completely missed it!
# May 8, 2006 2:26 PM

Andy said:

I don't usually post comments on bloggs.  But this tip has saved me a lot of panicking and googling.  Superb. Thank you Eric!
# May 15, 2006 9:55 AM

Khaled Riyal said:

Thanks Eric for providing the edited script,saved me a lot of time :)

# November 19, 2006 8:20 AM

AB said:

What can you do if the production server doesn't allow you to run batch scripts. Is there an alternative to get this working in a production environment ?

# April 2, 2007 9:14 AM

Rodel E. Dagumampan said:

Registration Needed.

I wonder whose idea is this. Why would I need to run a batch file or run a registry script just to make my application work. I run the service on the production server and a weird registry error pops-up. A message looks like only a rocket engineer can decrypt and fix. I browsed around and it seems a batch file was created by fellow bloggers like you master to work around the issue but yet no detailed explanation from P&P why is this so. It must be just plain simple and stupid.

or, I may have missed somthing here. :(

# May 11, 2007 12:14 AM

Rare Groove Rider said:

Errors when Deploying a .NET Application using Enterprise Library and an Unrelated Oracle Error

# March 13, 2008 3:15 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

Our Sponsors

Free Tech Publications