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

AOT fails with ABI.System.Threading in 1.6 Experimental #1638

Closed
Gaoyifei1011 opened this issue Jun 12, 2024 · 8 comments
Closed

AOT fails with ABI.System.Threading in 1.6 Experimental #1638

Gaoyifei1011 opened this issue Jun 12, 2024 · 8 comments
Labels
AOT bug Something isn't working
Milestone

Comments

@Gaoyifei1011
Copy link
Contributor

Describe the bug

AOT fails with ABI.System.Threading in 1.6 Experimental

To Reproduce

When Windows App SDK 1.6 Experimental and CsWinRT 2.1.0 were installed at the same time, a source generator error occurred when compiling the program

2>D:\Github\GetStoreApp\GetStoreApp\obj\x64\Debug\net9.0-windows10.0.22621.0\win-x64\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGenericInstantiation.g.cs(3728,33,3728,61): error CS0234: 命名空间“ABI.System”中不存在类型或命名空间名“Threading”(是否缺少程序集引用?)

Expected behavior

Successfully build with CsWinRT 2.1.0 preview and Windows App SDK 1.6 Experimental

Version Info

CsWinRT 2.1.0-preview
.NET SDK 9.0.0-preview4
Windows SDK 10.0.22621.35-preview

Additional context

image
image

@Gaoyifei1011 Gaoyifei1011 added the bug Something isn't working label Jun 12, 2024
@dongle-the-gadget
Copy link
Contributor

Can you make a minimal repro?

@manodasanW manodasanW added the AOT label Jun 12, 2024
@Gaoyifei1011
Copy link
Contributor Author

Can you make a minimal repro?

However, this error doesn't happen when I create a blank template, and I don't know which API is causing it

@manodasanW
Copy link
Member

From the source generator generated files, can you find and provide the generated class that is using ABI.System.Threading and then from that I might be able to figure out the scenario.

@Gaoyifei1011
Copy link
Contributor Author

Gaoyifei1011 commented Jun 15, 2024

From the source generator generated files, can you find and provide the generated class that is using ABI.System.Threading and then from that I might be able to figure out the scenario.

When I jumped to 3728 lines of error referred to in the error message, it showed something that was inconsistent with the error message
WinRTGenericInstantiation.g.cs.txt

image

@manodasanW
Copy link
Member

I see no references to Threading in the attached file which is strange. Instead of manually going to the generated files in VS, if you try double clicking the error message, does it automatically open the generated file and highlight the relevant line. If that doesn't work, another thing to try is set the EmitCompilerGeneratedFiles property is your csproj and then check the generated file in the obj folder and see if that has any references to Threading.

@Gaoyifei1011
Copy link
Contributor Author

EmitCompilerGeneratedFiles

[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
private static unsafe int Do_Abi_get_Value_1(IntPtr thisPtr, IntPtr* __return_value__)
{
    System.Threading.CancellationTokenSource ____return_value__ = default;
    *__return_value__ = default;
    try
    {
        ____return_value__ = global::ABI.System.Collections.Generic.KeyValuePairMethods<string, System.Threading.CancellationTokenSource>.Abi_get_Value_1(thisPtr);
        *__return_value__ = global::ABI.System.Threading.CancellationTokenSource.FromManaged(____return_value__);
    }
    catch (global::System.Exception __exception__)
    {
        global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__);
        return global::WinRT.ExceptionHelpers.GetHRForException(__exception__);
    }
    return 0;
}

WinRTGenericInstantiation.g.cs.txt

image

@Gaoyifei1011
Copy link
Contributor Author

I see no references to Threading in the attached file which is strange. Instead of manually going to the generated files in VS, if you try double clicking the error message, does it automatically open the generated file and highlight the relevant line. If that doesn't work, another thing to try is set the EmitCompilerGeneratedFiles property is your csproj and then check the generated file in the obj folder and see if that has any references to Threading.

Thanks for your reminder, found is missing unexpectedly CancellationTokenSource

@Gaoyifei1011
Copy link
Contributor Author

I see no references to Threading in the attached file which is strange. Instead of manually going to the generated files in VS, if you try double clicking the error message, does it automatically open the generated file and highlight the relevant line. If that doesn't work, another thing to try is set the EmitCompilerGeneratedFiles property is your csproj and then check the generated file in the obj folder and see if that has any references to Threading.

Further, I found that there was a problem with my personal code.
The question comes from
public Dictionary<string,CancellationTokenSource> XXXDict { get; }

The Dictionary generics put in a CancellationTokenSource class and set this property to public, triggering the abi interop generation of winrt aot, which caused the compilation error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AOT bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants