Quantcast
Channel: patterns & practices – Enterprise Library
Viewing all 1928 articles
Browse latest View live

New Post: Enterprise Library 6.0 in Web Service - Where to instantiate?

$
0
0
Are you running IIS in Classic Mode? If so then the standard way of performing a one time initialization at application startup is to use the Application_Start method of Global.asax. See ASP.NET Application Life Cycle Overview for IIS 5.0 and 6.0 for more information.

If you aren't running in Classic Mode, then you would need to perform a one time initialization to load the configuration before using any of the EntLib objects/methods. One way to do this would be to create a common base class that extends WebService and have that base class perform the initialization in a static (shared) constructor. So your code would look something like this:
<WebService(Namespace:="MyWebService")>
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
PublicClass MyWebServiceInterface
    Inherits MyWebService

EndClass
PublicClass MyWebService
    Inherits System.Web.Services.WebService

    SharedSubNew()

        Try' ELib 6.0Dim config As IConfigurationSource = ConfigurationSourceFactory.Create()
            Dim factory As ExceptionPolicyFactory = New ExceptionPolicyFactory(config)
            Dim logFactory As LogWriterFactory = New LogWriterFactory(config)
            Dim dbfactory As DatabaseProviderFactory = New DatabaseProviderFactory()

            Logger.SetLogWriter(logFactory.Create(), True)
            Dim exMgr As ExceptionManager = factory.CreateManager()
            ExceptionPolicy.SetExceptionManager(exMgr, True)
        Catch ex As Exception
            ' Simply Ignore' We cannot log or handle Exceptions until LogWriter and ExceptionPolicy is set up...!EndTryTry
            DatabaseFactory.SetDatabaseProviderFactory(New DatabaseProviderFactory(), True)
        Catch ex As Exception
            'Log exceptions.
            ExceptionPolicy.HandleException(ex, "Log Only Policy")
        EndTryEndSubEndClass
Finally, since you mention .NET 4.6.1, you could use some sort startup class such as owin startup or webactivatorex.

Also - do I need to add any Finalize logic for these?

No, you don't have to manage the lifetime of the EntLib objects.

New Post: Enterprise Library 6.0 in Web Service - Where to instantiate?

$
0
0
Thanks! That did the trick.

We are targeting Windows 2012 R2, so either IIS 8.5 or newer, and we do not plan to run in Classic mode.

New Post: Documentation for Logging application block configuration source schema

$
0
0
Hi Team,
Just wanted to check whether anyone has came across documentation for "Logging application block - configuration source schema". I' am looking for one similar at https://msdn.microsoft.com/en-us/library/ff650458.aspx (Retired ) for Enterprise library 6.0. I googled quite a bit but couldn't locate any.

I want to understand specifically what the different sections w.r.t Logging application block stand for in the config file, what available options are there for each section, what all predefined values are available for formater templates like {timestamp}, {message} e t c

I have seen examples from Microsoft site but what I' am looking for is exclusive documentation like the one at the above link for Enterprise library 6.0

Regards,
Ganesh

Created Unassigned: 5.0 Enterprise Library failing to log under visual studio 2015 [33861]

$
0
0
I have some code that had been working under both Visual Studio 2012, and later we upgraded the project to Visual Studio 2013 and it was still working fine. Today I tried compiling it under Visual Studio 2015, it compiled fine, no warnings or errors. But when we try to log an error, the function seems to be taking a long time and nothing is generated. Here is the configuration block:

private static void LoggingInitialization()
{
var configBuilder = new ConfigurationSourceBuilder();

configBuilder.ConfigureLogging().WithOptions
.DoNotRevertImpersonation()
.LogToCategoryNamed("Trace")
.WithOptions.SetAsDefaultCategory()
.SendTo
.FlatFile("Flatfile Trace Listener")
.FormatWith(
new FormatterBuilder()
.TextFormatterNamed("File Formatter")
.UsingTemplate("Timestamp: {timestamp}{newline}Message: {message}{newline}Log Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}Severity: {severity}{newline}Title: {title}{newline}Machine: {localMachine}{newline}App Domain: {localAppDomain}{newline}ProcessId: {localProcessId}{newline}Process Name: {localProcessName}{newline}Thread Name: {threadName}{newline}Win32 ThreadId: {win32ThreadId}{newline}Extended Properties: {dictionary({key} - {value}{newline})}")
)
.ToFile(@"c:\test.log")
.SendTo
.EventLog("Event Log Listener")
.FormatWith(
new FormatterBuilder()
.TextFormatterNamed("Text Formatter")
.UsingTemplate("Timestamp: {timestamp}{newline}Message: {message}{newline}Log Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}Severity: {severity}{newline}Title: {title}{newline}Machine: {localMachine}{newline}App Domain: {localAppDomain}{newline}ProcessId: {localProcessId}{newline}Process Name: {localProcessName}{newline}Thread Name: {threadName}{newline}Win32 ThreadId: {win32ThreadId}{newline}Extended Properties: {dictionary({key} - {value}{newline})}")
)
.ToLog("Application")
.SendTo
.Email("Email Trace Listener")
.To(Global.ErrorEmailTo)
.From(Global.ErrorEmailFrom)
.WithSubjectStart(String.Format("{0} {1} Application", Global.WorkingEnvironment, Global.ApplicationName))
.WithSubjectEnd("")
.UsingSmtpServer(Global.SMTPServer)
.UsingSmtpServerPort(Global.SMTPPort)
.Unauthenticated()
.FormatWithSharedFormatter("Text Formatter");

configBuilder.ConfigureExceptionHandling()
.GivenPolicyWithName(Global.ApplicationLayerPolicy)
.ForExceptionType<System.Exception>()
.LogToCategory("Trace")
.WithSeverity(TraceEventType.Error)
.UsingEventId(100)
.ThenNotifyRethrow();

var configSource = new DictionaryConfigurationSource();
configBuilder.UpdateConfigurationWithReplace(configSource);
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);

Normally the code is called from:
try
{
..some code here
}
catch (Exception ex)
{
ExceptionPolicy.HandleException(ex, Global.ApplicationLayerPolicy);
}

New Post: How to use static logger??? Logging Application Block

$
0
0
Sai,

I too got the same error. How did you resolve this one?

New Post: How to use static logger??? Logging Application Block

$
0
0
It sounds like you probably have a custom TraceListener or Formatter that is not overriding the CoreBuildTraceListener or BuildFormatter methods respectively (could also be a LogFilter but that seems less likely). Can you post your configuration?

New Post: Enterprise Logging 6.0 - Customise Rolling Enterprise Logging

$
0
0
Hi,

I am using Enterprise Logging 6.0 component to create logs in asp.net application, I wanted to keep the log file name based on each day logging for example -
The log file will have the name in a format like Exception_MMDDYYYY

Thanks for your help.

Pramod

New Post: VigRX Plus UK


New Post: VIMAX® Best Penis Enlargement Pills

New Post: Unable to install msmqdistributor service

$
0
0
Hi,

I am getting below error while installing msmqdistributor service:


C:\Windows\Microsoft.NET\Framework\v4.0.30319>installutil -i "D:\Software\Micros
oft\Enterprise Library\msmqdistributor.exe"


Exception occurred while initializing the installation:
System.IO.FileLoadException: Could not load file or assembly 'file:///D:\Softwar
e\Microsoft\Enterprise Library\msmqdistributor.exe' or one of its dependencies.
Operation is not supported. (Exception from HRESULT: 0x80131515).

New Post: Unable to install msmqdistributor service

$
0
0
Perhaps some of the files are "blocked"? Try right click on the files->Properties. Then click "Unblock".

Created Unassigned: Config tool fails to install [33862]

$
0
0
6/7/2016 10:55:21 AM - Microsoft VSIX Installer
6/7/2016 10:55:21 AM - -------------------------------------------
6/7/2016 10:55:21 AM - Initializing Install...
6/7/2016 10:55:21 AM - Extension Details...
6/7/2016 10:55:21 AM - Identifier : A42E118F-C41F-47A2-ADB5-04CDEBF8EB90
6/7/2016 10:55:21 AM - Name : EnterpriseLibrary.Config.v6
6/7/2016 10:55:21 AM - Author : Microsoft
6/7/2016 10:55:21 AM - Version : 6.0.1304.1
6/7/2016 10:55:21 AM - Description : Launches the Microsoft Enterprise Library v6 Configuration Console
6/7/2016 10:55:21 AM - Locale : en-US
6/7/2016 10:55:21 AM - MoreInfoURL :
6/7/2016 10:55:21 AM - InstalledByMSI : False
6/7/2016 10:55:21 AM - SupportedFrameworkVersionRange : [4.5]
6/7/2016 10:55:21 AM -
6/7/2016 10:55:21 AM - SignedBy : Microsoft Corporation
6/7/2016 10:55:21 AM - Certificate Info : [Subject]
CN=Microsoft Corporation, OU=MOPR, OU=OPC, O=Microsoft Corporation, L=Redmond, S=Washington, C=US

[Issuer]
CN=Microsoft Code Signing PCA, O=Microsoft Corporation, L=Redmond, S=Washington, C=US

[Serial Number]
33000000B2E6906F8BE7453D5B0001000000B2

[Not Before]
1/24/2013 2:33:41 PM

[Not After]
4/24/2014 3:33:41 PM

[Thumbprint]
E4EEC5DFB7F413E5A15191DA00D017F97E3A6260

6/7/2016 10:55:21 AM - Supported Products :
6/7/2016 10:55:21 AM - Microsoft.VisualStudio.Ultimate
6/7/2016 10:55:21 AM - Version : [11.0]
6/7/2016 10:55:21 AM - Microsoft.VisualStudio.Premium
6/7/2016 10:55:21 AM - Version : [11.0]
6/7/2016 10:55:21 AM - Microsoft.VisualStudio.Pro
6/7/2016 10:55:21 AM - Version : [11.0]
6/7/2016 10:55:21 AM -
6/7/2016 10:55:21 AM - References :
6/7/2016 10:55:21 AM - -------------------------------------------------------
6/7/2016 10:55:21 AM - Identifier : Microsoft.VisualStudio.MPF
6/7/2016 10:55:21 AM - Name : Visual Studio MPF
6/7/2016 10:55:21 AM - Version : 10.0
6/7/2016 10:55:21 AM - MoreInfoURL :
6/7/2016 10:55:21 AM - Nested : No
6/7/2016 10:55:21 AM -
6/7/2016 10:55:21 AM -
6/7/2016 10:55:21 AM - Searching for applicable products...
6/7/2016 10:55:21 AM - Found installed product - Microsoft Visual Studio 2010 Premium
6/7/2016 10:55:21 AM - Found installed product - Microsoft Visual Studio Premium 2012
6/7/2016 10:55:24 AM - The extension with ID 'A42E118F-C41F-47A2-ADB5-04CDEBF8EB90' is not installed to Microsoft Visual Studio Premium 2012.
6/7/2016 10:55:24 AM - Found installed product - Microsoft Visual Studio Professional 2012
6/7/2016 10:55:24 AM - Found installed product - Microsoft LightSwitch for Visual Studio 2012
6/7/2016 10:55:24 AM - Found installed product - Microsoft Visual Studio 2012 Shell (Integrated)
6/7/2016 10:55:24 AM - Found installed product - Global Location
6/7/2016 10:55:27 AM - The following target products have been selected...
6/7/2016 10:55:27 AM - Microsoft Visual Studio Premium 2012
6/7/2016 10:55:27 AM -
6/7/2016 10:55:28 AM - Beginning to install extension to Microsoft Visual Studio Premium 2012...
6/7/2016 10:55:28 AM - Install Error : Microsoft.VisualStudio.ExtensionManager.MissingTargetFrameworkException: The extension 'EnterpriseLibrary.Config.v6' requires a version of the .NET Framework that is not installed.
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.CheckForValidDotNetFramework(IExtension extension)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.CheckForInstallBlockers(InstallableExtensionImpl extension, IInstalledExtensionList modifiedInstalledExtensionsList, Boolean isNestedExtension, Boolean& olderVersionInstalled)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.InstallInternal(InstallableExtensionImpl extension, Boolean perMachine, Boolean isNestedExtension, IDictionary`2 extensionsInstalledSoFar, List`1 extensionsUninstalledSoFar, IInstalledExtensionList modifiedInstalledExtensionsList, AsyncOperation asyncOp, UInt64 totalBytesToWrite, UInt64& totalBytesWritten)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.BeginInstall(IInstallableExtension installableExtension, Boolean perMachine, AsyncOperation asyncOp)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.InstallWorker(IInstallableExtension extension, Boolean perMachine, AsyncOperation asyncOp)

Edited Unassigned: Config tool fails to install [33862]

$
0
0
As shown in the attached screen shot, I have the multi-target pack of the .NET FW 4.5 installed, yet the EL config installer still fails. Is it failing because it doesn't recognize the mult-target pack? The multi-target pack is pushed out by the IT dept, I have little control over it. Any thoughts are appreciated. Thank you.


here's the log

6/7/2016 10:55:21 AM - Microsoft VSIX Installer
6/7/2016 10:55:21 AM - -------------------------------------------
6/7/2016 10:55:21 AM - Initializing Install...
6/7/2016 10:55:21 AM - Extension Details...
6/7/2016 10:55:21 AM - Identifier : A42E118F-C41F-47A2-ADB5-04CDEBF8EB90
6/7/2016 10:55:21 AM - Name : EnterpriseLibrary.Config.v6
6/7/2016 10:55:21 AM - Author : Microsoft
6/7/2016 10:55:21 AM - Version : 6.0.1304.1
6/7/2016 10:55:21 AM - Description : Launches the Microsoft Enterprise Library v6 Configuration Console
6/7/2016 10:55:21 AM - Locale : en-US
6/7/2016 10:55:21 AM - MoreInfoURL :
6/7/2016 10:55:21 AM - InstalledByMSI : False
6/7/2016 10:55:21 AM - SupportedFrameworkVersionRange : [4.5]
6/7/2016 10:55:21 AM -
6/7/2016 10:55:21 AM - SignedBy : Microsoft Corporation
6/7/2016 10:55:21 AM - Certificate Info : [Subject]
CN=Microsoft Corporation, OU=MOPR, OU=OPC, O=Microsoft Corporation, L=Redmond, S=Washington, C=US

[Issuer]
CN=Microsoft Code Signing PCA, O=Microsoft Corporation, L=Redmond, S=Washington, C=US

[Serial Number]
33000000B2E6906F8BE7453D5B0001000000B2

[Not Before]
1/24/2013 2:33:41 PM

[Not After]
4/24/2014 3:33:41 PM

[Thumbprint]
E4EEC5DFB7F413E5A15191DA00D017F97E3A6260

6/7/2016 10:55:21 AM - Supported Products :
6/7/2016 10:55:21 AM - Microsoft.VisualStudio.Ultimate
6/7/2016 10:55:21 AM - Version : [11.0]
6/7/2016 10:55:21 AM - Microsoft.VisualStudio.Premium
6/7/2016 10:55:21 AM - Version : [11.0]
6/7/2016 10:55:21 AM - Microsoft.VisualStudio.Pro
6/7/2016 10:55:21 AM - Version : [11.0]
6/7/2016 10:55:21 AM -
6/7/2016 10:55:21 AM - References :
6/7/2016 10:55:21 AM - -------------------------------------------------------
6/7/2016 10:55:21 AM - Identifier : Microsoft.VisualStudio.MPF
6/7/2016 10:55:21 AM - Name : Visual Studio MPF
6/7/2016 10:55:21 AM - Version : 10.0
6/7/2016 10:55:21 AM - MoreInfoURL :
6/7/2016 10:55:21 AM - Nested : No
6/7/2016 10:55:21 AM -
6/7/2016 10:55:21 AM -
6/7/2016 10:55:21 AM - Searching for applicable products...
6/7/2016 10:55:21 AM - Found installed product - Microsoft Visual Studio 2010 Premium
6/7/2016 10:55:21 AM - Found installed product - Microsoft Visual Studio Premium 2012
6/7/2016 10:55:24 AM - The extension with ID 'A42E118F-C41F-47A2-ADB5-04CDEBF8EB90' is not installed to Microsoft Visual Studio Premium 2012.
6/7/2016 10:55:24 AM - Found installed product - Microsoft Visual Studio Professional 2012
6/7/2016 10:55:24 AM - Found installed product - Microsoft LightSwitch for Visual Studio 2012
6/7/2016 10:55:24 AM - Found installed product - Microsoft Visual Studio 2012 Shell (Integrated)
6/7/2016 10:55:24 AM - Found installed product - Global Location
6/7/2016 10:55:27 AM - The following target products have been selected...
6/7/2016 10:55:27 AM - Microsoft Visual Studio Premium 2012
6/7/2016 10:55:27 AM -
6/7/2016 10:55:28 AM - Beginning to install extension to Microsoft Visual Studio Premium 2012...
6/7/2016 10:55:28 AM - Install Error : Microsoft.VisualStudio.ExtensionManager.MissingTargetFrameworkException: The extension 'EnterpriseLibrary.Config.v6' requires a version of the .NET Framework that is not installed.
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.CheckForValidDotNetFramework(IExtension extension)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.CheckForInstallBlockers(InstallableExtensionImpl extension, IInstalledExtensionList modifiedInstalledExtensionsList, Boolean isNestedExtension, Boolean& olderVersionInstalled)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.InstallInternal(InstallableExtensionImpl extension, Boolean perMachine, Boolean isNestedExtension, IDictionary`2 extensionsInstalledSoFar, List`1 extensionsUninstalledSoFar, IInstalledExtensionList modifiedInstalledExtensionsList, AsyncOperation asyncOp, UInt64 totalBytesToWrite, UInt64& totalBytesWritten)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.BeginInstall(IInstallableExtension installableExtension, Boolean perMachine, AsyncOperation asyncOp)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.InstallWorker(IInstallableExtension extension, Boolean perMachine, AsyncOperation asyncOp)

Reviewed: Enterprise Library 6 - April 2013 (七月 25, 2016)

$
0
0
Rated 4 Stars (out of 5) - try downloading

New Post: Feature Request - Have less generic exception (not InvalidOperationException) when LogWriter is set OR not set

$
0
0
(Apologies if this is the wrong place)

I recently updated my codebase from version 4 to 6 and this impacted the way my DR container resolves the logging library.

I either get:
The LogWriter has not been set for the Logger static class. Set it invoking the Logger.SetLogWriter method.
OR
The LogWriter is already set.
In both cases, an InvalidOperationException is thrown.

So I would like to request the addition of specific exceptions:

LogWriterNotSetException and LogWriterAlreadySetException

And/Or

The addition of a boolean flag (LogWriterIsSet) to indicate if it is set or not

Created Unassigned: Feature Request - Have less generic exception (not InvalidOperationException) when LogWriter is set OR not set [33863]

$
0
0
(Apologies if this is the wrong place)

I recently updated my codebase from version 4 to 6 and this impacted the way my DR container resolves the logging library.

I either get:

> The LogWriter has not been set for the Logger static class. Set it invoking the Logger.SetLogWriter method.

OR

> The LogWriter is already set.




In both cases, an __InvalidOperationException__ is thrown.

So I would like to request the addition of specific exceptions:

__LogWriterNotSetException__ and __LogWriterAlreadySetException__

And/Or

The addition of a boolean flag (__LogWriterIsSet__) to indicate if it is set or not

New Post: Enterprise Library

$
0
0
I have used the Enterprise Library 5.0 to create the daily log file. The log is created but its writing log in two files instead of one file.

Here is name of first file name: Policy.txt

Second file name: 28afdf13-db29-453c-8a85-2684e9895353Policy.txt

The log file is not rolling instead its creating new file.

Here is log configuration.

<add name="Policy Flat File" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" fileName="C:\LOGS\Policy.txt" header="" footer="" formatter="MAO-Privacy-Policy" rollFileExistsBehavior="Increment" rollInterval="Midnight" timeStampPattern="yyyy-MM-dd" rollSizeKB="10000" maxArchivedFiles="30" />

Please help to fix this issue.

-Ashish

New Post: Enterprise Library 4.1 error

$
0
0
When I try to run a WCF method an exception is raised and throws the below error.

The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, ExceptionHandlePolicy]) failed: The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' cannot be resolved. Please verify the spelling is correct or that the full type name is provided. (Strategy type ConfiguredObjectStrategy, index 2)

I cannot upgrade to the latest version of MS EL 6.0 because our project heavily uses Composite Web which is obsolete now.

Is there any way to resolve this issue

Created Unassigned: UnityContainer Pipeline Behavior when using Interception [33864]

$
0
0
Our recent application deployed to production is facing performance issue and users are revoked access because of the same. It’s observed that application response time is degrading quite often and sometime IIS application is crashing as well. Microsoft has provided an analysis to indicate that our application Service code has looping issue while using unity container framework.


We are facing issue related to Enterprise Library Unity Container. We maintain an application cache on our application server side for some entities (5 business entities). We have used unity container interception feature to intercept calls in our façade layer (data provider layer in application server) to decide whether the required entity exists in the cache or not. It has been observed in MS dump utility trace and in our application logs, that a huge number of calls are made to our CacheHandler that is configured with Unity framework for cached entities. This is causing stack overflow issue on the server and memory usage is growing as well very rapidly. This is resulting our IIS app(application service layer) to respond very slow or sometime even crashing the IIS app (w3wp.exe) completely.

