SD.LLBLGen.Pro. ORMSupportClasses.DependencyInjectionInfoProviderSingleton throws System.TypeInitializationException

Posts   
 
    
Posts: 36
Joined: 02-May-2012
# Posted on: 08-Jun-2016 17:26:50   

SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton throws System.TypeInitializationException

The type initializer for 'SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton' threw an exception

Adapter, remoting via IIS. LLBL versions SD.LLBLGen.Pro.ORMSupportClasses.NET20: 3.5.12.417 (.net 3.5) and SD.LLBLGen.Pro.ORMSupportClasses: 4.2.14.701 (.net 4.0 and 4.5)

SQL Server 2008R2 and 2012

This happens intermittently, and more so in a production environment (heavier usage) but also in qa and development environments.

To fix this in production, they delete temp files on web server or restart the server.

In development we stop and start the solution again. Sometimes takes a few tries.

It has been happening for a while now, but as we get more clients using the application, the problem is being reported more and more.

It looks like it is trying to get write access to the web.config file on the server, because a section is missing? But it can't be missing or it wouldn't be working 99% of the time?

I am still digging into this, but if the stack traces below tell you anything useful, let me know.

Thanks

Kerry

web.config:


  <dependencyInjectionInformation>
    <additionalAssemblies>
      <assembly filename="STaCS.CW.Middleware.WorkflowLab.dll"/>
      <assembly filename="STaCS.CW.Middleware.Workflow.dll"/>
      <assembly filename="STaCS.CW.Middleware.Entity.dll"/>
    </additionalAssemblies>
  </dependencyInjectionInformation>


Dev stack trace from client side remoting to server (LLBL 3.5):

System.TypeInitializationException: The type initializer for 'SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton' threw an exception. --->

System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for dependencyInjectionInformation:

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

(C:\Code\CW32\STaCS\CW\Middleware\Server\STaCS.CW.Middleware.Server\web.config line 150) --->

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) at System.Security.CodeAccessPermission.Demand()

at System.Reflection.RuntimeAssembly.get_Location()

at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.ParseAssemblies(XmlNode assembliesNode)

in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionSectionHandler.cs:line 166

at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.CreateStatic(XmlNode section)

in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionSectionHandler.cs:line 83

at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.Create(Object parent, Object configContext, XmlNode section)

in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionSectionHandler.cs:line 66 at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory .CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader) at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory .CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader) at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader) at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line) --- End of inner exception stack trace --- at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Web.HttpContext.GetSection(String sectionName) at System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName) at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal .IInternalConfigSystem.GetSection(String configKey) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProvider.Init() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionInfoProvider.cs:line 278 at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProvider..ctor() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionInfoProvider.cs:line 122 at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton..cctor() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionInfoProvider.cs:line 54 --- End of inner exception stack trace ---

Server stack trace: at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton .PerformDependencyInjection(Object injectionTarget) at SD.LLBLGen.Pro.ORMSupportClasses.EntityCore`1.PerformDependencyInjection() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Core\EntityCore.cs:line 1429 at STaCS.CW.Middleware.EntityClasses.UserRoleEntity.InitClassMembers() in c:\Code\CW32\STaCS\CW\Middleware\Entity\EntityClasses\UserRoleEntity.cs:line 412 at STaCS.CW.Middleware.EntityClasses.UserRoleEntity.InitClassEmpty(IValidator validator, IEntityFields2 fields) in c:\Code\CW32\STaCS\CW\Middleware\Entity\EntityClasses\UserRoleEntity.cs:line 551 at STaCS.CW.Middleware.EntityClasses.UserRoleEntity..ctor(IEntityFields2 fields) in c:\Code\CW32\STaCS\CW\Middleware\Entity\EntityClasses\UserRoleEntity.cs:line 76 at STaCS.CW.Middleware.FactoryClasses.UserRoleEntityFactory.Create(IEntityFields2 fields) in c:\Code\CW32\STaCS\CW\Middleware\Entity\FactoryClasses\EntityFactories.cs:line 4472 at SD.LLBLGen.Pro.ORMSupportClasses.EntityFactoryCore2.Create() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Core\EntityFactoryCore.cs:line 284 at SD.LLBLGen.Pro.ORMSupportClasses.EntityFactoryCache2.GetEntityFactory(IEntityFactory2 factory) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\FastSerialization\EntityFactoryCache2.cs:line 109 at SD.LLBLGen.Pro.ORMSupportClasses.EntityFactoryCache2.GetEntityFactory(Type factoryType) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\FastSerialization\EntityFactoryCache2.cs:line 137 at STaCS.CW.Middleware.EntityClasses.UserEntity.get_PrefetchPathUserRoleCollection() in c:\Code\CW32\STaCS\CW\Middleware\Entity\EntityClasses\UserEntity.cs:line 1769 at STaCS.CW.Middleware.Workflow.UserWF.get_LoginPrefetchPath() in c:\Code\CW32\STaCS\CW\Middleware\Workflow\UserWF.cs:line 29 at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at STaCS.CW.Middleware.Workflow.UserWF.get_LoginPrefetchPath() at STaCS.CW.Client.Modules.CWMain.CWMainWorkItem.StartSession() in c:\Code\CW32\STaCS\CW\Client\Modules\CWMain\CWMainWorkItem.cs:line 477

       private bool StartSession()
        {
         ...
            UserWF wfUser = new UserWF();
            user = wfUser.Load(userName, wfUser.LoginPrefetchPath);


        public IPrefetchPath2 LoginPrefetchPath
        {
            get
            {
                IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.UserEntity);

                IPrefetchPathElement2 userRoleElement = prefetchPath.Add(UserEntity.PrefetchPathUserRoleCollection);
                IPrefetchPathElement2 roleElement = userRoleElement.SubPath.Add(UserRoleEntity.PrefetchPathRole);
                IPrefetchPathElement2 element = roleElement.SubPath.Add(RoleEntity.PrefetchPathActivityTypeRoleCollection);

                prefetchPath.Add(UserEntity.PrefetchPathRoleCollectionViaUserRole);
                prefetchPath.Add(UserEntity.PrefetchPathUserFileImageCollection);
                prefetchPath.Add(UserEntity.PrefetchPathLaboratory);
                //prefetchPath.Add(UserEntity.PrefetchPathFileImageCollectionViaUserFileImage, FileImageEntity.ExcludedFieldsList());

                return prefetchPath;
            }
        }
                

In the same dev session, this is the trace from the web server test page we use to test database connectivity directly on server (still my dev machine in this case):

Verifying Workflow/DB Connectivity... Failure

System.TypeInitializationException: The type initializer for 'SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton' threw an exception. --->

System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for dependencyInjectionInformation:

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

(C:\Code\CW32\STaCS\CW\Middleware\Server\STaCS.CW.Middleware.Server\web.config line 150) ---> System.Security.SecurityException:

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) at System.Security.CodeAccessPermission.Demand()

at System.Reflection.RuntimeAssembly.get_Location()

at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.ParseAssemblies(XmlNode assembliesNode)

in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionSectionHandler.cs:line 166

at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.CreateStatic(XmlNode section)

in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionSectionHandler.cs:line 83

at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.Create(Object parent, Object configContext, XmlNode section)

in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionSectionHandler.cs:line 66

at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory .CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory .CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)

--- End of inner exception stack trace --- at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Web.HttpContext.GetSection(String sectionName) at System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName) at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal. IInternalConfigSystem.GetSection(String configKey) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProvider.Init() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionInfoProvider.cs:line 278 at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProvider..ctor() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionInfoProvider.cs:line 122 at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton..cctor() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionInfoProvider.cs:line 54 --- End of inner exception stack trace --- at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton. PerformDependencyInjection(Object injectionTarget) at SD.LLBLGen.Pro.ORMSupportClasses.EntityCore`1.PerformDependencyInjection() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Core\EntityCore.cs:line 1429 at STaCS.CW.Middleware.EntityClasses.UserRoleEntity.InitClassMembers() in c:\Code\CW32\STaCS\CW\Middleware\Entity\EntityClasses\UserRoleEntity.cs:line 412 at STaCS.CW.Middleware.EntityClasses.UserRoleEntity.InitClassEmpty(IValidator validator, IEntityFields2 fields) in c:\Code\CW32\STaCS\CW\Middleware\Entity\EntityClasses\UserRoleEntity.cs:line 551 at STaCS.CW.Middleware.EntityClasses.UserRoleEntity..ctor(IEntityFields2 fields) in c:\Code\CW32\STaCS\CW\Middleware\Entity\EntityClasses\UserRoleEntity.cs:line 76 at STaCS.CW.Middleware.FactoryClasses.UserRoleEntityFactory.Create(IEntityFields2 fields) in c:\Code\CW32\STaCS\CW\Middleware\Entity\FactoryClasses\EntityFactories.cs:line 4472 at SD.LLBLGen.Pro.ORMSupportClasses.EntityFactoryCore2.Create() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Core\EntityFactoryCore.cs:line 284 at SD.LLBLGen.Pro.ORMSupportClasses.EntityFactoryCache2.GetEntityFactory(IEntityFactory2 factory) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\FastSerialization\EntityFactoryCache2.cs:line 109 at SD.LLBLGen.Pro.ORMSupportClasses.EntityFactoryCache2.GetEntityFactory(Type factoryType) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\FastSerialization\EntityFactoryCache2.cs:line 137 at STaCS.CW.Middleware.EntityClasses.UserEntity.get_PrefetchPathUserRoleCollection() in c:\Code\CW32\STaCS\CW\Middleware\Entity\EntityClasses\UserEntity.cs:line 1769 at STaCS.CW.Middleware.Workflow.UserWF.get_DefaultPrefetchPath() in c:\Code\CW32\STaCS\CW\Middleware\Workflow\UserWF.cs:line 46 at STaCS.CW.Middleware.Workflow.UserWF.Load(Int32 userId) in c:\Code\CW32\STaCS\CW\Middleware\Workflow\UserWF.cs:line 197 at DefaultPage.btnTest_Click(Object sender, EventArgs e) in c:\Code\CW32\STaCS\CW\Middleware\Server\STaCS.CW.Middleware.Server\Default.aspx.cs:line 73


           public new UserEntity Load(int userId)
        {
            return this.Load(userId, DefaultPrefetchPath);
        }

                public new UserEntity Load(int userId, IPrefetchPath2 prefetchPath)
        {
            UserEntity user = null;

            try
            {
                RelationPredicateBucket filter = new RelationPredicateBucket();
                filter.PredicateExpression.Add(UserFields.UserId == userId);

                EntityCollection<UserEntity> users = this.List(filter, prefetchPath, true);
                if (users.Count == 1)
                {
                    user = users[0];
                }
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, ExceptionPolicies.WorkflowExceptionPolicy);
                if (rethrow)
                {
                    throw;
                }
            }
            return user;
        }

        protected override IPrefetchPath2 DefaultPrefetchPath
        {
            get
            {
                IPrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.UserEntity);
                prefetch.Add(UserEntity.PrefetchPathUserRoleCollection);
                prefetch.Add(UserEntity.PrefetchPathRoleCollectionViaUserRole);
                //prefetch.Add(UserEntity.PrefetchPathUserFileImageCollection);
                //prefetch.Add(UserEntity.PrefetchPathFileImageCollectionViaUserFileImage);
                return prefetch;
            }
        }

