none
System.ServiceModel 3.0.0.0 / Performance Counter errors RRS feed

  • Question

  • We have a .NET 3.51 WCF Service hosted in IIS 7.5.  We do use custom perf counters in the service to instrument the speed of some of our operations.   Several times a day, we see the following error in the Windows Application Log.  What causes this error and how do we prevent it?

     

     A performance counter was not loaded.
     Category Name: ServiceModelEndpoint 3.0.0.0
     Counter Name: Calls
     Exception:System.InvalidOperationException: Instance 'contentdocument.contentdocument@11entserver|contentdocument.svc' already exists with a lifetime of Process.  It cannot be recreated or reused until it has been removed or until the process using it has exited.
       at System.Diagnostics.SharedPerformanceCounter.FindInstance(Int32 instanceNameHashCode, String instanceName, CategoryEntry* categoryPointer, InstanceEntry** returnInstancePointerReference, Boolean activateUnusedInstances, PerformanceCounterInstanceLifetime lifetime, Boolean& foundFreeInstance)
       at System.Diagnostics.SharedPerformanceCounter.GetCounter(String counterName, String instanceName, Boolean enableReuse, PerformanceCounterInstanceLifetime lifetime)
       at System.Diagnostics.SharedPerformanceCounter..ctor(String catName, String counterName, String instanceName, PerformanceCounterInstanceLifetime lifetime)
       at System.Diagnostics.PerformanceCounter.Initialize()
       at System.Diagnostics.PerformanceCounter.get_RawValue()
       at System.ServiceModel.Diagnostics.PerformanceCounters.GetPerformanceCounterInternal(String categoryName, String perfCounterName, String instanceName, PerformanceCounterInstanceLifetime instanceLifetime)
     Process Name: w3wp
     Process ID: 7468


    • Edited by scott_m Wednesday, May 14, 2014 10:07 PM
    Wednesday, May 14, 2014 10:06 PM

Answers

  • Hi,

    >>Exception:System.InvalidOperationException: Instance 'contentdocument.contentdocument@11entserver|contentdocument.svc' already exists with a lifetime of Process.  It cannot be recreated or reused until it has been removed or until the process using it has exited.

    In order to solve this, please try to implement a service host factory that exposes a custom service host. The custom service host will adjust the service's description which is used to build the performance counter instance name.

    From http://msdn.microsoft.com/en-us/library/aa395224.aspx .

    using System;
    using System.Diagnostics;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    
    namespace MyNamespace
    {
        public class WebFarmServiceHostFactory : 
                                       ServiceHostFactory
        {
            protected override ServiceHost CreateServiceHost(
                       Type serviceType, Uri[] baseAddresses)
            {
                return new WebFarmServiceHost(
                      serviceType, baseAddresses);
            }
        }
    
        public class WebFarmServiceHost : ServiceHost
        {
            public WebFarmServiceHost(
                Type serviceType, params Uri[] baseAddresses)
                : base(serviceType, baseAddresses) { }
    
            protected override void ApplyConfiguration()
            {
                base.ApplyConfiguration();
    
                Description.Name = "W3wp" + Process.GetCurrentProcess().Id +
                                   Description.Name;
            }
        }
    }


    And refer to the factory in your service markup:

    <%@ ServiceHost Language="C#" Debug="true"
      Factory="MyNamespace.WebFarmServiceHostFactory"
      Service="WcfService1.Service1" CodeBehind="Service1.svc.cs" %>


    This will now create a process specific instance name for your performance counters.

    For more information, please try to refer to:
    http://kleindublin.blogspot.com/2009/02/wcf-event-log-entry-servicemodelservice.html .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, May 15, 2014 5:29 AM
    Moderator

All replies

  • Hi,

    >>Exception:System.InvalidOperationException: Instance 'contentdocument.contentdocument@11entserver|contentdocument.svc' already exists with a lifetime of Process.  It cannot be recreated or reused until it has been removed or until the process using it has exited.

    In order to solve this, please try to implement a service host factory that exposes a custom service host. The custom service host will adjust the service's description which is used to build the performance counter instance name.

    From http://msdn.microsoft.com/en-us/library/aa395224.aspx .

    using System;
    using System.Diagnostics;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    
    namespace MyNamespace
    {
        public class WebFarmServiceHostFactory : 
                                       ServiceHostFactory
        {
            protected override ServiceHost CreateServiceHost(
                       Type serviceType, Uri[] baseAddresses)
            {
                return new WebFarmServiceHost(
                      serviceType, baseAddresses);
            }
        }
    
        public class WebFarmServiceHost : ServiceHost
        {
            public WebFarmServiceHost(
                Type serviceType, params Uri[] baseAddresses)
                : base(serviceType, baseAddresses) { }
    
            protected override void ApplyConfiguration()
            {
                base.ApplyConfiguration();
    
                Description.Name = "W3wp" + Process.GetCurrentProcess().Id +
                                   Description.Name;
            }
        }
    }


    And refer to the factory in your service markup:

    <%@ ServiceHost Language="C#" Debug="true"
      Factory="MyNamespace.WebFarmServiceHostFactory"
      Service="WcfService1.Service1" CodeBehind="Service1.svc.cs" %>


    This will now create a process specific instance name for your performance counters.

    For more information, please try to refer to:
    http://kleindublin.blogspot.com/2009/02/wcf-event-log-entry-servicemodelservice.html .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, May 15, 2014 5:29 AM
    Moderator
  • Hi,

    >>Exception:System.InvalidOperationException: Instance 'contentdocument.contentdocument@11entserver|contentdocument.svc' already exists with a lifetime of Process.  It cannot be recreated or reused until it has been removed or until the process using it has exited.

    In order to solve this, please try to implement a service host factory that exposes a custom service host. The custom service host will adjust the service's description which is used to build the performance counter instance name.

    From http://msdn.microsoft.com/en-us/library/aa395224.aspx .

    using System;
    using System.Diagnostics;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    
    namespace MyNamespace
    {
        public class WebFarmServiceHostFactory : 
                                       ServiceHostFactory
        {
            protected override ServiceHost CreateServiceHost(
                       Type serviceType, Uri[] baseAddresses)
            {
                return new WebFarmServiceHost(
                      serviceType, baseAddresses);
            }
        }
    
        public class WebFarmServiceHost : ServiceHost
        {
            public WebFarmServiceHost(
                Type serviceType, params Uri[] baseAddresses)
                : base(serviceType, baseAddresses) { }
    
            protected override void ApplyConfiguration()
            {
                base.ApplyConfiguration();
    
                Description.Name = "W3wp" + Process.GetCurrentProcess().Id +
                                   Description.Name;
            }
        }
    }


    And refer to the factory in your service markup:

    <%@ ServiceHost Language="C#" Debug="true"
      Factory="MyNamespace.WebFarmServiceHostFactory"
      Service="WcfService1.Service1" CodeBehind="Service1.svc.cs" %>


    This will now create a process specific instance name for your performance counters.

    For more information, please try to refer to:
    http://kleindublin.blogspot.com/2009/02/wcf-event-log-entry-servicemodelservice.html .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Hi Amy,

    It appears there may be a hot fix for this issue.  How does the hotfix differ from this solution?

    Which method is preferred?

    Hotfix link

    thanks

    Thursday, May 15, 2014 12:07 PM
  • Hi,

    The Hotfix link provides a fix for the .NET Framework 2.0, then it seems that you are not using the .Net 2.0. So please try to check the solution in my first post.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 16, 2014 2:42 AM
    Moderator