locked
The type initializer for 'Microsoft.Xrm.Client.Services.OrganizationServiceCache' threw an exception. RRS feed

  • Question

  • I am getting this error randomly in a perfectly working ASP.Net site otherwise. It looks like it attempts to creare CachedOrganizationService every other time whereas I have disabled caching in my web.config

       <add name="Xrm" connectionString="Server=http://myserver; Domain=domain; Username=username; Password=pwd"/>
      </connectionStrings>
      <microsoft.xrm.client>
        <contexts>
          <add name="Xrm" type="Xrm.XrmServiceContext, REDIP"/>
        </contexts>
      </microsoft.xrm.client>

    The code looks as listed below

       protected void ContactsDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
            {
                var db = new XrmServiceContext("Xrm");
                db.MergeOption = Microsoft.Xrm.Sdk.Client.MergeOption.NoTracking;
                var products = from pp in db.exch_parentproductSet
                               join pm  in db.exch_productmedicareSet
                                 on pp.exch_parentproductId equals pm.exch_ParentProductId.Id
                                          where pp.exch_AccountID.Id == new Guid("C2FA445C-E5A2-E211-8765-BC305B996F9")
                               select new { pp.exch_parentproductname, pm.exch_PlanCode };
                e.Result = products.ToList();
            }

    This is tied to an ASP.Net grid control in .Net Framework 4.

    The type initializer for 'Microsoft.Xrm.Client.Services.OrganizationServiceCache' threw an exception.] Microsoft.Xrm.Client.Services.OrganizationServiceCache..ctor(ObjectCache cache, OrganizationServiceCacheSettings settings) +0 Microsoft.Xrm.Client.Configuration.<>c__DisplayClass2.<CreateOrganizationServiceCache>b__1() +44 Microsoft.Xrm.Client.Configuration.InitializableConfigurationElement`1.CreateDependency(Type type, Func`1 createDefault, Object[] args) +59 Microsoft.Xrm.Client.Configuration.OrganizationServiceCacheElement.CreateOrganizationServiceCache(ObjectCache cache, OrganizationServiceCacheSettings settings) +197 Microsoft.Xrm.Client.Configuration.CrmConfigurationProvider.CreateServiceCache(String serviceCacheName, String connectionId, Boolean allowDefaultFallback) +437 Microsoft.Xrm.Client.Configuration.CrmConfigurationProvider.CreateService(OrganizationServiceElement serviceElement, CrmConnection connection) +198 Microsoft.Xrm.Client.Threading.HttpSingleton`1.GetInstance(String name, Func`1 create) +128 Microsoft.Xrm.Client.Configuration.CrmConfigurationProvider.CreateService(CrmConnection connection, String serviceName, Boolean allowDefaultFallback) +595 Microsoft.Xrm.Client.Configuration.CrmConfigurationProvider.CreateService(String contextName, Boolean allowDefaultFallback) +434 Microsoft.Xrm.Client.CrmOrganizationServiceContext..ctor(String contextName) +21


    Any suggestions greatly appreciated!

    Warm regards,

    Sofia Khatoon

    Tuesday, March 10, 2015 3:43 PM

All replies

  • Hi Sofia,

    Put your code under try and catch block may be you will get some more useful information.

    try{ //your code}

    catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)

    //check for ex.Detail.Message 

     }



    Microsoft Dynamics CRM Training|Our Blog | Follow US | Our Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Wednesday, March 11, 2015 5:30 AM
    Moderator
  • I ended up doing the following steps to resolve this issue.

    1) Uninstalling .Net framework 4.5 from build macine

    2) Reinstall .Net framework 4 to build machine

    3) Recreate the site in .Net 4 and deploy it

    Thanks for the suggestions. 

    Warm regards,

    Sofia Khatoon


    sofia khatoon

    Wednesday, March 11, 2015 2:18 PM