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

Commit 479d7ed

Browse files
sdmacleajkotas
authored andcommitted
Remove create assembly name (#24154)
* Remove RuntimeAssembly.CreateAssemblyName Fixes #24135 CreateAssemblyName was not compatible with AssemblyLoadContext isolation. Assembly.Load(string) Assembly.LoadWithPartialName(string) Activator.CreateInstance(...) * Remove unused AssemblyNameNative::Init arguments * Temp disable corefx CreateInstanceAssemblyResolve
1 parent a8d5756 commit 479d7ed

File tree

8 files changed

+34
-74
lines changed

8 files changed

+34
-74
lines changed

src/System.Private.CoreLib/shared/System/Activator.RuntimeType.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,9 @@ public static partial class Activator
112112
}
113113
else
114114
{
115-
RuntimeAssembly? assemblyFromResolveEvent;
116-
AssemblyName assemblyName = RuntimeAssembly.CreateAssemblyName(assemblyString, out assemblyFromResolveEvent);
117-
if (assemblyFromResolveEvent != null)
118-
{
119-
// Assembly was resolved via AssemblyResolve event
120-
assembly = assemblyFromResolveEvent;
121-
}
122-
else if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime)
115+
AssemblyName assemblyName = new AssemblyName(assemblyString);
116+
117+
if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime)
123118
{
124119
// WinRT type - we have to use Type.GetType
125120
type = Type.GetType(typeName + ", " + assemblyString, true /*throwOnError*/, ignoreCase);

src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -199,25 +199,6 @@ public static Assembly GetAssembly(Type type)
199199

200200
public static Assembly Load(byte[] rawAssembly) => Load(rawAssembly, rawSymbolStore: null);
201201

202-
[Obsolete("This method has been deprecated. Please use Assembly.Load() instead. https://go.microsoft.com/fwlink/?linkid=14202")]
203-
public static Assembly LoadWithPartialName(string partialName)
204-
{
205-
if (partialName == null)
206-
throw new ArgumentNullException(nameof(partialName));
207-
208-
if ((partialName.Length == 0) || (partialName[0] == '\0'))
209-
throw new ArgumentException(SR.Format_StringZeroLength, nameof(partialName));
210-
211-
try
212-
{
213-
return Load(partialName);
214-
}
215-
catch (FileNotFoundException)
216-
{
217-
return null;
218-
}
219-
}
220-
221202
// Loads the assembly with a COFF based IMAGE containing
222203
// an emitted assembly. The assembly is loaded into a fully isolated ALC with resolution fully deferred to the AssemblyLoadContext.Default.
223204
// The second parameter is the raw bytes representing the symbol store that matches the assembly.

src/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
#nullable enable
6+
using System.IO;
67
using System.Runtime.CompilerServices;
78
using System.Runtime.InteropServices;
89
using System.Runtime.Loader;
@@ -22,6 +23,27 @@ public static Assembly Load(string assemblyString)
2223
return RuntimeAssembly.InternalLoad(assemblyString, ref stackMark, AssemblyLoadContext.CurrentContextualReflectionContext);
2324
}
2425

