TypeInitializationException was unhandled

Topics: Developer Forum, User Forum
Aug 3, 2009 at 1:55 AM

I am testing SharedCache by writing a very simple client application. The server is up and running on another machine.

On the client I get an exception at this line:
"return IndexusDistributionCache.SharedCache.Get<T>(key);"

The exception is: The type initializer for 'SharedCache.WinServiceCommon.Provider.Cache.IndexusDistributionCache' threw an exception.

InnerException Message: {"Object reference not set to an instance of an object."}
InnerException Source: "SharedCache.WinServiceCommon"
InnerException Data: {System.Collections.ListDictionaryInternal}
InnerException Stack Trace:    at SharedCache.WinServiceCommon.Provider.Cache.IndexusDistributionCache.LoadProvider() in E:\Lib - All\Lib - SharedCache\SharedCache_Sources_Release_3.0.5.1\SharedCache.WinServiceCommon\Provider\Cache\IndexusDistributionCache.cs:line 174
   at SharedCache.WinServiceCommon.Provider.Cache.IndexusDistributionCache..cctor() in E:\Lib - All\Lib - SharedCache\SharedCache_Sources_Release_3.0.5.1\SharedCache.WinServiceCommon\Provider\Cache\IndexusDistributionCache.cs:line 76

The app.config is basically the same as the one out-of-the-box and it has the server name specified under the <servers> tag.

How can I diagnose the error? Is it a library bug?

Nov 6, 2010 at 3:46 PM

I'm also receiving the following error doing a simple out of the box test using the Test console app except I have replication disabled (ServiceFamilyMode="0").

The type initializer for 'SharedCache.WinServiceCommon.Provider.Cache.IndexusDistributionCache' threw an exception.

Any help anyone?

Thank you.

Dec 16, 2010 at 5:39 AM

I had this same issue, and after digging around in the SharedCache source, I determined it was because I was missing an "indexusNetSharedCache" section in the app.config of my console app:

 

<section name="indexusNetSharedCache" type="MergeSystem.Indexus.WinServiceCommon.Configuration.Client.IndexusProviderSection, MergeSystem.Indexus.WinServiceCommon" />

 

I also didn't have the client-specific config section in my app.config. The exception was resolved once I added these two things.

Here's an example client config:

<indexusNetSharedCache defaultProvider="IndexusSharedCacheProvider">
  <providers>
  <add name="IndexusSharedCacheProvider" type="MergeSystem.Indexus.WinServiceCommon.Provider.Cache.IndexusSharedCacheProvider, MergeSystem.Indexus.WinServiceCommon" />
  </providers>
  <clientSetting 
    SharedCacheVersionNumber="3.0.5.1"
    LoggingEnable="1"
    CompressionEnabled="0"
    CompressionMinSize="1024000"
    HashingAlgorithm="Hashing"
    SocketPoolMinAvailableSize="5"
  />
  <servers>
    <add key="mysystem" ipaddress="127.0.0.1" port="48888" />
  </servers>
</indexusNetSharedCache>