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

Mark Assembly.GetCallingAssembly with [RequiresDynamicCode]. #71973

Closed

Conversation

teo-tsirpanis
Copy link
Contributor

Fixes #71290
Fixes #53825

I added [RequiresDynamicCode] to Assembly.GetDynamicAssembly across all runtimes, and also marked all APIs that use it. The only uses of it in non-test code are AssemblyBuilder.DefineDynamicAssembly which obviously is already marked, and some APIs in Microsoft.VisualBasic.Core (c.c. @cston).

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jul 11, 2022
@ghost
Copy link

ghost commented Jul 11, 2022

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #71290
Fixes #53825

I added [RequiresDynamicCode] to Assembly.GetDynamicAssembly across all runtimes, and also marked all APIs that use it. The only uses of it in non-test code are AssemblyBuilder.DefineDynamicAssembly which obviously is already marked, and some APIs in Microsoft.VisualBasic.Core (c.c. @cston).

Author: teo-tsirpanis
Assignees: -
Labels:

area-System.Reflection, new-api-needs-documentation

Milestone: -

@@ -329,6 +330,7 @@ public enum FileAttribute
Directory = 16,
Archive = 32,
}
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The FileSystem module is not supported in AOT environments. Use members of the System.IO namespace instead.")]
[Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute]
public sealed partial class FileSystem
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Many but not all APIs of this class use GetCallingAssembly (some did call it only in debug asserts) but I didn't bother and marked the whole class. This class is very outdated either way.

@MichalStrehovsky
Copy link
Member

I wanted to comment when I saw the original issue but I forgot. I don't know if we have the right way to annotate this.

RequiresDynamicCode means we need to generate native code at runtime.

The problem here is different:

  • On WASM, we are not allowed to do stack walk because the platform forbids it. We don't know who's the caller because of that.
  • On NativeAOT, we can strip metadata about code that doesn't need it. We can do a stack walk, but we still might not know what MethodBase the code is associated with. It's kind of a trimming problem. It's just the trimming can be a lot more aggressive for native code. The more appropriate would be RequiresUnreferencedCode, but even that one is not exact.

I don't know what the right solution is. I'm just having a bit doubts about this one.

@jkotas
Copy link
Member

jkotas commented Jul 12, 2022

The next best option would be to mark this API obsolete. dotnet/csharplang#4984 would be required for that to have viable replacement.

@buyaa-n
Copy link
Member

buyaa-n commented Jul 12, 2022

Sounds like could use combination of RequiresUnreferencedCode and UnsupportedOSPlatform("browser")

@MichalStrehovsky
Copy link
Member

Sounds like could use combination of RequiresUnreferencedCode and UnsupportedOSPlatform("browser")

Unfortunately WASM not supporting stackwalks is more nuanced - it works when we're running interpreter because we're not using the WASM execution stack. It doesn't work when the code was AOT'd.

I would really love it if we could just obsolete this API and not have this problem :/.

@buyaa-n
Copy link
Member

buyaa-n commented Jul 20, 2022

Thanks all, as we don't want to fix the issue this way closing the PR

@buyaa-n buyaa-n closed this Jul 20, 2022
@teo-tsirpanis teo-tsirpanis deleted the get-calling-assembly-rdc branch July 20, 2022 16:26
@ghost ghost locked as resolved and limited conversation to collaborators Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Reflection community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation
Projects
None yet
4 participants