This is from one of the QA installations (LLBL 4.2)

STaCS.CW.Common.ExceptionHandling.CWException: Exception has been thrown by the target of an invocation. --->

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->

System.TypeInitializationException: The type initializer for 'SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton' threw an exception. --->

System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for dependencyInjectionInformation:

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

(C:\inetpub\wwwroot\FWPD36_QA\web.config line 190) ---> System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) at System.Security.CodeAccessPermission.Demand()

at System.Reflection.RuntimeAssembly.get_Location()

at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.ParseAssemblies(XmlNode assembliesNode) at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.CreateStatic(XmlNode section) at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.Create(Object parent, Object configContext, XmlNode section) at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory .CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory .CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)

--- End of inner exception stack trace --- at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Web.HttpContext.GetSection(String sectionName) at System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName) at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal .IInternalConfigSystem.GetSection(String configKey) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProvider.Init() at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProvider..ctor() at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton..cctor() --- End of inner exception stack trace --- at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton.PerformDependencyInjection(Object injectionTarget) at SD.LLBLGen.Pro.ORMSupportClasses.EntityCore1.PerformDependencyInjection() at STaCS.CW.Middleware.EntityClasses.SubmissionEntity.InitClassEmpty(IValidator validator, IEntityFields2 fields) at STaCS.CW.Middleware.FactoryClasses.SubmissionEntityFactory.Create(IEntityFields2 fields) at SD.LLBLGen.Pro.ORMSupportClasses.EntityFactoryCore2.Create() at SD.LLBLGen.Pro.ORMSupportClasses.EntityFactoryCache2.GetEntityFactory(IEntityFactory2 factory) at SD.LLBLGen.Pro.ORMSupportClasses.EntityFactoryCache2.GetEntityFactory(Type factoryType) at STaCS.CW.Middleware.EntityClasses.SubmissionEntity.CreateEntityFactory() at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.CreateFields() at STaCS.CW.Middleware.EntityClasses.SubmissionEntity..ctor() --- End of inner exception stack trace --- at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance[T]() at STaCS.CW.Middleware.Workflow.BaseEntityWorkflow1.Load(Int32 entityId, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludeFields) --- End of inner exception stack trace --- at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.IntentionalRethrow(Exception chainException, Exception originalException) at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.RethrowRecommended(Exception chainException, Exception originalException) at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.Handle(Exception exceptionToHandle) at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl.HandleException(Exception exceptionToHandle) at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName) at STaCS.CW.Middleware.Workflow.BaseEntityWorkflow1.Load(Int32 entityId, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludeFields) at STaCS.CW.Middleware.Workflow.BaseEntityWorkflow1.Load(Int32 entityId) at DefaultPage.btnTest_Click(Object sender, EventArgs e)

