2 // System.AppDomainSetup.cs
5 // Dietmar Maurer (dietmar@ximian.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // (C) 2001 Ximian, Inc. http://www.ximian.com
9 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
12 // Fix serialization compatibility with MS.NET.
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Runtime.CompilerServices;
36 using System.Runtime.InteropServices;
37 using System.Security;
40 using System.Runtime.Hosting;
41 using System.Security.Policy;
47 [ClassInterface (ClassInterfaceType.None)]
52 public sealed class AppDomainSetup
54 public sealed class AppDomainSetup : IAppDomainSetup
57 string application_base;
58 string application_name;
60 string configuration_file;
63 string private_bin_path;
64 string private_bin_path_probe;
65 string shadow_copy_directories;
66 string shadow_copy_files;
67 bool publisher_policy;
68 private bool path_changed;
69 private LoaderOptimization loader_optimization;
70 bool disallow_binding_redirects;
71 bool disallow_code_downloads;
73 // those fields also exist in the runtime, so we need dummies in 1.x profile too.
75 private ActivationArguments _activationArguments;
76 AppDomainInitializer domain_initializer;
78 ApplicationTrust application_trust;
80 object _activationArguments;
81 object domain_initializer; // always null
83 string [] domain_initializer_args;
84 SecurityElement application_trust_xml;
85 bool disallow_appbase_probe;
86 byte [] configuration_bytes;
88 public AppDomainSetup ()
92 internal AppDomainSetup (AppDomainSetup setup)
94 application_base = setup.application_base;
95 application_name = setup.application_name;
96 cache_path = setup.cache_path;
97 configuration_file = setup.configuration_file;
98 dynamic_base = setup.dynamic_base;
99 license_file = setup.license_file;
100 private_bin_path = setup.private_bin_path;
101 private_bin_path_probe = setup.private_bin_path_probe;
102 shadow_copy_directories = setup.shadow_copy_directories;
103 shadow_copy_files = setup.shadow_copy_files;
104 publisher_policy = setup.publisher_policy;
105 path_changed = setup.path_changed;
106 loader_optimization = setup.loader_optimization;
107 disallow_binding_redirects = setup.disallow_binding_redirects;
108 disallow_code_downloads = setup.disallow_code_downloads;
110 _activationArguments = setup._activationArguments;
111 domain_initializer = setup.domain_initializer;
112 domain_initializer_args = setup.domain_initializer_args;
113 application_trust_xml = setup.application_trust_xml;
114 disallow_appbase_probe = setup.disallow_appbase_probe;
115 configuration_bytes = setup.configuration_bytes;
120 public AppDomainSetup (ActivationArguments activationArguments)
122 _activationArguments = activationArguments;
125 public AppDomainSetup (ActivationContext activationContext)
127 _activationArguments = new ActivationArguments (activationContext);
131 static string GetAppBase (string appBase)
136 int len = appBase.Length;
137 if (len >= 8 && appBase.ToLower ().StartsWith ("file://")) {
138 appBase = appBase.Substring (7);
139 if (Path.DirectorySeparatorChar != '/')
140 appBase = appBase.Replace ('/', Path.DirectorySeparatorChar);
141 if (Environment.IsRunningOnWindows) {
142 // Under Windows prepend "//" to indicate it's a local file
143 appBase = "//" + appBase;
148 // under 1.x the ":" gets a special treatment - but it doesn't make sense outside Windows
149 } else if (!Environment.IsRunningOnWindows || (appBase.IndexOf (':') == -1)) {
151 appBase = Path.GetFullPath (appBase);
157 public string ApplicationBase {
158 get { return GetAppBase (application_base); }
159 set { application_base = value; }
162 public string ApplicationName {
164 return application_name;
167 application_name = value;
171 public string CachePath {
180 public string ConfigurationFile {
182 if (configuration_file == null)
184 if (Path.IsPathRooted(configuration_file))
185 return configuration_file;
186 if (ApplicationBase == null)
187 throw new MemberAccessException("The ApplicationBase must be set before retrieving this property.");
188 return Path.Combine(ApplicationBase, configuration_file);
191 configuration_file = value;
195 public bool DisallowPublisherPolicy {
197 return publisher_policy;
200 publisher_policy = value;
204 public string DynamicBase {
206 if (dynamic_base == null)
209 if (Path.IsPathRooted (dynamic_base))
212 if (ApplicationBase == null)
213 throw new MemberAccessException ("The ApplicationBase must be set before retrieving this property.");
215 return Path.Combine (ApplicationBase, dynamic_base);
218 if (application_name == null)
219 throw new MemberAccessException ("ApplicationName must be set before the DynamicBase can be set.");
220 uint id = (uint) application_name.GetHashCode ();
221 dynamic_base = Path.Combine (value, id.ToString("x"));
225 public string LicenseFile {
230 license_file = value;
234 [MonoLimitation ("In Mono this is controlled by the --share-code flag")]
235 public LoaderOptimization LoaderOptimization {
237 return loader_optimization;
240 loader_optimization = value;
244 public string PrivateBinPath {
246 return private_bin_path;
249 private_bin_path = value;
254 public string PrivateBinPathProbe {
256 return private_bin_path_probe;
259 private_bin_path_probe = value;
264 public string ShadowCopyDirectories {
266 return shadow_copy_directories;
269 shadow_copy_directories = value;
273 public string ShadowCopyFiles {
275 return shadow_copy_files;
278 shadow_copy_files = value;
283 public bool DisallowBindingRedirects {
285 return disallow_binding_redirects;
288 disallow_binding_redirects = value;
292 public bool DisallowCodeDownload {
294 return disallow_code_downloads;
297 disallow_code_downloads = value;
303 public ActivationArguments ActivationArguments {
304 get { return _activationArguments; }
305 set { _activationArguments = value; }
308 [MonoLimitation ("it needs to be invoked within the created domain")]
309 public AppDomainInitializer AppDomainInitializer {
310 get { return domain_initializer; }
311 set { domain_initializer = value; }
314 [MonoLimitation ("it needs to be used to invoke the initializer within the created domain")]
315 public string [] AppDomainInitializerArguments {
316 get { return domain_initializer_args; }
317 set { domain_initializer_args = value; }
320 [MonoNotSupported ("This property exists but not considered.")]
321 public ApplicationTrust ApplicationTrust {
323 if (application_trust_xml == null)
325 if (application_trust == null)
326 application_trust = new ApplicationTrust ();
327 return application_trust;
330 application_trust = value;
332 application_trust_xml = value.ToXml ();
333 application_trust.FromXml (application_trust_xml);
336 application_trust_xml = null;
340 [MonoNotSupported ("This property exists but not considered.")]
341 public bool DisallowApplicationBaseProbing {
342 get { return disallow_appbase_probe; }
343 set { disallow_appbase_probe = value; }
346 [MonoNotSupported ("This method exists but not considered.")]
347 public byte [] GetConfigurationBytes ()
349 return configuration_bytes != null ? configuration_bytes.Clone () as byte [] : null;
352 [MonoNotSupported ("This method exists but not considered.")]
353 public void SetConfigurationBytes (byte [] value)
355 configuration_bytes = value;