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

Compiler doesn't elaborate environment variable MONO_GC_PARAMS #9701

Open
daniele-calanchi opened this issue Jan 22, 2025 · 8 comments
Open
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@daniele-calanchi
Copy link

daniele-calanchi commented Jan 22, 2025

Android framework version

net9.0-android

Affected platform version

.NET 9.0.101

Description

If i write environment variables in a text file and then add it to project with AndroidEnvironment build action i see a couple of problems:

  • Any variable containing in it's value the character '=' won't get added (Eg: 'MONO_GC_PARAMS=major=marksweep' if i write 'MONO_GC_PARAMS=foo' then no problem)
  • Even if the variables MONO_GC_PARAMS, MONO_LOG_LEVEL or MONO_DEBUG are defined in environment variables file, the app still apply first the default values and then the override ones.

The result is that i cannot set the 'bridge-implementation=new' of the mono garbage collector.

The following are the versions of the tools used:
MacOS 14.6.1
MSBuild version 17.12.12+1cce77968 for .NET
.NET 9.0.101
Android api 35

Steps to Reproduce

  1. Create a new MAUI project, specifically for Android platform
  2. Create a 'Environment.txt' file with content 'MONO_GC_PARAMS=major=marksweep'
  3. Add it to the project with AndroidEnvironment as build action
  4. Set msbuild logs to Diagnostic
  5. Watch in the logs as the app starts that the environment variable is not added

Did you find any workaround?

No response

Relevant log output

Content of the file Environment.txt:
MONO_LOG_LEVEL=debug
MONO_GC_PARAMS=foo
MONO_GC_PARAMS=bridge-implementation=new
MONO_DEBUG=1

Excerpt of the output log of the app:
01-22 17:53:24.743  7877  7877 W monodroid: Creating public update directory: `/data/user/0/com.companyname.mauiapp1/files/.__override__/arm64-v8a`
01-22 17:53:24.743  7877  7877 D monodroid: Mono AOT mode: interp
01-22 17:53:24.743  7877  7877 I monodroid: Setting environment variable 'MONO_GC_PARAMS' to 'major=marksweep-conc'
01-22 17:53:24.743  7877  7877 I monodroid: Setting environment variable 'MONO_LOG_LEVEL' to 'info'
01-22 17:53:24.743  7877  7877 I monodroid: Setting environment variable 'XA_HTTP_CLIENT_HANDLER_TYPE' to 'Xamarin.Android.Net.AndroidMessageHandler'
01-22 17:53:24.743  7877  7877 D monodroid: Loading environment from  override directories.
01-22 17:53:24.743  7877  7877 D monodroid: /data/user/0/com.companyname.mauiapp1/files/.__override__/arm64-v8a/environment
01-22 17:53:24.743  7877  7877 D monodroid: Loading /data/user/0/com.companyname.mauiapp1/files/.__override__/arm64-v8a/environment
01-22 17:53:24.743  7877  7877 D monodroid: Setting environment variable from the override file /data/user/0/com.companyname.mauiapp1/files/.__override__/arm64-v8a/environment: 'MONO_LOG_LEVEL' = 'debug'
01-22 17:53:24.743  7877  7877 D monodroid: Setting environment variable from the override file /data/user/0/com.companyname.mauiapp1/files/.__override__/arm64-v8a/environment: 'MONO_GC_PARAMS' = 'foo'
01-22 17:53:24.743  7877  7877 D monodroid: Setting environment variable from the override file /data/user/0/com.companyname.mauiapp1/files/.__override__/arm64-v8a/environment: 'MONO_DEBUG' = '1'
01-22 17:53:24.743  7877  7877 D monodroid: Setting environment variable from the override file /data/user/0/com.companyname.mauiapp1/files/.__override__/arm64-v8a/environment: '__XA_PACKAGE_NAMING_POLICY__' = 'LowercaseCrc64'
01-22 17:53:24.743  7877  7877 D monodroid: Setting environment variable from the override file /data/user/0/com.companyname.mauiapp1/files/.__override__/arm64-v8a/environment: 'mono.enable_assembly_preload' = '0'
01-22 17:53:24.743  7877  7877 D monodroid: Setting environment variable from the override file /data/user/0/com.companyname.mauiapp1/files/.__override__/arm64-v8a/environment: 'DOTNET_MODIFIABLE_ASSEMBLIES' = 'Debug'
01-22 17:53:24.743  7877  7877 D monodroid: Setting up for DSO lookup in app data directories
01-22 17:53:24.744  7877  7877 D monodroid: Using runtime path: /data/app/~~IbQRxpVI8Y592VNi46z1nA==/com.companyname.mauiapp1-jQ6lwiTQcItXE8NawSeJvQ==/lib/arm64
01-22 17:53:24.744  7877  7877 D monodroid: Probing for Mono AOT mode
01-22 17:53:24.744  7877  7877 D monodroid: Enabling Mono Interpreter
01-22 17:53:24.744  7877  7877 D monodroid: Probing if we should use LLVM
01-22 17:53:24.744  7877  7877 W monodroid: runtime args empty
01-22 17:53:24.744  7877  7877 I monodroid-gc: environment supports jni NewWeakGlobalRef
@daniele-calanchi daniele-calanchi added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Jan 22, 2025
@jonathanpeppers
Copy link
Member

The result is that i cannot set the 'bridge-implementation=new' of the mono garbage collector.

This is the default, do you even need to do this?

@jonathanpeppers jonathanpeppers removed the needs-triage Issues that need to be assigned. label Jan 22, 2025
@jonathanpeppers jonathanpeppers added this to the Under Consideration milestone Jan 22, 2025
@daniele-calanchi
Copy link
Author

i'm experiencing the issue described here https://github.com/dotnet/runtime/issues/106410

[namix.mobileapp] * Assertion at /__w/1/s/src/mono/mono/metadata/sgen-tarjan-bridge.c:1174, condition `xref_count == xref_index' not met, function:processing_build_callback_data, xref_count is 1101 but we added 1096 xrefs

@jonathanpeppers
Copy link
Member

Maybe @grendello knows a way to escape the = sign? Does surrounding the value in quotes help?

MONO_GC_PARAMS="major=marksweep"

@grendello
Copy link
Contributor

It doesn't seem that problem is quoting, rather that the values from the environment file:

MONO_GC_PARAMS=foo
MONO_GC_PARAMS=bridge-implementation=new

are replaced by this code with major=marksweep-conc, which we see in the logs. Looks like the environment parser somehow misses the MONO_GC_PARAMS entry in the environment file when there's an embedded = in the value?

@daniele-calanchi
Copy link
Author

I've tried to check the code in GeneratePackageManagerJava.cs and EnvironmentFilesParser.cs.
I could follow the path it was taking but found no clear problem that would result in the behavior i'm observing

@daniele-calanchi
Copy link
Author

Maybe @grendello knows a way to escape the = sign? Does surrounding the value in quotes help?

MONO_GC_PARAMS="major=marksweep"

I've tried single and double quoting it and even used $([MSBuild]::Unescape()) with unicode values for special chars, but nothing

@daniele-calanchi
Copy link
Author

Could that be a concurrency problem?

@daniele-calanchi
Copy link
Author

daniele-calanchi commented Jan 23, 2025

Sorry, i was in a bit of a rush yesterday.
@grendello Regarding the code you pasted earlier, could it be a concurrency issue in which the file parsed in that moment still doesn't contains my android environment variables?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Projects
None yet
Development

No branches or pull requests

4 participants