After a code analysis and debugging it has been found out that we use httpmodule which is using a unity container instance. Httpmodule is used to handle “PostMapRquest” http pipeline event. In this event handler we create a new extension to the unity container each time a call made to the server. In the new extension we also do register our provider instances for interception along with the interceptor. On the cachehandler whenever we check for the entity we call the following method for going ahead with the next pipeline behavior

// Call the original method
result = getNext()(input, getNext);

As per our understanding the call above triggers the Unity pipeline and invokes each extension and behaviors underneath. This is causing more calls to our Cachehandler than expected. As the HttpModule lives as long as the IIS application lives , unity container is growing big whenever each call is made.

Solution:
We will not keep the instance of UnityContainer once the service call is executed. For each call we will instantiate a new unity container and just before the Post Map request event handler ends we will remove all extensions from the unity container and dispose the container.

// Clear all the extensions when application context is created.
this.unityContainer.RemoveAllExtensions();
this.unityContainer.Dispose();

We will also modify the code to restrict registering only one type of provider to UnityContainer for one time only. This will reduce the no of providers underneath and will reduce the cachehandler call within a single flow. We will follow Unity Config file to do the registration to avoid multiple registration. Please let us know your recommendation and let us also know if we are correct on our analysis.

Commented Unassigned: UnityContainer Pipeline Behavior when using Interception [33864]

$
0
0
Our recent application deployed to production is facing performance issue and users are revoked access because of the same. It’s observed that application response time is degrading quite often and sometime IIS application is crashing as well. Microsoft has provided an analysis to indicate that our application Service code has looping issue while using unity container framework.


We are facing issue related to Enterprise Library Unity Container. We maintain an application cache on our application server side for some entities (5 business entities). We have used unity container interception feature to intercept calls in our façade layer (data provider layer in application server) to decide whether the required entity exists in the cache or not. It has been observed in MS dump utility trace and in our application logs, that a huge number of calls are made to our CacheHandler that is configured with Unity framework for cached entities. This is causing stack overflow issue on the server and memory usage is growing as well very rapidly. This is resulting our IIS app(application service layer) to respond very slow or sometime even crashing the IIS app (w3wp.exe) completely.

After a code analysis and debugging it has been found out that we use httpmodule which is using a unity container instance. Httpmodule is used to handle “PostMapRquest” http pipeline event. In this event handler we create a new extension to the unity container each time a call made to the server. In the new extension we also do register our provider instances for interception along with the interceptor. On the cachehandler whenever we check for the entity we call the following method for going ahead with the next pipeline behavior

// Call the original method
result = getNext()(input, getNext);

As per our understanding the call above triggers the Unity pipeline and invokes each extension and behaviors underneath. This is causing more calls to our Cachehandler than expected. As the HttpModule lives as long as the IIS application lives , unity container is growing big whenever each call is made.

Solution:
We will not keep the instance of UnityContainer once the service call is executed. For each call we will instantiate a new unity container and just before the Post Map request event handler ends we will remove all extensions from the unity container and dispose the container.

// Clear all the extensions when application context is created.
this.unityContainer.RemoveAllExtensions();
this.unityContainer.Dispose();

We will also modify the code to restrict registering only one type of provider to UnityContainer for one time only. This will reduce the no of providers underneath and will reduce the cachehandler call within a single flow. We will follow Unity Config file to do the registration to avoid multiple registration. Please let us know your recommendation and let us also know if we are correct on our analysis.

Comments: Hi, The Unity project has been moved to github so you should probably post your issue there: https://github.com/unitycontainer/unity/issues . A scaled down repro of the issue might help as well. However, here are some of my thoughts. From your description the one thing that stands out to me is: # > In this event handler we create a new extension to the unity container each time a call made to the server. # This seems like a very atypical usage. Usually, a container extension is added once at container creation time. Given that if you use one container and extension per request (and dispose at the end of the request) then everything is OK, it seems to me, without looking at any code, that multiple container extension registrations might be causing some issues (e.g multiple registrations or circular references). I'm going to guess that the reason you register an extension per request is that you need to populate (and use) per request information (or at least lifetime) in the extension and perhaps the instantiated objects themselves. One typical approach to deal with that is to create a child container on every request. The process is similar to what you are doing but should be more efficient: * On application start create the UnityContainer and register any "common" registrations (e.g. true singletons) * When a request comes in call container.CreateChildContainer() and register your extension * Resolve all objects from the child container * Dispose the child container at the end of the request
Viewing all 1928 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>