26+
[Obsolete("This method has been deprecated. Please use Assembly.Load() instead. https://go.microsoft.com/fwlink/?linkid=14202")]
27+
[System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
28+
public static Assembly? LoadWithPartialName(string partialName)
29+
{
30+
if (partialName == null)
31+
throw new ArgumentNullException(nameof(partialName));
32+
33+
if ((partialName.Length == 0) || (partialName[0] == '\0'))
34+
throw new ArgumentException(SR.Format_StringZeroLength, nameof(partialName));
35+
36+
try
37+
{
38+
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
39+
return RuntimeAssembly.InternalLoad(partialName, ref stackMark, AssemblyLoadContext.CurrentContextualReflectionContext);
40+
}
41+
catch (FileNotFoundException)
42+
{
43+
return null;
44+
}
45+
}
46+
2547
// Locate an assembly by its name. The name can be strong or
2648
// weak. The assembly is loaded into the domain of the caller.
2749
[System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod

src/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public AssemblyName(string assemblyName)
2222
throw new ArgumentException(SR.Format_StringZeroLength);
2323

2424
_name = assemblyName;
25-
nInit(out RuntimeAssembly? dummy, false);
25+
nInit();
2626
}
2727

2828
internal AssemblyName(string? name,
@@ -49,7 +49,7 @@ internal AssemblyName(string? name,
4949
}
5050

5151
[MethodImpl(MethodImplOptions.InternalCall)]
52-
internal extern void nInit(out RuntimeAssembly? assembly, bool raiseResolveEvent);
52+
internal extern void nInit();
5353

5454
// This call opens and closes the file, but does not add the
5555
// assembly to the domain.

src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -306,38 +306,11 @@ public override IList<CustomAttributeData> GetCustomAttributesData()
306306

307307
internal static RuntimeAssembly InternalLoad(string assemblyString, ref StackCrawlMark stackMark, AssemblyLoadContext? assemblyLoadContext = null)
308308
{
309-
RuntimeAssembly? assembly;
310-
AssemblyName an = CreateAssemblyName(assemblyString, out assembly);
311-
312-
if (assembly != null)
313-
{
314-
// The assembly was returned from ResolveAssemblyEvent
315-
return assembly;
316-
}
309+
AssemblyName an = new AssemblyName(assemblyString);
317310

318311
return InternalLoadAssemblyName(an, ref stackMark, assemblyLoadContext);
319312
}
320313

321-
// Creates AssemblyName. Fills assembly if AssemblyResolve event has been raised.
322-
internal static AssemblyName CreateAssemblyName(
323-
string assemblyString,
324-
out RuntimeAssembly? assemblyFromResolveEvent)
325-
{
326-
if (assemblyString == null)
327-
throw new ArgumentNullException(nameof(assemblyString));
328-
329-
if ((assemblyString.Length == 0) ||
330-
(assemblyString[0] == '\0'))
331-
throw new ArgumentException(SR.Format_StringZeroLength);
332-
333-
AssemblyName an = new AssemblyName();
334-
335-
an.Name = assemblyString;
336-
an.nInit(out assemblyFromResolveEvent, true);
337-
338-
return an;
339-
}
340-
341314
internal static RuntimeAssembly InternalLoadAssemblyName(AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext? assemblyLoadContext = null)
342315
{
343316
#if FEATURE_APPX

src/vm/assemblyname.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ FCIMPL1(Object*, AssemblyNameNative::GetPublicKeyToken, Object* refThisUNSAFE)
149149
FCIMPLEND
150150

151151

152-
FCIMPL3(void, AssemblyNameNative::Init, Object * refThisUNSAFE, OBJECTREF * pAssemblyRef, CLR_BOOL fRaiseResolveEvent)
152+
FCIMPL1(void, AssemblyNameNative::Init, Object * refThisUNSAFE)
153153
{
154154
FCALL_CONTRACT;
155155

@@ -158,8 +158,6 @@ FCIMPL3(void, AssemblyNameNative::Init, Object * refThisUNSAFE, OBJECTREF * pAss
158158

159159
HELPER_METHOD_FRAME_BEGIN_1(pThis);
160160

161-
*pAssemblyRef = NULL;
162-
163161
if (pThis == NULL)
164162
COMPlusThrow(kNullReferenceException, W("NullReference_This"));
165163

@@ -174,19 +172,6 @@ FCIMPL3(void, AssemblyNameNative::Init, Object * refThisUNSAFE, OBJECTREF * pAss
174172
{
175173
spec.AssemblyNameInit(&pThis,NULL);
176174
}
177-
else if ((hr == FUSION_E_INVALID_NAME) && fRaiseResolveEvent)
178-
{
179-
Assembly * pAssembly = GetAppDomain()->RaiseAssemblyResolveEvent(&spec);
180-
181-
if (pAssembly == NULL)
182-
{
183-
EEFileLoadException::Throw(&spec, hr);
184-
}
185-
else
186-
{
187-
*((OBJECTREF *) (&(*pAssemblyRef))) = pAssembly->GetExposedObject();
188-
}
189-
}
190175
else
191176
{
192177
ThrowHR(hr);

src/vm/assemblyname.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AssemblyNameNative
2323
static FCDECL1(Object*, ToString, Object* refThisUNSAFE);
2424
static FCDECL1(Object*, GetPublicKeyToken, Object* refThisUNSAFE);
2525
static FCDECL1(Object*, EscapeCodeBase, StringObject* filenameUNSAFE);
26-
static FCDECL3(void, Init, Object * refThisUNSAFE, OBJECTREF * pAssemblyRef, CLR_BOOL fRaiseResolveEvent);
26+
static FCDECL1(void, Init, Object * refThisUNSAFE);
2727
};
2828

2929
#endif // _AssemblyName_H

tests/CoreFX/CoreFX.issues.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,10 @@
14031403
"name": "System.Tests.VersionTests.Comparisons_NullArgument_ThrowsArgumentNullException",
14041404
"reason": "Version was improved to no longer throw from comparison operators"
14051405
},
1406+
{
1407+
"name" : "System.Tests.ActivatorNetcoreTests.CreateInstanceAssemblyResolve",
1408+
"reason" : "Waiting for https://github.com/dotnet/corefx/pull/37080"
1409+
}
14061410
]
14071411
}
14081412
},

0 commit comments

Comments
 (0)