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;
39 using System.Runtime.Hosting;
40 using System.Security.Policy;
46 [ClassInterface (ClassInterfaceType.None)]
50 public sealed class AppDomainSetup : IAppDomainSetup
52 string application_base;
53 string application_name;
55 string configuration_file;
58 string private_bin_path;
59 string private_bin_path_probe;
60 string shadow_copy_directories;
61 string shadow_copy_files;
62 bool publisher_policy;
63 private bool path_changed;
64 private LoaderOptimization loader_optimization;
65 bool disallow_binding_redirects;
66 bool disallow_code_downloads;
68 // those fields also exist in the runtime, so we need dummies in 1.x profile too.
70 private ActivationArguments _activationArguments;
71 ApplicationTrust application_trust;
72 AppDomainInitializer domain_initializer;
74 object _activationArguments;
75 object application_trust; // always null
76 object domain_initializer; // always null
78 string [] domain_initializer_args;
79 bool disallow_appbase_probe;
80 byte [] configuration_bytes;
82 public AppDomainSetup ()
86 internal AppDomainSetup (AppDomainSetup setup)
88 application_base = setup.application_base;
89 application_name = setup.application_name;
90 cache_path = setup.cache_path;
91 configuration_file = setup.configuration_file;
92 dynamic_base = setup.dynamic_base;
93 license_file = setup.license_file;
94 private_bin_path = setup.private_bin_path;
95 private_bin_path_probe = setup.private_bin_path_probe;
96 shadow_copy_directories = setup.shadow_copy_directories;
97 shadow_copy_files = setup.shadow_copy_files;
98 publisher_policy = setup.publisher_policy;
99 path_changed = setup.path_changed;
100 loader_optimization = setup.loader_optimization;
101 disallow_binding_redirects = setup.disallow_binding_redirects;
102 disallow_code_downloads = setup.disallow_code_downloads;
104 _activationArguments = setup._activationArguments;
105 domain_initializer = setup.domain_initializer;
106 domain_initializer_args = setup.domain_initializer_args;
107 application_trust = setup.application_trust;
108 disallow_appbase_probe = setup.disallow_appbase_probe;
109 configuration_bytes = setup.configuration_bytes;
114 public AppDomainSetup (ActivationArguments activationArguments)
116 _activationArguments = activationArguments;
119 public AppDomainSetup (ActivationContext activationContext)
121 _activationArguments = new ActivationArguments (activationContext);
125 static string GetAppBase (string appBase)
130 int len = appBase.Length;
131 if (len >= 8 && appBase.ToLower ().StartsWith ("file://")) {
132 appBase = appBase.Substring (7);
133 if (Path.DirectorySeparatorChar != '/')
134 appBase = appBase.Replace ('/', Path.DirectorySeparatorChar);
135 if (Environment.IsRunningOnWindows) {
136 // Under Windows prepend "//" to indicate it's a local file
137 appBase = "//" + appBase;
142 // under 1.x the ":" gets a special treatment - but it doesn't make sense outside Windows
143 } else if (!Environment.IsRunningOnWindows || (appBase.IndexOf (':') == -1)) {
145 appBase = Path.GetFullPath (appBase);
151 public string ApplicationBase {
152 get { return GetAppBase (application_base); }
153 set { application_base = value; }
156 public string ApplicationName {
158 return application_name;
161 application_name = value;
165 public string CachePath {
174 public string ConfigurationFile {
176 if (configuration_file == null)
178 if (Path.IsPathRooted(configuration_file))
179 return configuration_file;
180 if (ApplicationBase == null)
181 throw new MemberAccessException("The ApplicationBase must be set before retrieving this property.");
182 return Path.Combine(ApplicationBase, configuration_file);
185 configuration_file = value;
189 public bool DisallowPublisherPolicy {
191 return publisher_policy;
194 publisher_policy = value;
198 public string DynamicBase {
200 if (dynamic_base == null)
203 if (Path.IsPathRooted (dynamic_base))
206 if (ApplicationBase == null)
207 throw new MemberAccessException ("The ApplicationBase must be set before retrieving this property.");
209 return Path.Combine (ApplicationBase, dynamic_base);
212 if (application_name == null)
213 throw new MemberAccessException ("ApplicationName must be set before the DynamicBase can be set.");
214 uint id = (uint) application_name.GetHashCode ();
215 dynamic_base = Path.Combine (value, id.ToString("x"));
219 public string LicenseFile {
224 license_file = value;
228 [MonoTODO ("In Mono this is controlled by the --share-code flag")]
229 public LoaderOptimization LoaderOptimization {
231 return loader_optimization;
234 loader_optimization = value;
238 public string PrivateBinPath {
240 return private_bin_path;
243 private_bin_path = value;
248 public string PrivateBinPathProbe {
250 return private_bin_path_probe;
253 private_bin_path_probe = value;
258 public string ShadowCopyDirectories {
260 return shadow_copy_directories;
263 shadow_copy_directories = value;
267 public string ShadowCopyFiles {
269 return shadow_copy_files;
272 shadow_copy_files = value;
277 public bool DisallowBindingRedirects {
279 return disallow_binding_redirects;
282 disallow_binding_redirects = value;
286 public bool DisallowCodeDownload {
288 return disallow_code_downloads;
291 disallow_code_downloads = value;
297 public ActivationArguments ActivationArguments {
298 get { return _activationArguments; }
299 set { _activationArguments = value; }
302 [MonoLimitation ("it needs to be invoked within the created domain")]
303 public AppDomainInitializer AppDomainInitializer {
304 get { return domain_initializer; }
305 set { domain_initializer = value; }
308 [MonoLimitation ("it needs to be used to invoke the initializer within the created domain")]
309 public string [] AppDomainInitializerArguments {
310 get { return domain_initializer_args; }
311 set { domain_initializer_args = value; }
314 [MonoNotSupported ("This property exists but not considered.")]
315 public ApplicationTrust ApplicationTrust {
316 get { return application_trust; }
317 set { application_trust = value; }
320 [MonoNotSupported ("This property exists but not considered.")]
321 public bool DisallowApplicationBaseProbing {
322 get { return disallow_appbase_probe; }
323 set { disallow_appbase_probe = value; }
326 [MonoNotSupported ("This method exists but not considered.")]
327 public byte [] GetConfigurationBytes ()
329 return configuration_bytes != null ? configuration_bytes.Clone () as byte [] : null;
332 [MonoNotSupported ("This method exists but not considered.")]
333 public void SetConfigurationBytes (byte [] bytes)
335 configuration_bytes = bytes;