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

Check for Mono runtime #81076

Closed
tmds opened this issue Jan 24, 2023 · 7 comments
Closed

Check for Mono runtime #81076

tmds opened this issue Jan 24, 2023 · 7 comments

Comments

@tmds
Copy link
Member

tmds commented Jan 24, 2023

A lot of code checking for mono runtime does it by seeing the Mono.Runtime type exists.

It is the suggested answer in this stack overflow question and is based on the Mono documentation.

It seems this is not working with the runtime based mono builds. I've tested against 7.0 and main.

When I run:

foreach (var type in new[] { "Mono.Runtime", "Mono.RuntimeStructs" })
{
    Console.WriteLine($"{type}: {Type.GetType(type) != null}");
}

The output is:

Mono.Runtime: False
Mono.RuntimeStructs: True

The check can also be found in .NET sources, for example: aspnetcore, msbuild, nuget, roslyn.

Should the type be re-introduced so this check continues to work?

Should a public API be added to perform this check?

cc @akoeplinger @jkotas @omajid @uweigand

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 24, 2023
@ghost
Copy link

ghost commented Jan 24, 2023

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

Issue Details

A lot of code checking for mono runtime does it by seeing the Mono.Runtime type exists.

It is the suggested answer in this stack overflow question and is based on the Mono documentation.

It seems this is not working with the runtime based mono builds. I've tested against 7.0 and main.

When I run:

foreach (var type in new[] { "Mono.Runtime", "Mono.RuntimeStructs" })
{
    Console.WriteLine($"{type}: {Type.GetType(type) != null}");
}

The output is:

Mono.Runtime: False
Mono.RuntimeStructs: True

The check can also be found in .NET sources, for example: aspnetcore, msbuild, nuget, roslyn.

Should the type be re-introduced so this check continues to work?

Should a public API be added to perform this check?

cc @akoeplinger @jkotas @omajid @uweigand

Author: tmds
Assignees: -
Labels:

untriaged, area-Infrastructure-mono

Milestone: -

@uweigand
Copy link
Contributor

I'm not convinced this would be a good change. .NET using the Mono runtime is a quite different environment from Mono. Most users of those pre-existing checks were likely actually checking for Mono itself. Having them all activated in .NET just because we're using the Mono runtime doesn't look like a good idea to me - we ideally want .NET to behave the same no matter the underlying runtime.

@akoeplinger
Copy link
Member

This was sort of intentional, like @uweigand said the Mono.Runtime type has long been used to check for legacy Mono (.NET Framework-based) so we left it out in dotnet/runtime to make sure code goes into the "modern" codepaths.

The Mono.RuntimeStructs is an alternative if you really need to know it even nowadays.

@tmds
Copy link
Member Author

tmds commented Jan 24, 2023

That makes sense.

Ideally, these runtimes behave the same.
In practice, they don't, which is why we have these checks.

It sounds like the use-case is considered too niche to add a public API.

Anyone looking for code to check for the variants (from BenchmarkDotNet's RuntimeInformation class):

public static bool IsMono { get; } = Type.GetType("Mono.RuntimeStructs") != null;
public static bool IsOldMono { get; } = Type.GetType("Mono.Runtime") != null;
public static bool IsNewMono { get; } = IsMono && !IsOldMono;

@tmds tmds closed this as completed Jan 24, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jan 24, 2023
@stephentoub
Copy link
Member

Ideally, these runtimes behave the same.
In practice, they don't, which is why we have these checks.

What are the differences that are causing you problems?

@tmds
Copy link
Member Author

tmds commented Jan 24, 2023

I still have to create an issue about it in this repo: running a webapp using dotnet run and then pressing Ctrl+C, gives a 143 exit code with Mono runtime, and a 0 exit code with CoreCLR.
Such a check is part of source-build's smoke tests, and it is failing on Mono: dotnet/source-build#3174.

To make the test pass on existing releases, I was looking for a way to check for Mono runtime.

@tmds
Copy link
Member Author

tmds commented Jan 24, 2023

I still have to create an issue about it

I've written up an issue in the sdk repo: #81093.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants