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

Mono's RuntimeAssembly.GetName calls CodeBase #54835

Closed
eerhardt opened this issue Jun 28, 2021 · 4 comments · Fixed by #54895
Closed

Mono's RuntimeAssembly.GetName calls CodeBase #54835

eerhardt opened this issue Jun 28, 2021 · 4 comments · Fixed by #54895
Labels
area-VM-reflection-mono Reflection issues specific to MonoVM runtime-mono specific to the Mono runtime
Milestone

Comments

@eerhardt
Copy link
Member

CodeBase is marked as RequiresAssemblyFiles, which means that it can throw an exception if the application is published as a single-file application.

public override AssemblyName GetName(bool copiedName)
{
return AssemblyName.Create(_mono_assembly, CodeBase);
}

We should decide what to do here for Mono. In CoreCLR, we don't call CodeBase directly, but instead we call the underlying GetCodeBase() method, which returns null when running in a single-file application:

// If the assembly is copied before it is loaded, the codebase will be set to the
// actual file loaded if copiedName is true. If it is false, then the original code base
// is returned.
public override AssemblyName GetName(bool copiedName)
{
string? codeBase = GetCodeBase();
var an = new AssemblyName(GetSimpleName(),
GetPublicKey(),
null, // public key token
GetVersion(),
GetLocale(),
GetHashAlgorithm(),
AssemblyVersionCompatibility.SameMachine,
codeBase,
GetFlags() | AssemblyNameFlags.PublicKey);

Maybe we should do the same?

cc @akoeplinger @steveisok

@eerhardt eerhardt added runtime-mono specific to the Mono runtime area-VM-reflection-mono Reflection issues specific to MonoVM labels Jun 28, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jun 28, 2021
@ghost
Copy link

ghost commented Jun 28, 2021

Tagging subscribers to this area:
See info in area-owners.md if you want to be subscribed.

Issue Details

CodeBase is marked as RequiresAssemblyFiles, which means that it can throw an exception if the application is published as a single-file application.

public override AssemblyName GetName(bool copiedName)
{
return AssemblyName.Create(_mono_assembly, CodeBase);
}

We should decide what to do here for Mono. In CoreCLR, we don't call CodeBase directly, but instead we call the underlying GetCodeBase() method, which returns null when running in a single-file application:

// If the assembly is copied before it is loaded, the codebase will be set to the
// actual file loaded if copiedName is true. If it is false, then the original code base
// is returned.
public override AssemblyName GetName(bool copiedName)
{
string? codeBase = GetCodeBase();
var an = new AssemblyName(GetSimpleName(),
GetPublicKey(),
null, // public key token
GetVersion(),
GetLocale(),
GetHashAlgorithm(),
AssemblyVersionCompatibility.SameMachine,
codeBase,
GetFlags() | AssemblyNameFlags.PublicKey);

Maybe we should do the same?

cc @akoeplinger @steveisok

Author: eerhardt
Assignees: -
Labels:

area-System.Reflection-mono, runtime-mono

Milestone: -

@steveisok
Copy link
Member

/cc @lambdageek

@eerhardt
Copy link
Member Author

I needed to suppress the new IL3002 warning from the RequiresAssemblyFiles analyzer in #54741.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jun 29, 2021
@lambdageek
Copy link
Member

Fixed by #54895

lambdageek added a commit to lambdageek/runtime that referenced this issue Jul 1, 2021
It's marked as not available in single file apps.
Call the underlying get_code_base icall.

Fixes dotnet#54835
@lambdageek lambdageek removed the untriaged New issue has not been triaged by the area owner label Jul 6, 2021
@lambdageek lambdageek added this to the 6.0.0 milestone Jul 6, 2021
lambdageek added a commit that referenced this issue Jul 7, 2021
…me (#54895)

* [mono] Don't call Assembly.CodeBase directly in RuntimeAssembly.GetName

   It's marked as not available in single file apps. Call the underlying get_code_base icall.

   Fixes #54835

* [icall] Use MonoImage:filename for RuntimeAssembly.get_code_base

   For bundled asssemblies in single file scenarios, RuntimeAssembly.CodeBase will be null, matching CoreCLR.

* disable codebase test on wasm
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 7, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VM-reflection-mono Reflection issues specific to MonoVM runtime-mono specific to the Mono runtime
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants