1
Vote

Unhandled type initializer

description

I am writing a custom timer job and thought I would use the configstore to manage configuration settings for my timer job. When the timer kicks off, it is supposed to retrieve some settings from the config store. As soon as it trys to get the first configuration value, I get the following error: "TypeInitializationException was unhandled by user code" and then "The type initializer for 'COB.SharePoint.Utilities.ConfigStore' threw an exception. The following is an excerpt from my code:
 
string NotifyEmail = ConfigStore.GetValue("ContractManagement","NotifyEmail");
string SiteUrl = ConfigStore.GetValue("ContractManagement","SiteUrl");
string ListName = ConfigStore.GetValue("ContractManagement","ListName");
 
I get the error on the first "GetValue" attempt.
 
Any clues?

comments

dipetersen wrote Mar 12, 2009 at 8:50 PM

UPDATE:

Looking a little closer, the inner-exception is:

{"The key 'ConfigStoreCacheDependencyFile' does not exist in the appSettings configuration section."}

Since this code is running as a JobDefinition, do you think this has something to do with the error I am receiving?

Thanks

dipetersen wrote Mar 12, 2009 at 9:05 PM

Here's the whole stack trace::


System.TypeInitializationException was unhandled by user code
Message="The type initializer for 'COB.SharePoint.Utilities.ConfigStore' threw an exception."
Source="COB.SharePoint.Utilities.ConfigStore"
TypeName="COB.SharePoint.Utilities.ConfigStore"
StackTrace:
   at COB.SharePoint.Utilities.ConfigStore.GetValue(String Category, String Key)
   at GavilonContractManagementTicklerJob.ContractManagementTicklerJob.CheckExpireDates()
   at GavilonContractManagementTicklerJob.ContractManagementTicklerJob.Execute(Guid targetInstanceId)
   at Microsoft.SharePoint.Administration.SPTimerJobInvoke.Invoke(TimerJobExecuteData& data, Int32& result)
InnerException: System.InvalidOperationException
   Message="The key 'ConfigStoreCacheDependencyFile' does not exist in the appSettings configuration section."
   Source="System"
   StackTrace:
        at System.Configuration.AppSettingsReader.GetValue(String key, Type type)
        at COB.SharePoint.Utilities.ConfigStore..cctor()
   InnerException: 

chrisobrien wrote Nov 5, 2009 at 10:35 PM

@dipeterson,

What's happening is that the appSettings keys the Config Store expects to find are not present in the configuation file used by the SharePoint administration service. It could be you added these to a web.config file, but this config will not be loaded by a timer job. Your options are:
  • add the config keys to machine.config (can be seen by all applications)
  • create a xxxx.exe.config file for the timer job process (sorry, can't remember where/what file name off the top of my head - internet search will find this info though) and add the keys there
The keys you need are detailed in the readme.txt (along with a couple of other steps, e.g. NTFS permissions for the cache dependency file), but for convenience the appSettings keys are:

<add key="ConfigSiteUrl" value="http://www.mySite.com" />
<add key="ConfigWebName" value="" />
<add key="ConfigListName" value="Config Store" />
<add key="ConfigStoreCacheDependencyFile" value="\myUncPath\folder\ConfigStoreCacheDependency.txt" />

Obviously you'll need to edit for your values.

HTH,

Chris.

heguangm wrote Apr 12, 2010 at 7:43 PM

I have similar situation as Dipetersen that I have a timer job accessing Config Store. I added the configuration settings to the central admin's web.config. However, my config store list is located in another site collection in different web application.

I passed the dependency file not existing problem. However, the configuration store could not find any records and the count in the dictionary is always 0.

From the event log, only see one excetion: Event Type: Error
Event Source: Windows SharePoint Services 3
Event Category: Timer
Event ID: 6398
Date: 4/12/2010
Time: 3:16:05 PM
User: N/A
Computer: DEV-MOSSA
Description:
The Execute method of job definition ######.GlobalAccountMasterSyncTimerJob (ID 1a8c05f5-cb18-4af9-9493-3942b61e404e) threw an exception. More information is included below.

The type initializer for 'COB.SharePoint.Utilities.ConfigStore' threw an exception.

Any ideas here?

Thanks,

Guangming

wrote Feb 14, 2013 at 2:26 AM