Skip to content

Commit 56d881f

Browse files
authored
Return empty string in InternalAssemblyBuilder.Location (#57396)
Return empty string in AssemblyBuilder.Location
1 parent 4cb2874 commit 56d881f

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public override FileStream[] GetFiles(bool getResourceModules)
104104
throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
105105
}
106106

107-
public override string Location => throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
107+
public override string Location => string.Empty;
108108

109109
[RequiresAssemblyFiles(ThrowingMessageInRAF)]
110110
public override string? CodeBase => throw new NotSupportedException(SR.NotSupported_DynamicAssembly);

src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public sealed partial class AssemblyBuilder : Assembly
1010
{
1111
[RequiresAssemblyFiles(ThrowingMessageInRAF)]
1212
public override string? CodeBase => throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
13-
public override string Location => throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
13+
public override string Location => string.Empty;
1414
public override MethodInfo? EntryPoint => null;
1515
public override bool IsDynamic => true;
1616

src/libraries/System.Reflection.Emit/tests/AssemblyBuilderTests.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Collections.Generic;
55
using System.Linq;
6-
using System.Runtime.InteropServices;
76
using Xunit;
87

98
namespace System.Reflection.Emit.Tests
@@ -424,7 +423,17 @@ void Invoke_Private_SameAssembly_ThrowsMethodAccessException()
424423
Assert.Throws<MethodAccessException>(() => d ());
425424
}
426425

426+
[Fact]
427+
public void DefineDynamicAssembly_AssemblyBuilderLocationIsEmpty_InternalAssemblyBuilderLocationIsEmpty()
428+
{
429+
AssemblyBuilder assembly = Helpers.DynamicAssembly(nameof(DefineDynamicAssembly_AssemblyBuilderLocationIsEmpty_InternalAssemblyBuilderLocationIsEmpty));
430+
Assembly internalAssemblyBuilder = AppDomain.CurrentDomain.GetAssemblies()
431+
.FirstOrDefault(a => a.FullName == assembly.FullName);
427432

433+
Assert.Empty(assembly.Location);
434+
Assert.NotNull(internalAssemblyBuilder);
435+
Assert.Empty(internalAssemblyBuilder.Location);
436+
}
428437

429438
}
430439
}

src/libraries/System.Reflection/tests/CoreCLR/AssemblyTests.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.IO;
5-
using System.Reflection.Emit;
65
using System.Runtime.Loader;
76
using Xunit;
87

@@ -30,13 +29,6 @@ public void LoadFromStream_Location_IsEmpty()
3029
Assert.Empty(assembly.Location);
3130
}
3231

33-
[Fact]
34-
public void DynamicAssembly_Location_ThrowsNotSupportedException()
35-
{
36-
AssemblyBuilder builder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("dynamic"), AssemblyBuilderAccess.Run);
37-
Assert.Throws<NotSupportedException>(() => builder.Location);
38-
}
39-
4032
[Fact]
4133
public void EntryPoint()
4234
{

0 commit comments

Comments
 (0)