本文整理汇总了C#中System.AppDomainSetup.SetCompatibilitySwitches方法的典型用法代码示例。如果您正苦于以下问题:C# AppDomainSetup.SetCompatibilitySwitches方法的具体用法?C# AppDomainSetup.SetCompatibilitySwitches怎么用?C# AppDomainSetup.SetCompatibilitySwitches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.AppDomainSetup
的用法示例。
在下文中一共展示了AppDomainSetup.SetCompatibilitySwitches方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareDataForSetup
[System.Security.SecurityCritical] // auto-generated
private static object PrepareDataForSetup(String friendlyName,
AppDomainSetup setup,
Evidence providedSecurityInfo,
Evidence creatorsSecurityInfo,
IntPtr parentSecurityDescriptor,
string sandboxName,
string[] propertyNames,
string[] propertyValues)
{
byte[] serializedEvidence = null;
bool generateDefaultEvidence = false;
#if FEATURE_CAS_POLICY
// serialize evidence
EvidenceCollection evidenceCollection = null;
if (providedSecurityInfo != null || creatorsSecurityInfo != null)
{
// If we're just passing through AppDomain.CurrentDomain.Evidence, and that evidence is just
// using the standard runtime AppDomainEvidenceFactory, don't waste time serializing it and
// deserializing it back -- instead, we can recreate a new AppDomainEvidenceFactory in the new
// domain. We only want to do this if there is no HostSecurityManager, otherwise the
// HostSecurityManager could have added additional evidence on top of our standard factory.
HostSecurityManager hsm = CurrentDomain.DomainManager != null ? CurrentDomain.DomainManager.HostSecurityManager : null;
bool hostMayContributeEvidence = hsm != null &&
hsm.GetType() != typeof(HostSecurityManager) &&
(hsm.Flags & HostSecurityManagerOptions.HostAppDomainEvidence) == HostSecurityManagerOptions.HostAppDomainEvidence;
if (!hostMayContributeEvidence)
{
if (providedSecurityInfo != null &&
providedSecurityInfo.IsUnmodified &&
providedSecurityInfo.Target != null &&
providedSecurityInfo.Target is AppDomainEvidenceFactory)
{
providedSecurityInfo = null;
generateDefaultEvidence = true;
}
if (creatorsSecurityInfo != null &&
creatorsSecurityInfo.IsUnmodified &&
creatorsSecurityInfo.Target != null &&
creatorsSecurityInfo.Target is AppDomainEvidenceFactory)
{
creatorsSecurityInfo = null;
generateDefaultEvidence = true;
}
}
}
if ((providedSecurityInfo != null) ||
(creatorsSecurityInfo != null)) {
evidenceCollection = new EvidenceCollection();
evidenceCollection.ProvidedSecurityInfo = providedSecurityInfo;
evidenceCollection.CreatorsSecurityInfo = creatorsSecurityInfo;
}
if (evidenceCollection != null) {
serializedEvidence =
CrossAppDomainSerializer.SerializeObject(evidenceCollection).GetBuffer();
}
#endif // FEATURE_CAS_POLICY
AppDomainInitializerInfo initializerInfo = null;
if (setup!=null && setup.AppDomainInitializer!=null)
initializerInfo=new AppDomainInitializerInfo(setup.AppDomainInitializer);
// will travel x-Ad, drop non-agile data
AppDomainSetup newSetup = new AppDomainSetup(setup, false);
#if FEATURE_CORECLR
// Remove the special AppDomainCompatSwitch entries from the set of name value pairs
// And add them to the AppDomainSetup
//
// This is only supported on CoreCLR through ICLRRuntimeHost2.CreateAppDomainWithManager
// Desktop code should use System.AppDomain.CreateDomain() or
// System.AppDomainManager.CreateDomain() and add the flags to the AppDomainSetup
List<String> compatList = new List<String>();
if(propertyNames!=null && propertyValues != null)
{
for (int i=0; i<propertyNames.Length; i++)
{
if(String.Compare(propertyNames[i], "AppDomainCompatSwitch", StringComparison.OrdinalIgnoreCase) == 0)
{
compatList.Add(propertyValues[i]);
propertyNames[i] = null;
propertyValues[i] = null;
}
}
if (compatList.Count > 0)
{
newSetup.SetCompatibilitySwitches(compatList);
}
}
#endif // FEATURE_CORECLR
return new Object[]
{
//.........这里部分代码省略.........
示例2: TestPreLoader_AppDomain
/// <summary>
/// Pre-loads a test into the correct app domain for the current loader mode.
/// </summary>
/// <param name="test"></param>
/// <param name="paths"></param>
void TestPreLoader_AppDomain(ReliabilityTest test, string[] paths)
{
AppDomain ad = null;
try
{
if (curTestSet.AppDomainLoaderMode != AppDomainLoaderMode.RoundRobin || test.CustomAction == CustomActionType.LegacySecurityPolicy)
{
string appDomainName = AppDomain.CurrentDomain.FriendlyName + "_" + "TestDomain_" + test.Assembly + "_" + Guid.NewGuid().ToString();
logger.WriteToInstrumentationLog(curTestSet, LoggingLevels.AppDomain, "Creating app domain: " + appDomainName + " for " + test.Index.ToString());
AppDomainSetup ads = new AppDomainSetup();
Evidence ev = AppDomain.CurrentDomain.Evidence;
if (test.CustomAction == CustomActionType.LegacySecurityPolicy)
{
ads.SetCompatibilitySwitches(new string[] { "NetFx40_LegacySecurityPolicy" });
ev = new Evidence(new EvidenceBase[] { new Zone(System.Security.SecurityZone.MyComputer) }, null);
}
// Set the probing scope for assemblies to %BVT_ROOT%. The default is %BVT_ROOT%\Stress\CLRCore,
// which causes some tests to fail because their assemblies are out of scope.
ads.ApplicationBase = "file:///" + Environment.GetEnvironmentVariable("BVT_ROOT").Replace(@"\", "/");
ads.PrivateBinPath = "file:///" + Environment.GetEnvironmentVariable("BASE_ROOT").Replace(@"\", "/");
ad = AppDomain.CreateDomain(appDomainName, ev, ads);
}
else
{
ad = _testDomains[test.AppDomainIndex];
}
AssemblyName an = new AssemblyName();
Object ourObj = null;
test.AppDomain = ad;
object obj = ad.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(LoaderClass).FullName);
LoaderClass lfc = obj as LoaderClass;
if (test.SuppressConsoleOutput)
lfc.SuppressConsole();
if (test.Assembly.ToLower().IndexOf(".exe") == -1 && test.Assembly.ToLower().IndexOf(".dll") == -1) // must be a simple name or fullname...
{
lfc.Load(test.Assembly, paths, this);
}
else // has an executable extension, must be in local directory.
{
lfc.LoadFrom(test.BasePath + test.Assembly, paths, this);
}
// check and see if this test is marked as requiring STA. We only do
// the check once, and then we set the STA/MTA/Unknown bit on the test attributes
// to avoid doing reflection every time we start the test.
if ((test.TestAttrs & TestAttributes.RequiresThread) == TestAttributes.None)
{
ApartmentState state = lfc.CheckMainForThreadType();
switch (state)
{
case ApartmentState.STA:
test.TestAttrs |= TestAttributes.RequiresSTAThread;
break;
case ApartmentState.MTA:
test.TestAttrs |= TestAttributes.RequiresMTAThread;
break;
case ApartmentState.Unknown:
test.TestAttrs |= TestAttributes.RequiresUnknownThread;
break;
}
}
ourObj = lfc.GetTest();
// and now call the register method on the type if it's one of our supported test types.
if (ourObj is ISingleReliabilityTest)
{
((ISingleReliabilityTest)ourObj).Register();
}
else if (ourObj is IMultipleReliabilityTest)
{
((IMultipleReliabilityTest)ourObj).Register();
}
else if (!(ourObj is string)) // we were unable to find a test here - a string is an executable filename.
{
Interlocked.Decrement(ref LoadingCount);
return;
}
test.TestObject = ourObj;
test.MyLoader = lfc;
}
catch (Exception)
{
// if we took an exception while loading the test, but we still have an app domain
//.........这里部分代码省略.........
示例3: GetAppDomainSetup
private AppDomainSetup GetAppDomainSetup(bool legacyCasEnabled) {
var setup = new AppDomainSetup();
if (legacyCasEnabled) {
setup.SetCompatibilitySwitches(new[] { "NetFx40_LegacySecurityPolicy" });
}
return setup;
}
示例4: SetNetFx40LegacySecurityPolicy
private static void SetNetFx40LegacySecurityPolicy(AppDomainSetup setup)
{
List<string> switches = new List<string> { "NetFx40_LegacySecurityPolicy" };
setup.SetCompatibilitySwitches(switches);
}
示例5: PrepareDataForSetup
// Used to switch into other AppDomain and call SetupRemoteDomain.
// We cannot simply call through the proxy, because if there
// are any remoting sinks registered, they can add non-mscorlib
// objects to the message (causing an assembly load exception when
// we try to deserialize it on the other side)
private static object PrepareDataForSetup(String friendlyName,
AppDomainSetup setup,
Evidence providedSecurityInfo,
Evidence creatorsSecurityInfo,
IntPtr parentSecurityDescriptor,
string sandboxName,
string[] propertyNames,
string[] propertyValues)
{
byte[] serializedEvidence = null;
bool generateDefaultEvidence = false;
AppDomainInitializerInfo initializerInfo = null;
if (setup!=null && setup.AppDomainInitializer!=null)
initializerInfo=new AppDomainInitializerInfo(setup.AppDomainInitializer);
// will travel x-Ad, drop non-agile data
AppDomainSetup newSetup = new AppDomainSetup(setup, false);
// Remove the special AppDomainCompatSwitch entries from the set of name value pairs
// And add them to the AppDomainSetup
//
// This is only supported on CoreCLR through ICLRRuntimeHost2.CreateAppDomainWithManager
// Desktop code should use System.AppDomain.CreateDomain() or
// System.AppDomainManager.CreateDomain() and add the flags to the AppDomainSetup
List<String> compatList = new List<String>();
if(propertyNames!=null && propertyValues != null)
{
for (int i=0; i<propertyNames.Length; i++)
{
if(String.Compare(propertyNames[i], "AppDomainCompatSwitch", StringComparison.OrdinalIgnoreCase) == 0)
{
compatList.Add(propertyValues[i]);
propertyNames[i] = null;
propertyValues[i] = null;
}
}
if (compatList.Count > 0)
{
newSetup.SetCompatibilitySwitches(compatList);
}
}
return new Object[]
{
friendlyName,
newSetup,
parentSecurityDescriptor,
generateDefaultEvidence,
serializedEvidence,
initializerInfo,
sandboxName,
propertyNames,
propertyValues
};
} // PrepareDataForSetup
示例6: IsCompatibilitySwitchSet
public void IsCompatibilitySwitchSet ()
{
Assert.Throws<ArgumentNullException> (delegate {
AppDomain.CurrentDomain.IsCompatibilitySwitchSet (null);
}, "null");
Assert.IsFalse ((bool) AppDomain.CurrentDomain.IsCompatibilitySwitchSet (String.Empty), "Empty");
// defined in SL4 RC documentation
Assert.IsFalse ((bool) AppDomain.CurrentDomain.IsCompatibilitySwitchSet ("NetFx40_Legacy20SortingBehavior"), "NetFx40_Legacy20SortingBehavior");
// defined in FX4 beta documentation
Assert.IsFalse ((bool) AppDomain.CurrentDomain.IsCompatibilitySwitchSet ("NetFx40_LegacySecurityPolicy"), "NetFx40_LegacySecurityPolicy");
Assert.IsFalse ((bool) AppDomain.CurrentDomain.IsCompatibilitySwitchSet ("NetFx40_TimeSpanLegacyFormatMode"), "NetFx40_TimeSpanLegacyFormatMode");
// undefined
Assert.IsFalse ((bool) AppDomain.CurrentDomain.IsCompatibilitySwitchSet ("MONO"), "undefined");
// we can set compatibility switches on an AppDomainSetup but we
// can't associate it with the current domain so they get ignored
AppDomainSetup ads = new AppDomainSetup ();
try {
ads.SetCompatibilitySwitches (new[] { "MONO" });
Assert.IsFalse ((bool) AppDomain.CurrentDomain.IsCompatibilitySwitchSet ("MONO"), "undefined");
}
finally {
ads.SetCompatibilitySwitches (null);
}
}