This is from a client site in production:

Details saved Wednesday, March 30, 2016 at 3:56:32 PM System.TypeInitializationException: The type initializer for 'SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton' threw an exception. --->

System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for dependencyInjectionInformation:

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

(C:\inetpub\wwwroot\STaCSProd\web.config line 190) --->

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) at System.Security.CodeAccessPermission.Demand()

at System.Reflection.RuntimeAssembly.get_Location()

at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.ParseAssemblies(XmlNode assembliesNode) at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.CreateStatic(XmlNode section) at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.Create(Object parent, Object configContext, XmlNode section) at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory .CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader) at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory .CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)

--- End of inner exception stack trace --- at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)

at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)

at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)

at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)

at System.Web.HttpContext.GetSection(String sectionName)

at System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName)

at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal .IInternalConfigSystem.GetSection(String configKey) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProvider.Init() at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProvider..ctor() at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton..cctor() --- End of inner exception stack trace ---

Server stack trace: at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton.PerformDependencyInjection(Object injectionTarget) at SD.LLBLGen.Pro.ORMSupportClasses.EntityCore`1.PerformDependencyInjection() at STaCS.CW.Middleware.EntityClasses.UserRoleEntity.InitClassEmpty(IValidator validator, IEntityFields2 fields) at STaCS.CW.Middleware.FactoryClasses.UserRoleEntityFactory.Create(IEntityFields2 fields) at SD.LLBLGen.Pro.ORMSupportClasses.EntityFactoryCore2.Create() at SD.LLBLGen.Pro.ORMSupportClasses.EntityFactoryCache2.GetEntityFactory(IEntityFactory2 factory) at SD.LLBLGen.Pro.ORMSupportClasses.EntityFactoryCache2.GetEntityFactory(Type factoryType) at STaCS.CW.Middleware.EntityClasses.UserEntity.get_PrefetchPathUserRoleCollection() at STaCS.CW.Middleware.Workflow.UserWF.get_LoginPrefetchPath() at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at STaCS.CW.Middleware.Workflow.UserWF.get_LoginPrefetchPath() at STaCS.CW.Client.Modules.CWMain.CWMainWorkItem.StartSession()

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 08-Jun-2016 19:04:56   

Could you please try adding the following to your web.config inside the configuration section?

<runtime> <loadFromRemoteSources enabled="true"/> </runtime>

Reference: https://msdn.microsoft.com/en-us/library/dd409252%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

Posts: 36
Joined: 02-May-2012
# Posted on: 08-Jun-2016 19:43:44   

I've encountered this setting before (for a different problem but it didn't solve it; we believed it to be a .net 4.0 issue) but I will test it out.

Note however that the problem has occurred in .net 3.5 and .net 4.5 as well.

In the .NET Framework 4.5, assemblies on local network shares are run as full trust by default; you do not have to enable the <loadFromRemoteSources> element.

Since it is not reproducible on demand, it may take a while to know if it works. In the meantime, do you know what section it is trying to create here? is it something that is only referenced sometimes and just needs to be there in the config?

note: this is a line 150 in this web.config:

  <dependencyInjectionInformation>
    <additionalAssemblies>
      <assembly filename="STaCS.CW.Middleware.WorkflowLab.dll"/>
      <assembly filename="STaCS.CW.Middleware.Workflow.dll"/>
      <assembly filename="STaCS.CW.Middleware.Entity.dll"/>
    </additionalAssemblies>
  </dependencyInjectionInformation>

System.TypeInitializationException: The type initializer for 'SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton' threw an exception. --->

System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for dependencyInjectionInformation:

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

(C:\Code\CW32\STaCS\CW\Middleware\Server\STaCS.CW.Middleware.Server\web.config line 150) --->

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) at System.Security.CodeAccessPermission.Demand()

at System.Reflection.RuntimeAssembly.get_Location()

at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.ParseAssemblies(XmlNode assembliesNode)

in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionSectionHandler.cs:line 166

at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.CreateStatic(XmlNode section)

in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionSectionHandler.cs:line 83

at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.Create(Object parent, Object configContext, XmlNode section)

in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DependencyInjection\DependencyInjectionSectionHandler.cs:line 66

at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory. CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory. CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)

Thanks

Posts: 36
Joined: 02-May-2012
# Posted on: 08-Jun-2016 19:58:42   

Also a note about other angles I've tried in the past, attached...

Attachments
Filename File size Added on Approval
CodeAccessPermission.Demand.ConfigurationErrorException.png 91,613 08-Jun-2016 19:59.00 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 08-Jun-2016 20:30:25   

It's not creating anything, it's only reading the section from the webconfig, which dlls to discover. So it's odd that this happens! The DI discovery process is started as soon as an entity type is instantiated, the static CTor is then executed and the process starts. It loads the dlls mentioned in web.config and performs reflection on them to see whether they contain injectibles for the DI process.

The error seems to come from the reflection process, namely it tries to obtain the location from the assembly and that fails. What's odd is that it doesn't fail all the time! If it failed all the time, medium trust and this: http://haacked.com/archive/2010/11/04/assembly-location-and-medium-trust.aspx/ would likely be the culprit, but now I have no direct idea what it could be...

Frans Bouma | Lead developer LLBLGen Pro
Posts: 36
Joined: 02-May-2012
# Posted on: 08-Jun-2016 20:49:52   

No, which is why it is very strange, since it works fine most of the time.

That's why we thought it was a framework issue, and I believe in googling it (months ago) I found a specific to 4.0 problem with System.Configuration, ie: why is it trying to write/create in that file? It should throw an exception if a setting is not there? (I might be able to find that link again)

So we upgraded to 4.5 and we thought that might have corrected it because it didn't happen again for a while, but then it finally started again and we are hearing from some clients as they ramp up usage that it's happening daily, and they are getting frustrated with the workaround (reboot the web server).

We also thought it was a remoting issue, but we've now had it happen when running the test page on the server.

So ya, really strange that it's doing that, and although I had it happen yesterday on my box, I have been unable to get it to happen again to try that suggestion above. Even though it shouldn't need write access, it wants write access and something is blocking it. Either we need to figure out what it is (IIS worker process?) or as a last resort, add a try/catch/retry the get Locationconfused

 at System.Reflection.RuntimeAssembly.get_Location()

   at SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler.ParseAssemblies(XmlNode assembliesNode) 

Other suggestions welcome!!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 09-Jun-2016 10:25:45   

KerryKilgour wrote:

No, which is why it is very strange, since it works fine most of the time.

That's why we thought it was a framework issue, and I believe in googling it (months ago) I found a specific to 4.0 problem with System.Configuration, ie: why is it trying to write/create in that file? It should throw an exception if a setting is not there? (I might be able to find that link again)

I don't really know why you keep going back to the point something is writing/creating the file? simple_smile It's originating inside the Assembly.Location property read according to the stacktrace, which is read from code which is started in the app/web.config section handler.

So it looks like it's something to do with the web.config file, but that's a red herring: the section handler we have which reads the assembly names to reflect on is calling Assembly.Location and that gives sometimes this error in your situation. So the section handler is the original source. As it reads line 150, asp.net gives you a hint that it might be caused by line 150, but it's really just a start of a call chain and not the root cause.

So to recap: When in your application an entity instance has to be created for the first time, the static constructor of DependencyInjectionInfoProvider is run. This initializes its cache with types. To initialize itself, it tries to find out what types have to be injected where. One way to do that is to check whether a dependency injection section is specified in the config file of the application, and if so, which dlls are specified there. It does this through its own section handler, which is standard .net stuff (a class which implements IConfigurationSectionHandler). The handler is used by the asp.net runtime to parse the config section so name-value pairs are obtained without the need of parsing xml.

It seems to go wrong on this line: filename = Path.Combine(Path.GetDirectoryName(typeof(DependencyInjectionSectionHandler).Assembly.Location), filename);

which is located here: http://referencesource42.llblgen.com/#SD.LLBLGen.Pro.ORMSupportClasses/DependencyInjection/DependencyInjectionSectionHandler.cs,166

The 'parsing' done in the handler is to interpret the data specified in the section in web.config and to convert it into usable information for the pass which reflects over the dlls specified. The line above which goes wrong is needed to determine the location of the application so it can determine relative paths. This is generic code which is also used in desktop/console applications so for web it's perhaps less needed, but it should work regardless, and it does, except for the situation you ran into.

As your situation is non-deterministic, it's highly likely a timing related issue: some processes work side by side without problem but once in a while things go out of sync and things start to go bad.

I think this is related to application pool recycling, but I'm not sure, so you have to perform a test. Please do in development the following:

  • as the part which fails is a service, you should create a simple console app which calls the service in a loop. If an exception occurs, it has to log the exception but continue the loop! It should only break if the security exception occurs.
  • in the console app call a fast method on the service which returns an entity. The key of the test is that the service method should be fast ( so you get a lot of calls) but it should use entities!
  • you start the service
  • you start the test console app.
  • you should see normal behavior: the console app calls the service, the service provides the data etc.
  • you then go into IIS admin and recycle the application pool for your service.
  • you can also try to recycle the application pool from a powershell script which does this in a loop with random intervals.

it might take a few tries but as the console app loops, it might very well be you run into this when you recycle the application pool for the service.

If this triggers the exception you at least know where to look further. An application pool recycle is a bit of a problem as there are 2 versions of the app in memory and some files might be locked.

I don't know whether you actually use a separate application pool for your service inside IIS (you should). If you do, be sure it never recycles on its own due to inactivity. By default IIS recycles application pools after 20minutes of inactivity or when 100MB of mem is used.

To trigger the start of dependency injection information discovery, you can do:

var dummy = new UserEntity();

in global.asax, in the Application started event handler. This makes sure as soon as the service is started, it will initialize the pipeline I described above for discovering DI information. This too might make it go away completely, but it would be better if you could reproduce it more reliably first of course simple_smile

So ya, really strange that it's doing that, and although I had it happen yesterday on my box, I have been unable to get it to happen again to try that suggestion above. Even though it shouldn't need write access, it wants write access and something is blocking it.

It's not writing anything, it's calling Assembly.Location to obtain the local folder of the application to determine the absolute location of relative paths specified in the dependency information in web.config.

It's likely this goes wrong because a part of the path is for a small period of time unavailable, and my guess is this happens due to recycling of application pools.

If nothing helps we can look at adding something to work around this, but first let's see whether the test I suggested above gives any insight simple_smile

oh and ps: Kerry, next time please come to us sooner so it won't lead to frustration simple_smile Having to restart a webserver is never a solution.

Frans Bouma | Lead developer LLBLGen Pro