unoplatform/uno · error · InvalidOperationException

The configuration property must be provided

Error message

The configuration property must be provided

What it means

The NativeCtors generator reads the MSBuild 'Configuration' property (Debug/Release) to decide hot-reload codegen. GetMSBuildPropertyValue returns null when the property is unset, which the generator treats as invalid and throws InvalidOperationException. MSBuild normally defines Configuration, so a null usually indicates the generator ran outside a normal build.

Source

Thrown at src/SourceGenerators/Uno.UI.SourceGenerators/NativeCtor/NativeCtorsGenerator.cs:55

			private readonly INamedTypeSymbol? _jniHandleOwnershipSymbol;
			private readonly INamedTypeSymbol?[] _javaCtorParams;
			private readonly string _configuration;
			private readonly bool _isDebug;
			private readonly bool _isHotReloadEnabled;

			public SerializationMethodsGenerator(GeneratorExecutionContext context)
			{
				_context = context;

				_iosViewSymbol = context.Compilation.GetTypeByMetadataName("UIKit.UIView");
				_objcNativeHandleSymbol = context.Compilation.GetTypeByMetadataName("ObjCRuntime.NativeHandle");
				_androidViewSymbol = context.Compilation.GetTypeByMetadataName("Android.Views.View");
				_intPtrSymbol = context.Compilation.GetTypeByMetadataName("System.IntPtr");
				_jniHandleOwnershipSymbol = context.Compilation.GetTypeByMetadataName("Android.Runtime.JniHandleOwnership");
				_javaCtorParams = new[] { _intPtrSymbol, _jniHandleOwnershipSymbol };

				_configuration = context.GetMSBuildPropertyValue("Configuration")
					?? throw new InvalidOperationException("The configuration property must be provided");

				_isDebug = string.Equals(_configuration, "Debug", StringComparison.OrdinalIgnoreCase);

				if (bool.TryParse(context.GetMSBuildPropertyValue("UnoForceHotReloadCodeGen"), out var isHotReloadEnabled))
				{
					_isHotReloadEnabled = isHotReloadEnabled;
				}
				else
				{
					_isHotReloadEnabled = _isDebug;
				}
			}

			public override void VisitNamedType(INamedTypeSymbol type)
			{
				_context.CancellationToken.ThrowIfCancellationRequested();

				foreach (var t in type.GetTypeMembers())

View on GitHub (pinned to 0418340488)

Solutions

  1. Build through dotnet/MSBuild which always sets Configuration (Debug by default).
  2. If driving the generator programmatically, pass Configuration via generatorOptions/MSBuildProperties or AnalyzerConfigOptions.
  3. Pass it explicitly on the command line: dotnet build -p:Configuration=Debug.

Example fix

# before
dotnet build # Configuration unset by custom host
# after
dotnet build -p:Configuration=Debug
Defensive patterns

Strategy: validation

Validate before calling

// Ensure Configuration is defined before building
dotnet build -p:Configuration=Debug
// or, in a custom host, seed GeneratorOptions MSBuildProperties["Configuration"] = "Debug"

Prevention

When it happens

Trigger: The source generator executes in a context where the Configuration MSBuild property is not set (null), e.g. driven directly by a Roslyn driver or a test harness that did not seed global properties.

Common situations: Unit-testing the generator with a bare CSharpGeneratorDriver; a stripped custom build host; an MSBuild invocation that cleared Configuration.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/0b09c85678a04155. Report an issue: GitHub.