How to troubleshoot "The Commerce Server runtime has detected that more than # instances of the SiteConfigReadOnlyFreeThreaded object have been created." warning messages

Introduction

This article describes how to troubleshoot SiteConfigReadOnlyFreeThreaded event log warning messages from Microsoft Commerce Server 2007. You can use these general troubleshooting tips before you contact Microsoft Product Support Services. 

You may notice successive warnings in the web server event logs from Commerce Server such as the following:

Event Type: Warning
Event Source: Commerce Server
Event Category: None
Event ID: 4116
Date:  11/20/2007
Time:  11:32:35 AM
User:  N/A
Computer: Contoso
Description:
The Commerce Server runtime has detected that more than 101 instances of the SiteConfigReadOnlyFreeThreaded object have been created. Creating many SiteConfigReadOnlyFreeThreaded instances will negatively affect the performance of the site. Please refer to the Commerce Server documentation for the recommended use of the SiteConfigReadOnlyFreeThreaded object.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Possible Causes

CommerceDataWarehouseAuthenticationModule

The CommerceDataWarehouseAuthenticationModule HTTP module is known to cause this problem.  This module provides the correlation mechanism to track ASP.NET site visitors to profile users.   If you are not using the data warehouse resource in your site, then remove the following section from the <httpModules>section of your web application.

<add name="CommerceDataWarehouseAuthenticationModule" type="Microsoft.CommerceServer.Runtime.CommerceDataWarehouseAuthenticationModule, Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

 If you are using the data warehouse resource in your site, install Commerce Server 2007 SP1 which includes a fix for the problem.

CatalogContext, OrderContext, ProfileContext

The CatalogContext, OrderContext, and ProfileContext internally creates instances of the SiteConfigReadOnlyFreeThreaded class to determine the connection strings of the Catalog and Transactions resources respectively.  Instead of creating your instances of CatalogContext and OrderContext, reference those loaded onto CommerceContext by the Commerce HTTP modules.

CommerceContext.Current.CatalogSystem

CommerceContext.Current.OrdersSystem

CommerceContext.Current.ProfileSystem

Using Registry Switches to Troubleshoot

By default, Commerce Server logs messages for this problem after 100 SiteConfigReadOnlyFreeThreaded instances have been created.  This is value can be configured in the registry by setting the following DWORD value.

HKEY_LOCAL_MACHINE\Software\Microsoft\Commerce Server 2007\ExcessiveUseWarnLevel

So, setting this value to a lower number will help you reproduce the warnings more quickly.

Finding the source of the problem is always the most challenging.  To force the Commerce Server runtime to throw an exception once the ExcessiveUseWarnLevel value has been exceeded, set the following DWORD value to 1.

HKEY_LOCAL_MACHINE\Software\Microsoft\Commerce Server 2007\ThrowExceptionOnExcessiveUse

You will then be able to access the stack trace and determine where in your code the problem is happening.

For example...

Server Error in '/Contoso' Application.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NotSupportedException: The Commerce Server runtime has detected that more than 3 instances of the SiteConfigReadOnlyFreeThreaded object have been created.
Creating many SiteConfigReadOnlyFreeThreaded instances will negatively affect the performance of the site. Please refer to the Commerce Server documentation for the recommended use of the SiteConfigReadOnlyFreeThreaded object.
Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

 [NotSupportedException: The Commerce Server runtime has detected that more than 3 instances of the SiteConfigReadOnlyFreeThreaded object have been created.
Creating many SiteConfigReadOnlyFreeThreaded instances will negatively affect the performance of the site. Please refer to the Commerce Server documentation for the recommended use of the SiteConfigReadOnlyFreeThreaded object.
]
   Microsoft.CommerceServer.Orders.OrderServices.CreateServerImpl(OrderSiteAgent agent) +336
   Microsoft.CommerceServer.Orders.OrderManagementContext.Create(OrderSiteAgent agent) +86
   Contoso.OrderHelper.GetOrderManagementContext() in c:\Contoso\OrderHelper.cs:996
   System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs e) +104
   System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +233
   System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2603
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +59
   System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +12
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +111
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +25
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +151
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +68
   System.Web.UI.WebControls.GridView.DataBind() +4
   Contoso.Web.Controls.LineItemsControl.BindData() in c:\contoso\Controls\Orders\LineItemsControl.ascx.cs:1009
   Contoso.Web.Controls.LineItemsControl.Page_Load(Object sender, EventArgs e) in c:\contoso\Orders\LineItemsControl.ascx.cs:376
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +45
   System.Web.UI.Control.OnLoad(EventArgs e) +98
   Contoso.UI.Web.BaseUserControl.OnLoad(EventArgs e) in c:\contoso\Code\BaseUserControl.cs:31
   System.Web.UI.Control.LoadRecursive() +71
   System.Web.UI.Control.LoadRecursive() +154
   System.Web.UI.Control.LoadRecursive() +154
   System.Web.UI.Control.LoadRecursive() +154
   System.Web.UI.Control.LoadRecursive() +154
   System.Web.UI.Control.LoadRecursive() +154
   System.Web.UI.Control.LoadRecursive() +154
   System.Web.UI.Control.LoadRecursive() +154
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4268

Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832

More Information

http://msdn2.microsoft.com/en-us/library/ms963135.aspx