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

AppContext.TargetFrameworkName differs between CoreRT and CoreCLR #23101

Closed
danmoseley opened this issue Aug 8, 2017 · 6 comments
Closed

AppContext.TargetFrameworkName differs between CoreRT and CoreCLR #23101

danmoseley opened this issue Aug 8, 2017 · 6 comments
Assignees
Labels
area-System.Runtime bug help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@danmoseley
Copy link
Member

dotnet/coreclr#13266 (review)

In CoreCLR, AppContext.TargetFrameworkName will always return null. On CoreRT/ProjectN, it will return attribute value from main exe https://github.com/dotnet/corert/blob/ff7eba504516fa0bc0a50357ad559c19b45d1d51/src/System.Private.CoreLib/src/System/AppContext.cs#L45

If we are OK with updating CoreCLR, we return return Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName; from AppDomainSetup.TargetFrameworkName

this will cause AppContext to parse ".NETCoreApp,Version=v2.0" and have an identifier and version instead of empty/null as it currently has and I don't know what that will do downstream.

@danmoseley
Copy link
Member Author

@AlexGhiondea is this a type you have context on? It's the Core equivalent of Quirking? Should we take this change?

@clairernovotny
Copy link
Member

clairernovotny commented Aug 13, 2017

This would be very useful, as there's no current reliable way at runtime to get the currently executing framework and version.

Created a new issue for this https://github.com/dotnet/corefx/issues/23197

@AlexGhiondea
Copy link
Contributor

@danmosemsft the AppContext type is primarily used for quirking but has also a few other uses.

On CoreCLR we don't return null. We actually look at AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName.

On CoreCLR I am not sure we want to read the value from the main exe as a) there might not be an entry assembly and b) the host can choose to put a different TFM on the default AppDomain.

/cc @jkotas

@jkotas
Copy link
Member

jkotas commented Jan 25, 2018

We should return value from the TargetFrameworkName attribute in CoreCLR, I think. It is one line change - copy the implementation from CoreRT:

        public static string TargetFrameworkName => Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName;

@Anipik
Copy link
Contributor

Anipik commented Jul 5, 2018

@jkotas I tried this change. But still the value being returned in the Corefx Tests is null. Currently Debugging to get more info

@Anipik Anipik self-assigned this Jul 5, 2018
@danmoseley
Copy link
Member Author

This is because xunit.console.netcore.exe is the entrypoint assembly for your test and it is missing the attribute. I assume it does work when you do "dotnet.exe myapp.dll" as myapp.dll is the entrypoint assembly and should have it.
For testing purposes I would either update the xunit exe's or better still use RemoteInvoke(), adding the TargetFrameworkAttribute manually into https://github.com/dotnet/corefx/blob/master/src/Common/tests/System/Diagnostics/RemoteExecutorConsoleApp/AssemblyAttributes.cs if you need to

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime bug help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests

6 participants