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

Topics: Exception Handling Application Block, Logging Application Block
Nov 5, 2007 at 9:59 PM
Edited Nov 5, 2007 at 10:18 PM
I managed to get rid rid of "That assembly does not allow partially trusted callers." exception by compiling unsigned version of ObjectBuilder. But now I am getting following exception

===================================

An error occurred loading a configuration file: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. (C:\Documents and Settings\dkerry\Local Settings\Application Data\assembly\dl3\NJ5TCO7T.77O\55R92G3X.PXH\6ffabc3a\d0501f65_b21fc801\Austock.OfficeSystem.General.DLL.config) (System.Configuration)

------------------------------
Program Location:

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, Boolean getLkg, Boolean checkPermission)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.Configuration.GetSection(String sectionName)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSourceImplementation.GetSection(String sectionName)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource.GetSection(String sectionName)
at Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings.GetLoggingSettings(IConfigurationSource configurationSource)
at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolderCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) in C:\EntLib3Src\ObjectBuilder-1.0.51206.0-source\ObjectBuilder\BuilderStrategy.cs:line 39
at Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) in C:\EntLib3Src\ObjectBuilder-1.0.51206.0-source\ObjectBuilder\Strategies\Singleton\SingletonStrategy.cs:line 48
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) in C:\EntLib3Src\ObjectBuilder-1.0.51206.0-source\ObjectBuilder\BuilderStrategy.cs:line 39
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.Configuration.LoggingExceptionHandlerAssembler.Assemble(IBuilderContext context, ExceptionHandlerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedObjectFactory`2.Create(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntryCustomFactory.Create(IBuilderContext context, ExceptionTypeData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) in C:\EntLib3Src\ObjectBuilder-1.0.51206.0-source\ObjectBuilder\BuilderStrategy.cs:line 39
at Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) in C:\EntLib3Src\ObjectBuilder-1.0.51206.0-source\ObjectBuilder\Strategies\Singleton\SingletonStrategy.cs:line 48
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) in C:\EntLib3Src\ObjectBuilder-1.0.51206.0-source\ObjectBuilder\BuilderStrategy.cs:line 39
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) in C:\EntLib3Src\ObjectBuilder-1.0.51206.0-source\ObjectBuilder\BuilderBase.cs:line 101
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) in C:\EntLib3Src\ObjectBuilder-1.0.51206.0-source\ObjectBuilder\BuilderBase.cs:line 79
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUpTTypeToBuild(IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies) in C:\EntLib3Src\ObjectBuilder-1.0.51206.0-source\ObjectBuilder\BuilderBase.cs:line 66
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUpT(IReadWriteLocator locator, String id, IConfigurationSource configurationSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.LocatorNameTypeFactoryBase`1.Create(String name)
at Austock.ExceptionHandling.ExceptionPolicy.HandleException(Exception exception, String policyName) in C:\Source\Austock\Austock.ExceptionHandling\ExceptionPolicy.cs:line 146

===================================

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

------------------------------
Program Location:

at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.Configuration.Internal.InternalConfigHost.StaticOpenStreamForRead(String streamName)
at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForRead(String streamName, Boolean assertPermissions)
at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForRead(String streamName)
at System.Configuration.ClientConfigurationHost.OpenStreamForRead(String streamName)
at System.Configuration.UpdateConfigHost.OpenStreamForRead(String streamName)
at System.Configuration.BaseConfigurationRecord.FindSection(String[] keys, SectionXmlInfo sectionXmlInfo, Int32& lineNumber)
at System.Configuration.BaseConfigurationRecord.GetSectionXmlReader(String[] keys, SectionInput input)


Why is it looking for the config file in C:\Documents and Settings\dkerry\Local Settings\Application Data\assembly\dl3NJ5TCO7T.77O\55R92G3X.PXH\6ffabc3a\d0501f65_b21fc801\ folder rather than the bin\debug or bin\release folder?

Aslo, when i did F5 to run the application it didn't create a copy of the config file in "C:\Documents and Settings\dkerry\Local Settings\Application Data\assembly\dl3\NJ5TCO7T.77O\55R92G3X.PXH\6ffabc3a\d0501f65_b21fc801\" folder, i had to manually copy it there.

It is causing these issue in VSTO project, document level or application level. It is working fine for other types of projects; win forms, console application.

I believe Application Blocks are meant to make your life easier, but it’s making it miserable. There are no good help resources available, have plenty of unanswered issues sitting in this forum and could not find any other discussion forum for posting issues.
Nov 6, 2007 at 11:24 AM
Edited Nov 6, 2007 at 12:10 PM
Hi,

You need to clearly explain your scenario and organize your posts better in order to get helpful answers; pasting a 50 lines long stack trace and burying one line stating this is a VSTO app won't be enough. How are you deploying your app? what does your config file look like? Why is it running in partial trust? I'm not familiar with VSTO apps, which might provide some of these answers...

You can see two things here:
  • the last part of the stack is the .net framework trying to read configuration, not entlib
  • a permission to read this file is required, and for some reason your app doesn't have it. Why the file is there, and why your app doesn't have permissions has nothing to do with entlib; you need to figure out why this is happening. It might be just the way VSTO apps work, blocks or not.

I suggest you try using the SystemConfigurationSource instead of the file one and see how it works. It is possible a VSTO app can only read configuration that way.

Fernando