Error configuring Session State Provider in web.config

Jul 10, 2008 at 12:36 AM
I am trying to test the Session State functionality of Memcached and keep getting this error when I run my site:

Parser Error Message: Exception has been thrown by the target of an invocation. (Line 83)

Source Error:

Line 81: <sessionState cookieless="false" regenerateExpiredSessionId="true" mode="Custom" customProvider="MemcachedSessionProvider">
Line 82: <providers>
Line 83: <add name="MemcachedSessionProvider" type="MemcachedProviders.Session.SessionStateProvider,MemcachedProviders"
Line 84: connectionStringName="SqlSessionServices" dbType="SQL" writeExceptionsToEventLog="false"/>
Line 85: </providers>
Coordinator
Jul 10, 2008 at 3:16 PM
If you have downloaded the source code with performance counters . go this file c:\windows\microsoft.net\framework\v2.0.50727\config\machine.config
change to the following tag
<processModel userName="SYSTEM" password="AutoGenerate"/>

If you are using version 1.2 your configuration looks ok. Did you setup the enyims section to provide memcached servers? If that is missing it will throw exception.
Jul 11, 2008 at 2:02 AM
Thanks for the reply fahadaz.  I updated the machine.config file but still no luck.  I did setup the enyim's section as follows:

  <enyim.com>
    <memcached>
      <servers>
        <add address="127.0.0.1" port="11211" />
      </servers>
      <socketPool minPoolsize="10" maxPoolsize="100" connectionTimeout="00:00:10" deadTimeout="00:02:00" />
    </memcached>
  </enyim.com>
Also, I verified the memcached service is running on the server (testing on one server for now).  I am using Memcached Provider 1.2 for .NET 2.0 along with memcached 1.2.1-win32 (downloaded from jehiah.cz\projects\...).  I am using VS 2008 to create the test ASP.NET Web app.  I assume this is all I need to get going.

I am basically following the instruction on the documentation "Using Memcached Session State Provider".  It makes sense except in the document is refers to an Enyim.Cache.dll and the actual file is Enyim.Caching.dll.  I assume this is fine and it was just overlooked in the documentation.  Do I need to install libevent?  I will keep troubleshooting but any further suggestions will be greatly appreciated.  Thanks.
Coordinator
Jul 11, 2008 at 3:51 AM
Sometimes windows firewall can block access to the memcached service. You can use the following steps to check if you can successfully connect to memcached service.

1. Start comand prompt
2. type :>telnet 127.0.0.1 11211
3. type :>stats 
    This should return memcached stats. If this fails, the firewall or something else is blocking access to memcached.

If problem persists, you can email me ur test project at the following address "fahadaz at gmail.com". I can try to debug it to see what is not working.

- Fahad
Jul 20, 2008 at 2:31 PM
Hi fahadaz,

I'm running into the same error - Exception has been thrown by the target of an invocation.

Line 55: 			<providers>
Line 56: 				<add name="MemcachedSessionProvider" 
Line 57: type="MemcachedProviders.Session.SessionStateProvider, MemcachedProviders"Line 58: 				dbType="None" writeExceptionsToEventLog="false"/>
Line 59: 			</providers


Running Memcached Providers 1.2 (asp.net 2), with memcached 1.2.1. I can telnet to memcached server and return stats.
Web Config as follows:

<configSections>
<section name="cacheProvider" type="MemcachedProviders.Cache.CacheProviderSection, MemcachedProviders"
     allowDefinition="MachineToApplication" restartOnExternalChanges="true"/>
  <sectionGroup name="enyim.com">
   <section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching" />
  </sectionGroup>
  <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>

 <sessionState cookieless="false" regenerateExpiredSessionId="true" mode="Custom" customProvider="MemcachedSessionProvider">
   <providers>
    <add name="MemcachedSessionProvider"
     type="MemcachedProviders.Session.SessionStateProvider, MemcachedProviders"
    dbType="None" writeExceptionsToEventLog="false"/>
   </providers>
  </sessionState>

<enyim.com>
  <memcached>
   <servers>
    <add address="127.0.0.1" port="11211" />
   </servers>
   <socketPool minPoolSize="10" maxPoolSize="100"
   connectionTimeout="00:00:10" deadTimeout="00:02:00" />
  </memcached>
 </enyim.com>
 <cacheProvider defaultProvider="MemcachedCacheProvider">
  <providers>
   <add name="MemcachedCacheProvider"
   type="MemcachedProviders.Cache.MemcachedCacheProvider, MemcachedProviders"
   keySuffix="_MySuffix_" defaultExpireTime="2000"/>
  </providers>
 </cacheProvider>  
 <log4net>
  <!-- Define some output appenders -->
  <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
   <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}]
- %message%newline" />
   </layout>
  </appender>
  <!--<threshold value="OFF" />-->
  <!-- Setup the root category, add the appenders and set the default priority -->
  <root>
   <priority value="WARN"/>
   <appender-ref ref="ConsoleAppender">
    <filter type="log4net.Filter.LevelRangeFilter">
     <levelMin value="WARN"/>
     <levelMax value="FATAL"/>
    </filter>
   </appender-ref>
  </root>
 </log4net>

Any pointers would be great - thanks.
Coordinator
Jul 21, 2008 at 2:37 AM
In enyim.com's section, you have set the connectionTimeout="00:00:10" (10 seconds). This is very small. Sample config suggests 10 minutes.
Try using connectionTimeout="00:10:00".
- Fahad
Jul 21, 2008 at 9:59 AM
Hi fahadaz,

Thanks for you quick response. I have changed the timeout setting but I'm still seeing this exception.

Exception has been thrown by the target of an invocation.

It is failing on this line - 
type="MemcachedProviders.Session.SessionStateProvider, MemcachedProviders" 

I'll start to debug this end.
Jul 21, 2008 at 12:23 PM
I have now resolved this. I was using an older version of Enyim.Caching.dll.

Thanks for your help.
Nov 21, 2008 at 4:34 AM
I get the same error, I try any solution but I can't resolve it.

Anyone help me?

Thanks
Coordinator
Nov 21, 2008 at 3:37 PM
Edited Nov 21, 2008 at 3:47 PM
Can u check if the performance counters are created. This happends when ur running the application while the performance are not created. This happends because ASP.net
don't have access to modify registry but can read from it.

Thanks,
Fahad
Nov 24, 2008 at 1:49 PM

nminhkha,

Believe it or not,, my error was resolved after correcting the case type of a keyword in the web.config file. In other words, my setup was correct but I had a lower case 's' instead of an upper case 'S' in words minPoolSize and maxPoolSize.

<enyim.com>
<memcached>
<servers>
<add address="127.0.0.1" port="11211" />
<add address="10.202.146.149" port="11211" />
</servers>
<socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:00:10" deadTimeout="00:02:00" />
</memcached>
</enyim.com>

Barring any other setup issues, keep in mind it is case-sensitive.

Regards,

Raul

NOTICE TO RECIPIENT: If you are not the intended recipient of this e-mail, you are prohibited from sharing, copying, or otherwise using or disclosing its contents. If you have received this e-mail in error, please notify the sender immediately by reply e-mail and permanently delete this e-mail and any attachments without reading, forwarding or saving them. Thank you.
Nov 24, 2008 at 3:33 PM
Thank all for reply.
I had resolved it.

I download source and rebuild. It run very good.

Thank :)
Jul 27, 2011 at 12:55 PM


Configuration Error

 

 

Line 38:   </enyim.com>
Line 39:   
Line 40:   <cacheProvider defaultProvider="MemcachedProvider">
Line 41:     <providers>
Line 42:       <add name="MemcachedProvider" type="MemcachedProviders.Cache.MemcachedProvider, MemcachedProviders" keySuffix="_MySuffix_" defaultExpireTime="2000"/>

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.  This error can be caused by a virtual directory not being configured as an application in IIS.

my Web.Config file is as

<?xml version="1.0"?>
<configuration>
  <configSections > 
  <section name="cacheProvider" type="MemcachedProviders.Cache.CacheProviderSection, MemcachedProviders" allowDefinition="MachineToApplication" restartOnExternalChanges="true"/>
  <sectionGroup name="enyim.com">
    <section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching" />
  </sectionGroup>
  <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
  </configSections>
  <log4net>
    <!-- Define some output appenders -->
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}]- %message%newline" />
      </layout>
    </appender>
    <!--<threshold value="OFF" />-->
    <!-- Setup the root category, add the appenders and set the default priority -->
    <root>
      <priority value="WARN"/>
      <appender-ref ref="ConsoleAppender">
        <filter type="log4net.Filter.LevelRangeFilter">
          <levelMin value="WARN"/>
          <levelMax value="FATAL"/>
        </filter>
      </appender-ref>
    </root>
  </log4net>
  <enyim.com>
    <memcached>
      <servers>
        <!-- put your own server(s) here-->
        <add address="192.168.5.67" port="11211" />
      </servers>
      <socketPool minPoolSize="10" maxPoolSize="100"
      connectionTimeout="00:00:10" deadTimeout="00:02:00" />
    </memcached>
  </enyim.com>
  
  <cacheProvider defaultProvider="MemcachedProvider">
    <providers>
      <add name="MemcachedProvider" type="MemcachedProviders.Cache.MemcachedProvider, MemcachedProviders" keySuffix="_MySuffix_" defaultExpireTime="2000"/>
    </providers>
  </cacheProvider>
  <location path="Register.aspx">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>

  <system.web>
    <authorization>
      <deny users="?"/>
    </authorization>
  </system.web>

</configuration>