Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void FilePathIsPopulatedCorrectly()
private static void MakeAssemblyGetEntryAssemblyReturnNull()
{
typeof(Assembly)
.GetField("s_forceNullEntryPoint", BindingFlags.NonPublic | BindingFlags.Static)
.GetField("s_overriddenEntryAssembly", BindingFlags.NonPublic | BindingFlags.Static)
.SetValue(null, true);

Assert.Null(Assembly.GetEntryAssembly());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void EntryAssemblyName_Null_NotIncludedInTrace()
private static void MakeAssemblyGetEntryAssemblyReturnNull()
{
typeof(Assembly)
.GetField("s_forceNullEntryPoint", BindingFlags.NonPublic | BindingFlags.Static)
.GetField("s_overriddenEntryAssembly", BindingFlags.NonPublic | BindingFlags.Static)
.SetValue(null, true);

Assert.Null(Assembly.GetEntryAssembly());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,31 @@ public override string ToString()
return type.Module?.Assembly;
}

// internal test hook
private static bool s_forceNullEntryPoint;
private static Assembly? s_overriddenEntryAssembly;

/// <summary>
/// Sets the application's entry assembly to the provided assembly object
/// as argument.
/// </summary>
/// <param name="assembly">
/// Assembly object that represents the application's new entry assembly.
/// </param>
/// <remarks>
/// It is important to mention that the assembly passed to this function
/// has to be a RuntimeAssembly type. Otherwise, an exception will be thrown.
/// </remarks>
public static void SetEntryAssembly(Assembly? assembly)
{
if (assembly is not RuntimeAssembly)
throw new ArgumentException(SR.Argument_MustBeRuntimeAssembly);

s_overriddenEntryAssembly = assembly;
}

public static Assembly? GetEntryAssembly()
{
if (s_forceNullEntryPoint)
return null;
if (s_overriddenEntryAssembly is not null)
return s_overriddenEntryAssembly;

return GetEntryAssemblyInternal();
}
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11157,6 +11157,7 @@ public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")]
[System.ObsoleteAttribute("ReflectionOnly loading is not supported and throws PlatformNotSupportedException.", DiagnosticId="SYSLIB0018", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static System.Reflection.Assembly ReflectionOnlyLoadFrom(string assemblyFile) { throw null; }
public static void SetEntryAssembly(System.Reflection.Assembly? assembly) { throw null; }
public override string ToString() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types and members the loaded assembly depends on might be removed")]
public static System.Reflection.Assembly UnsafeLoadFrom(string assemblyFile) { throw null; }
Expand Down