Skip to content

Commit

Permalink
Return empty string in InternalAssemblyBuilder.Location (#57396)
Browse files Browse the repository at this point in the history
Return empty string in AssemblyBuilder.Location
  • Loading branch information
pedrobsaila committed Aug 20, 2021
1 parent 4cb2874 commit 56d881f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public override FileStream[] GetFiles(bool getResourceModules)
throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
}

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

[RequiresAssemblyFiles(ThrowingMessageInRAF)]
public override string? CodeBase => throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public sealed partial class AssemblyBuilder : Assembly
{
[RequiresAssemblyFiles(ThrowingMessageInRAF)]
public override string? CodeBase => throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
public override string Location => throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
public override string Location => string.Empty;
public override MethodInfo? EntryPoint => null;
public override bool IsDynamic => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Xunit;

namespace System.Reflection.Emit.Tests
Expand Down Expand Up @@ -424,7 +423,17 @@ void Invoke_Private_SameAssembly_ThrowsMethodAccessException()
Assert.Throws<MethodAccessException>(() => d ());
}

[Fact]
public void DefineDynamicAssembly_AssemblyBuilderLocationIsEmpty_InternalAssemblyBuilderLocationIsEmpty()
{
AssemblyBuilder assembly = Helpers.DynamicAssembly(nameof(DefineDynamicAssembly_AssemblyBuilderLocationIsEmpty_InternalAssemblyBuilderLocationIsEmpty));
Assembly internalAssemblyBuilder = AppDomain.CurrentDomain.GetAssemblies()
.FirstOrDefault(a => a.FullName == assembly.FullName);

Assert.Empty(assembly.Location);
Assert.NotNull(internalAssemblyBuilder);
Assert.Empty(internalAssemblyBuilder.Location);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.IO;
using System.Reflection.Emit;
using System.Runtime.Loader;
using Xunit;

Expand Down Expand Up @@ -30,13 +29,6 @@ public void LoadFromStream_Location_IsEmpty()
Assert.Empty(assembly.Location);
}

[Fact]
public void DynamicAssembly_Location_ThrowsNotSupportedException()
{
AssemblyBuilder builder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("dynamic"), AssemblyBuilderAccess.Run);
Assert.Throws<NotSupportedException>(() => builder.Location);
}

[Fact]
public void EntryPoint()
{
Expand Down

0 comments on commit 56d881f

Please sign in to comment.