Enterprise Library Install Services without Visual Studio

Fecha: 25/Jul/2005 (20 de Julio de 2005)
Autor: Bruno Capuano; bcapuano@gmail.com

 


Introducción

Cuando empezamos a trabajar con Enterprise Library, una de las excepciones mas comunes con las que nos encontramos, se da cuando desde una aplicación Asp.Net o Windows se quiere utilizar algun componente de Enterprise Library que deja una traza en WMI o utiliza algún contador de perfomance. Por lo gral, la excepcion es del tipo Access Denied, como muestro a continuación.


Error de servidor en la aplicación '/Aplicacion/Demo_Web'.

Excepción de seguridad

Descripción: La aplicación intentó realizar una operación no permitida por la directiva de seguridad. Para otorgar a esta aplicación los permisos necesarios, póngase en contacto con el administrador del sistema o

cambie el nivel de confianza de la aplicación en el archivo de configuración.

Detalles de la excepción: System.Security.SecurityException: Acceso denegado al Registro solicitado.

Error de código fuente:

Se ha generado una excepción no controlada durante la ejecución de la solicitud Web actual. La información sobre el origen y la ubicación

de la excepción pueden identificarse utilizando la excepción del seguimiento de la pila siguiente.



Seguimiento de la pila:


 [SecurityException: Acceso denegado al Registro solicitado.]
   Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) +473
   System.Diagnostics.EventLog.CreateEventSource(String source, String logName, String machineName, Boolean useMutex) +443
   System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) +347
   System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category) +21
   System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID) +15
   System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type) +11
   Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.PerformanceCounterInstances.ReportCounterFailure(String message)
   Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.PerformanceCounterInstances..ctor(String categoryName, String counterName,
    Boolean createNewInstance)
   Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.InstrumentedEvent.AddPerformanceCounter(String category, String[] counterNames,
    Boolean createNewInstance)
   Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.InstrumentedEvent.Initialize(String counterCategory, String[] counterNames,
    Boolean createNewInstance, String eventLogSource, EventLogIdentifier[] eventIds)
   Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.InstrumentedEvent..ctor(String counterCategory, String[] counterNames,
    Boolean createNewInstance)
   Microsoft.Practices.EnterpriseLibrary.Caching.Instrumentation.CachingServiceItemTurnoverEvent..ctor(String[] counterNames)
   Microsoft.Practices.EnterpriseLibrary.Caching.Instrumentation.CachingServiceItemTurnoverEvent..cctor()

  Información de versión: Versión de Microsoft .NET Framework:1.1.4322.2032; Versión de ASP.NET:1.1.4322.2032

 


Solución

La solución para este problema es inicializar los contadores y demás objetos que utiliza Enterprise Library, lanzando el Bat InstallServices.Bat.

El mismo, suele estar en ..\Program Files\Microsoft Enterprise Library June 2005\src\InstallServices.bat.

Sin embargo, si miramos el contenido de este archivo bat, nos encontramos con la siguiente siguiente linea

set visualStudioDir=C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\

La misma nos indica que utiliza Visual Studio para la compilación y distribución de los componentes de traza de Enterprise Library. Si queremos utilizar este Bat en un server de producción, tendremos un problema (asumiendo que ningun server de producción tiene el Visual Studio instalado .. :D)

La solucion a este problema es simplemente comentar esta linea y cambiarla por la del path de instalacion de .Net, como muestro a continuación:

@REM set visualStudioDir=C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\

set visualStudioDir=%SystemRoot%\Microsoft.NET\Framework\v1.1.4322

Obviamente %SystemRoot%, esta en el path local del server y apunta por ejemplo, a C:\WINDOWS\.

Si quieren el bat completo y cambiado, lo pueden descargar desde aquí . Sino tambien lo adjunto completo al final del artículo.

Ante cualquier duda, pueden escribirme a  bcapuano@gmail.com

Saludos

El Bruno

http://spaces.msn.com/members/brunocapuano.


DeployServices.bat

@echo off

@REM  ---------------------------------------------------------------------------------

@REM  DeployServices.bat file

@REM

@REM  This batch file installs/uninstalls various services for the Enterprise Library

@REM  application blocks.

@REM

@REM   - Copy the Enterprise Library \bin folder to a folder on

@REM            the server where you want to deploy (i.e. C:\entlib)

@REM   - Copy this batch file into the same folder (required)

@REM   - Run the batch file from the server's console or a terminal session.

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

@REM set visualStudioDir=C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\

set visualStudioDir=%SystemRoot%\Microsoft.NET\Framework\v1.1.4322

@REM 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  Register VS.NET environment variables

@REM  (required to call installutil)

@REM  ----------------------------------------

@REM if not Exist "%visualStudioDir%..\Tools\vsvars32.bat" goto HELPVS

@REM @call "%visualStudioDir%..\Tools\vsvars32.bat"

@REM -------------------------------------------------------

@REM Change to the directory where the assemblies reside

@REM -------------------------------------------------------

@REM pushd %binDir%

@ECHO.

@ECHO -----------------------------------------------------------------

@ECHO Installing Services for the Common Application Block

@ECHO -----------------------------------------------------------------

@ECHO.

if Exist Microsoft.Practices.EnterpriseLibrary.Common.dll %visualStudioDir%\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 %visualStudioDir%\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 %visualStudioDir%\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 %visualStudioDir%\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 %visualStudioDir%\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 %visualStudioDir%\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 %visualStudioDir%\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 %visualStudioDir%\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  ----------------------------------------

if %pause%==true PAUSE

@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

:HELPVS

echo Error: Unable to locate Visual Studio.NET

echo.

echo InstallServices.bat assumes Visual Studio.NET 2003 has been installed in its default location

echo ("%visualStudioDir%".)

echo.

echo If you have installed Visual Studio.NET 2003 to a different location, you will need

echo to update this batch file to reflect that location.

echo.

goto exit

: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


ir al índice