-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add SingleFileUnsupportedAttribute #45705
Comments
Tagging subscribers to this area: @agocke, @vitek-karas Issue DetailsBackground and MotivationThere are different APIs that are unusable in single-file applications (see https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file). This attribute's intent to help us mark methods that are single-file unfriendly so that tools can better reason about them (see #44488.) Proposed APInamespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false, AllowMultiple = false)]
public sealed class SingleFileUnsupportedAttribute : Attribute
{
public SingleFileUnsupportedAttribute(string message)
{
Message = message;
}
public string Message { get; }
public string Url { get; set; }
}
} Usage ExamplesThis attribute should be used to annotate single-file unfriendly methods: namespace System.Reflection
{
public abstract partial class Assembly : ICustomAttributeProvider, ISerializable
{
...
- public virtual string Location => throw NotImplemented.ByDesign;
+ public virtual string Location
+ {
+ [SingleFileUnsupported("Always returns an empty string for single-file apps",
+ "<url pointing to a docs page with more information and different options on how to deal with this>")]
+ get { throw NotImplemented.ByDesign; }
+ }
...
+ [SingleFileUnsupported("Throws IOException for single-file apps", "<url>"]
public virtual FileStream? GetFile(string name) { throw NotImplemented.ByDesign; }
...
}
} RisksNone. With this attribute we expect to better inform users whenever they make use of incompatible methods in their single-file apps.
|
Is there any proposal/design about how are we planning to improve user experience for form factors which have restrictions on existing APIs? Unless we want to create an attribute for every combination it'd be better to model the design on feature which is more complex. That could be for example reflection emit for pure AOT or COM. |
What kind of broader feature design were you thinking of? A more general attribute like, [RequiresPlatformCapability(PlatformCapability.SingleFile)] for example? |
@terrajobst has a more broad design for capability annotations here: dotnet/designs#111. When we were discussing |
I was thinking about more end-to-end design with variations of needs coming from different features. More comprehensive proposal covering
|
Let me draw out the bounds of this discussion, since I think there are fewer degrees of freedom than are perceived. Let's say that the goal is to provide a way to mark an API as requiring a capability, and having a separate API that can detect that capability, but at a higher level of abstraction. The bounds then are:
I believe all designs would be variants of this specification. The open questions I see are:
|
I think we could try to go beyond that. It'd be great to use the same approach to annotate APIs which have different behaviour based on other factors. I listed a few earlier but one can see such capabilities to be useful even for configurable options like
Using attributes is one thing and interpreting them is a different thing. As we learnt with platform compatibility attribute it's better to design from begging for intersections and exclusions. /cc @jeffhandley |
I've created a PR with a design doc in the linker to explain a little more what we want to do with the attribute (dotnet/linker#1681). It should also serve as a good place to settle the answers to why this approach and not others (still missing in the doc). |
@terrajobst I believe this API is ready for review. If you wanted to consider broadened support I think one of my other proposals touches on the same problem |
Should we consider aligning with the |
Hmm, doesn't read very well to me. |
@terrajobst Did you want to sound off on the platform capability design and how it could fold into single-file analysis? I laid out some options in #45705 (comment). |
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = false)]
public sealed class SingleFileUnsupportedAttribute : Attribute
{
public SingleFileUnsupportedAttribute();
public string DiagnosticId { get; set; }
public string UrlFormat { get; set; }
}
} |
I don't agree with this. The primary reason to have the message is so that the annotated code can provide a domain specific feedback. For example DI frameworks:
We're trying to model this attribute to be similar to the
I agree that calling it "Unsupported" doesn't feel right. I like the This kind of goes into the discussion of: Do we want to treat Xamarin.Android apps as single-file apps as well? And what about most native-AOT apps (iOS, CoreRT), those are technically also single-file... Even Blazor is single-file-like to some extent. |
This sounds like it's based off of our decision making for Obsolete, but after thinking about it I'm not sure it's applicable to this scenario. @terrajobst let's set up a quick meeting to discuss trade-offs here. |
What about naming it |
I do like the idea of aligning with the Requires naming pattern as suggested by @MichalStrehovsky and @vitek-karas for this and future similar properties. What about
I agree. It is not clear what "original" refers to. E.g. is it assembly binary before trimming and/or R2R? |
I like the consistency of My general framing would be: the structure of |
After some discussion with @agocke and @vitek-karas we agreed to this API shape instead: namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Constructor |
AttributeTargets.Event |
AttributeTargets.Method |
AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
public sealed class RequiresAssemblyFilesAttribute : Attribute
{
public RequiresAssemblyFilesAttribute();
public string Message { get; set; }
public string Url { get; set; }
}
} @dotnet/fxdc, please yell if you see any concerns. |
Why |
This was intentional. A relatively common confusion is that the attribute talks about the entire application - not about any single assembly. So we wanted to make it a bit clearer that it's a statement about "multiple assemblies" (as in assemblies in the application). |
Background and Motivation
There are different APIs that are unusable in single-file applications (see https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file). This attribute's intent to help us mark methods that are single-file unfriendly so that tools can better reason about them (see #44488.)
As a first step after adding this attribute to the runtime (if approved) we intend to annotate the following APIs inside the runtime libraries:
Assembly.Location
,Module.FullyQualifiedName
,Module.Name
,Assembly.GetFile
,Assembly.GetFiles
,Assembly.CodeBase
,Assembly.EscapedCodeBase
,AssemblyName.CodeBase
,AssemblyName.EscapedCodeBase
.Proposed API
Usage Examples
This attribute should be used to annotate single-file unfriendly methods:
Risks
None. With this attribute we expect to better inform users whenever they make use of incompatible methods in their single-file apps.
The text was updated successfully, but these errors were encountered: