ModulesConfigurationSection fail to load in Network Enviornment

Topics: Prism v4 - WPF 4
Feb 2, 2011 at 3:48 PM

Hi,

I got a Prism 4.0 based application which loads configured module from a config file. If I run this application on the netwrok folder it fails to read the "modules" config section and it throws Security Exception and asking for FullTrust. In same application if I reference the module then all works well even on netwrok share.

As far as I know, since .net 3.5 SP1 onwards the security consideration on running assembly from netwrok is removed and also proved correct as by referencing same module on netwrok is works fine. Also I tried in Prism 2.0 and its working fine.

Is it possible that Prism has got some kind of bug which throws an security exception if it tries to load a module on the network share? Or am I doing something wrong? Has anyone did this before?

Following the app.config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="modules" type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism"/>
  </configSections>
  <modules>
    <!-- Specify the module information in Following format-->
    <module assemblyFile="ModularityWithUnity.Desktop.ModuleE.dll" moduleType="ModularityWithUnity.Desktop.ModuleE, ModularityWithUnity.Desktop.ModuleE, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" moduleName="ModuleE" startupLoaded="false" />    
    <!--<module assemblyFile="Modules/Longview.Wpf.Module.ComGen.dll" moduleType="Longview.Wpf.Module.ComGen.ComGen, Longview.Wpf.Module.ComGen" moduleName="ComGen" startupLoaded="false" />-->
  </modules>
  <runtime>
    <loadFromRemoteSources enabled="true" />
  </runtime>
</configuration>
Following is the code in Shell which loads modules specifed in Config file.
protected override void ConfigureModuleCatalog()
        {
            // DiscoveryManager referenced in code.
            Type discoveryManagerType = typeof(DiscoveryManager);
            ModuleCatalog.AddModule(new ModuleInfo(discoveryManagerType.Name, discoveryManagerType.AssemblyQualifiedName));

            // LoadManager referenced in code.
            Type loadManagerType = typeof(LoadManager);
            ModuleCatalog.AddModule(new ModuleInfo(loadManagerType.Name, loadManagerType.AssemblyQualifiedName));

            // Load any module that are configured in Configuration File
            ConfigurationModuleCatalog configurationCatalog = new ConfigurationModuleCatalog();
            ((AggregateModuleCatalog)ModuleCatalog).AddCatalog(configurationCatalog);

        }
Feb 3, 2011 at 1:09 PM

Hi,

Could you provide us with the complete stack trace information of your exception? I´m trying to reproduce your scenario but I can´t get a Security Exception.

Thanks,

Miguel Bronzovic
http://blogs.southworks.net/mbronzovic

 

Feb 4, 2011 at 3:22 PM

System.Configuration.ConfigurationErrorsException was unhandled
  Message=An error occurred creating the configuration section handler for modules: Request failed. (F:\<Some Folder>\Shell\Wpf.Shell\bin\Debug\Application Portal.vshost.exe.Config line 6)
  Source=System.Configuration
  BareMessage=An error occurred creating the configuration section handler for modules: Request failed.
  Filename=F:\<Some Folder>\Shell\Wpf.Shell\bin\Debug\Application Portal.vshost.exe.Config
  Line=6
  StackTrace:
       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.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, 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.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
       at System.Configuration.ConfigurationManager.GetSection(String sectionName)
       at Microsoft.Practices.Prism.Modularity.ConfigurationStore.RetrieveModuleConfigurationSection() in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Modularity\ConfigurationStore.Desktop.cs:line 32
       at Microsoft.Practices.Prism.Modularity.ConfigurationModuleCatalog.EnsureModulesDiscovered() in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Modularity\ConfigurationModuleCatalog.Desktop.cs:line 70
       at Microsoft.Practices.Prism.Modularity.ConfigurationModuleCatalog.InnerLoad() in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Modularity\ConfigurationModuleCatalog.Desktop.cs:line 54
       at Microsoft.Practices.Prism.Modularity.ModuleCatalog.Load() in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Modularity\ModuleCatalog.cs:line 176
       at Microsoft.Practices.Prism.Modularity.ModuleCatalog.Initialize() in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Modularity\ModuleCatalog.cs:line 344
       at Longview.Wpf.Shell.AggregateModuleCatalog.Initialize() in F:\<Some Folder>\Shell\Wpf.Shell\AggregateModuleCatalog.cs:line 116
       at Microsoft.Practices.Prism.Modularity.ModuleManager.Run() in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Modularity\ModuleManager.cs:line 110
       at Microsoft.Practices.Prism.UnityExtensions.UnityBootstrapper.InitializeModules() in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism.UnityExtensions\UnityBootstrapper.cs:line 192
       at Microsoft.Practices.Prism.UnityExtensions.UnityBootstrapper.Run(Boolean runWithDefaultConfiguration) in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism.UnityExtensions\UnityBootstrapper.cs:line 115
       at Microsoft.Practices.Prism.Bootstrapper.Run() in c:\release\WorkingDir\PrismLibraryBuild\PrismLibrary\Desktop\Prism\Bootstrapper.cs:line 77
       at Longview.Wpf.Shell.App.OnStartup(StartupEventArgs e) in F:\<Some Folder>\Shell\Wpf.Shell\app.xaml.cs:line 19
       at System.Windows.Application.<.ctor>b__1(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at Longview.Wpf.Shell.App.Main() in F:\<Some Folder>\Shell\Wpf.Shell\obj\x86\Debug\App.g.cs:line 50
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Security.SecurityException
       Message=Request failed.
       Source=mscorlib
       GrantedSet=""
       PermissionState=<PermissionSet class="System.Security.PermissionSet"
version="1"
Unrestricted="true"/>

       RefusedSet=""
       Url=""
       StackTrace:
            at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)
            at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)
            at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
            at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
            at System.Configuration.TypeUtil.InvokeCtorWithReflectionPermission(ConstructorInfo ctor)
            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)
       InnerException:

Developer
Feb 16, 2011 at 6:12 PM
Edited Feb 16, 2011 at 6:13 PM

Hi,

After spiking with your scenario, we've found that the behavior you're mentioning happens due to a known issue in .Net 4, which causes the ConfigurationManager.GetSection method not to work from shared locations. You can read more about this in the following thread from the .Net framework MSDN forum:

.NET 4 bug: ConfigurationManager.GetSection throws exception running from network share - status?

You could try using any of the other mechanisms for obtaining a module catalog provided by Prism. You can read more about this in the Modularity Chapter from the Prism MSDN documentation.

If you do need to use the App.config file to store your modules' information, one possible workaround would be to create a different implementation of IModuleCatalog, which would be similar to the ConfigurationModuleCatalog, except that it would uses the ConfigurationManager.AppSettings property instead of the ConfigurationStore (which internally uses the ConfigurationManager.GetSection method to retrieve the modules section in the App.config). Take into account that the main functionality of the aforementioned classes is to obtain ModuleInfo instances from the entries in the App.config file, so you should make your custom ModuleCatalog obtain the necessary information from the key-value pairs in the AppSettings part of the App.Config to create the ModuleInfos.

You might find the contents of the following classes useful to achieve this scenario (they can be found inside the Modularity folder of the Microsoft.Practices.Prism assembly):

  • ModuleConfigurationElement
  • ConfigurationStore
  • ConfigurationModuleCatalog

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi