Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return empty string in InternalAssemblyBuilder.Location #57396

Merged
merged 7 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -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 @@ -3,7 +3,7 @@

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

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

[Fact]
public void DefineDynamicAssembly_InternalAssemblyLocationIsEmpty()
{
AssemblyBuilder assembly = Helpers.DynamicAssembly();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
AssemblyBuilder assembly = Helpers.DynamicAssembly();
AssemblyBuilder assembly = Helpers.DynamicAssembly(nameof(DefineDynamicAssembly_InternalAssemblyLocationIsEmpty));

Otherwise the assembly will get a default name TestAssembly and the test might succeed by accident if some other test uses the same assembly name. (Unlikely as the test would still likely do the right validation, but still)

Assembly internalAssemblyBuilder = AssemblyLoadContext.Default.Assemblies
.FirstOrDefault(_ => _.FullName == assembly.FullName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.FirstOrDefault(_ => _.FullName == assembly.FullName);
.FirstOrDefault(a => a.FullName == assembly.FullName);

Don't use _ for a variable name if you are actually going to use the variable. _ is used when you want to ignore the variable/return value.


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

}
}