locked
Having Enterprise Library 5.0 use app.config RRS feed

  • Question

  • User1191616196 posted

    Hi,

    I have a Solution which contains a Web project and a Class Library project. The Class library project contains Enterprise library 5.0 and app.config. When I try to perform a Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write, I get the following exception:

     

    Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", name = "(none)". Exception occurred while: while resolving. Exception is: InvalidOperationException - The type LogWriter cannot be constructed. You must configure the container to supply this value. ----------------------------------------------- At the time of the exception, the container was: Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)

     

    If I move all the class files to the web project and have the Enterprise library configuration in the Web.config, everything works fine. I guess the issue is that the Enterprise library is not detecting the app.config which contains all the configuration. How can I have my enterprise library use the App.config present in its prroject.

     

    Kindly help me with this regard.

    Thanks in advance.

    Friday, November 19, 2010 12:04 AM

Answers

All replies

  • User-837620913 posted

    You need to add a few settings in the web.config to point to an external (non web.config) config file:

    http://www.pnpguidance.net/Post/EnterpriseLibraryExternalConfigurationSourceApplicationBlockSettings.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 19, 2010 5:43 AM
  • User452079492 posted

    hi,
    I have the same problem experienced by Frenz:

    Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", name = "(none)". Exception occurred while: while resolving. Exception is: InvalidOperationException - The type LogWriter cannot be constructed. You must configure the container to supply this value. ----------------------------------------------- At the time of the exception, the container was: Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)


    I read the configuration file using the following code:


                Dim container As New UnityContainer
                Dim configurator = New UnityContainerConfigurator(container)
                ' Read the configuration files and set up the container.
                EnterpriseLibraryContainer.ConfigureContainer(configurator, New FileConfigurationSource("file.config"))
                _LogWriter = container.Resolve(Of LogWriter)()
                ' add custom listener to logWriter
                If IsLogging Then

                    Dim collList As New List(Of TraceListener)
                    Dim dbTraceList As TraceListener = Nothing
                    Dim dblogSource As LogSource = Nothing

                    dbTraceList = New SIALogListener(_connLog, _databaseLog)
                    collList.Add(dbTraceList)
                    dblogSource = New LogSource("CustomDBLog", collList, SourceLevels.All)
                    dblogSource.AutoFlush = True
                    _LogWriter.TraceSources("General").Listeners.Add(dbTraceList)

                End If

    to avoid connecting to the app or web.config file

    The library works perfectly. NET but loading it from VB6 COM interop mode is evident in the error that I write.

    Can you help or suggest possible solutions?
    What seems strange to me is that the dll in a VS2010 function perfectly and highlights the problem only in the VB6

    Thanks
    Regards

    Tuesday, January 4, 2011 4:36 AM