Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > ClickOnce + AppDomain.CreateDomain = SecurityException on ReflectionPermission
 

ClickOnce + AppDomain.CreateDomain = SecurityException on ReflectionPermission

I have a ClickOnce package I am trying to deploy that loads dll's on the fly, like plugins. I took advice from another blog post and put them in separate app domains. It runs great on my dev box, but once I publish and try to run, I get a SecurityException that says:

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

I have given the app full trust for ClickOnce security settings. Here is the code I am calling to setup the AppDomain:

        private static AppDomain CreateAppDomain(string domainName, string fileName, string configFileName)
        {
            var setup = new AppDomainSetup
                            {
                                ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
                                ApplicationName = Path.GetFileName(fileName),
                                CachePath = AppDomain.CurrentDomain.BaseDirectory,
                                ConfigurationFile = configFileName,
                                PrivateBinPath = Path.GetDirectoryName(fileName),
                                ShadowCopyDirectories = Path.GetDirectoryName(fileName),
                                ShadowCopyFiles = "true"
                            };

            return AppDomain.CreateDomain(domainName, AppDomain.CurrentDomain.Evidence, setup);
        }

        public static object ExecuteModule(string moduleName, object[] parameters)
        {
            var exePath = Assembly.GetExecutingAssembly().Location;
            var filePath = string.Format(@"{0}\Modules\Module.{1}.dll",
                                         exePath.Substring(0, exePath.LastIndexOf(@"\")),
                                         moduleName);

            var domain = CreateAppDomain(moduleName, filePath, string.Empty);
            var moduleManager =
                (ModuleManager)
                domain.CreateInstanceAndUnwrap(
                    AssemblyName.GetAssemblyName(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                              "ModuleLoader.dll")).FullName,
                    typeof(ModuleManager).FullName);

            domain.AssemblyResolve += ((sender, args) =>
                                           {
                                               var appDomain = sender as AppDomain;
                                               var moduleFolder = appDomain.RelativeSearchPath;
                                               var path = Path.Combine(moduleFolder, string.Format("{0}.dll", args.Name.Split(',')[0]));
                                               return appDomain.Load(AssemblyName.GetAssemblyName(path));
                                           });
            return moduleManager.FetchModuleEntryPoint(filePath, domain, parameters);
        }

Any ideas?
BowlerMonk  Tuesday, September 01, 2009 2:34 PM
Hi,

And how is your app deployed to your users (share, intranet, internet)?

Could you get the call stack of the exception? Without this information, I don't think it is necessary the CreateDomain method causing the problem.

Regards,
Jie
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

If you have any feedback, please tell us.

The CodeFx Project
My Blog (in Simplified Chinese)
Wang, Jie  Thursday, September 03, 2009 9:37 AM

You can use google to search for other answers

Custom Search

More Threads

• Microsoft: HELP - include .Net Framework 2.0 in Windowsx86 Service Packs?
• how to make install throuh cd and get updates through web.
• Click Once issues: vs 2005, vs2008, Application Files, mage, mageUI
• Problem with a icon and the Windows 7 Logo Toolkit
• MSI
• Deploy .net framework 3.5 with ClickOne and Visual Basic Express Edition 2008
• Control hosted in Web page works in IIS5 but not IIS6
• Value does not fall within the expected range.
• Update files for a Clickonce install
• Anyone having problems w/ ClickOnce in the July CTP?