Skip to content

NET10: AOT => Failed to set the specified COM apartment state. Current apartment state 'MTA'. #119925

@Disidente

Description

@Disidente

Description

Fail with simple GTK4 Test app compiled with AOT in NET10.

In NET9 or via dotnet run with NET10 work fine.

Error creando Gtk.Application: System.InvalidOperationException: Failed to set the specified COM apartment state. Current apartment state 'MTA'.
at System.Threading.Thread.SetApartmentStateUnchecked(ApartmentState, Boolean) + 0x15f
at myProgram.Program.

d__1.MoveNext() + 0xb9

Reproduction Steps

Project.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <AssemblyName>gtk4Test</AssemblyName>
    <PublishAot>true</PublishAot>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="GirCore.Gtk-4.0" Version="0.7.0-preview.2" />
    <PackageReference Include="GirCore.Gio-2.0" Version="0.7.0-preview.2" />
    <PackageReference Include="GirCore.GtkSource-5" Version="0.7.0-preview.2" />
    <PackageReference Include="GirCore.GObject-2.0.Integration" Version="0.7.0-preview.2" />
  </ItemGroup>
  
</Project>  

Program.cs

	[System.STAThread]
        public static void Main(string[] args)
        {
            var application = Gtk.Application.New("org.GirCore.GTK4TestApp", Gio.ApplicationFlags.FlagsNone);
	}

Expected behavior

In NET9 work fine.

Actual behavior

Error creando Gtk.Application: System.InvalidOperationException: Failed to set the specified COM apartment state. Current apartment state 'MTA'.
at System.Threading.Thread.SetApartmentStateUnchecked(ApartmentState, Boolean) + 0x15f
at myProgram.Program.

d__1.MoveNext() + 0xb9

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions