Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 0dcdd0d

Browse files
AlexGhiondeajkotas
authored andcommitted
Allow multiple SetData calls on AppDomain (#11496)
* Allow multiple SetData calls on AppDomain * Remove restriction from GetData and remove now-dead code Locate * Remove LoaderOptimization check since it is not used on CoreCLR
1 parent 3770733 commit 0dcdd0d

File tree

2 files changed

+6
-53
lines changed

2 files changed

+6
-53
lines changed

src/mscorlib/src/System/AppDomain.cs

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -566,17 +566,6 @@ public void SetData(string name, object data)
566566
throw new ArgumentNullException(nameof(name));
567567
Contract.EndContractBlock();
568568

569-
// SetData should only be used to set values that don't already exist.
570-
object currentVal;
571-
lock (((ICollection)LocalStore).SyncRoot)
572-
{
573-
LocalStore.TryGetValue(name, out currentVal);
574-
}
575-
if (currentVal != null)
576-
{
577-
throw new InvalidOperationException(SR.InvalidOperation_SetData_OnlyOnce);
578-
}
579-
580569
lock (((ICollection)LocalStore).SyncRoot)
581570
{
582571
LocalStore[name] = data;
@@ -590,38 +579,14 @@ public Object GetData(string name)
590579
throw new ArgumentNullException(nameof(name));
591580
Contract.EndContractBlock();
592581

593-
int key = AppDomainSetup.Locate(name);
594-
if (key == -1)
595-
{
596-
if (name.Equals(AppDomainSetup.LoaderOptimizationKey))
597-
return FusionStore.LoaderOptimization;
598-
else
599-
{
600-
object data;
601-
lock (((ICollection)LocalStore).SyncRoot)
602-
{
603-
LocalStore.TryGetValue(name, out data);
604-
}
605-
if (data == null)
606-
return null;
607-
return data;
608-
}
609-
}
610-
else
582+
object data;
583+
lock (((ICollection)LocalStore).SyncRoot)
611584
{
612-
// Be sure to call these properties, not Value, so
613-
// that the appropriate permission demand will be done
614-
switch (key)
615-
{
616-
case (int)AppDomainSetup.LoaderInformation.ApplicationBaseValue:
617-
return FusionStore.ApplicationBase;
618-
case (int)AppDomainSetup.LoaderInformation.ApplicationNameValue:
619-
return FusionStore.ApplicationName;
620-
default:
621-
Debug.Assert(false, "Need to handle new LoaderInformation value in AppDomain.GetData()");
622-
return null;
623-
}
585+
LocalStore.TryGetValue(name, out data);
624586
}
587+
if (data == null)
588+
return null;
589+
return data;
625590
}
626591

627592
[Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread. http://go.microsoft.com/fwlink/?linkid=14202", false)]

src/mscorlib/src/System/AppDomainSetup.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -338,18 +338,6 @@ internal static string LoaderOptimizationKey
338338
}
339339
}
340340

341-
static internal int Locate(String s)
342-
{
343-
if (String.IsNullOrEmpty(s))
344-
return -1;
345-
346-
Debug.Assert('A' == ACTAG_APP_BASE_URL[0], "Assumption violated");
347-
if (s[0] == 'A' && s == ACTAG_APP_BASE_URL)
348-
return (int)LoaderInformation.ApplicationBaseValue;
349-
350-
return -1;
351-
}
352-
353341
#if FEATURE_COMINTEROP
354342
public bool SandboxInterop
355343
{

0 commit comments

Comments
 (0)