Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Is CsWinRT compatible with .NET 8 AOT? #1590

Answered by manodasanW
smourier asked this question in Q&A
Discussion options

Hi,

I have this project:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<OutputType>Exe</OutputType>
		<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
		<ImplicitUsings>enable</ImplicitUsings>
		<Nullable>enable</Nullable>
		<PublishAot>true</PublishAot>
		<EnableAotAnalyzer>true</EnableAotAnalyzer>
	</PropertyGroup>
</Project>

And this C# code:

using Windows.Devices.Enumeration;

namespace ConsoleAppAot
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var res = DeviceInformation.FindAllAsync().GetResults();
        }
    }
}

Builds fine but when I run, I get a PlatformNotSupportedException error from WinRT's GuidGenerator:


Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.TypeInitializationException: The type initializer for 'ABI.Windows.Foundation.IAsyncOperation`1' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'Vftbl' threw an exception.
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.TypeInitializationException: The type initializer for 'ABI.System.Collections.Generic.IReadOnlyList`1' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'Vftbl' threw an exception.
 ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Linq.Expressions.Compiler.DelegateHelpers.MakeNewCustomDelegate(Type[] types)
   at System.Linq.Expressions.Compiler.DelegateHelpers.MakeDelegateType(Type[] types)
   at ABI.System.Collections.Generic.IReadOnlyList`1.Vftbl..cctor()
   --- End of inner exception stack trace ---
   at ABI.System.Collections.Generic.IReadOnlyList`1..cctor()
   --- End of inner exception stack trace ---
   at ABI.System.Collections.Generic.IReadOnlyList`1.GetGuidSignature()
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at WinRT.GuidGenerator.GetSignature(Type type)
   at WinRT.GuidGenerator.GetSignature(Type type)
   at WinRT.GuidGenerator.<>c.<GetSignature>b__2_1(Type t)
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.String.Join(String separator, IEnumerable`1 values)
   at WinRT.GuidGenerator.GetSignature(Type type)
   at WinRT.GuidGenerator.CreateIID(Type type)
   at ABI.Windows.Foundation.IAsyncOperation`1.Vftbl..cctor()
   --- End of inner exception stack trace ---
   at ABI.Windows.Foundation.IAsyncOperation`1..cctor()
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   at System.RuntimeFieldHandle.GetValue(RtFieldInfo field, Object instance, RuntimeType fieldType, RuntimeType declaringType, Boolean& domainInitialized)
   at System.Reflection.RtFieldInfo.GetValue(Object obj)
   at WinRT.GuidGenerator.GetIID(Type type)
   at WinRT.IWinRTObject.IsInterfaceImplementedFallback(RuntimeTypeHandle interfaceType, Boolean throwIfNotImplemented)
   at WinRT.IWinRTObject.System.Runtime.InteropServices.IDynamicInterfaceCastable.IsInterfaceImplemented(RuntimeTypeHandle interfaceType, Boolean throwIfNotImplemented)
   at WinRT.ComWrappersSupport.CreateRcwForComObject[T](IntPtr ptr, Boolean tryUseCache)
   at WinRT.ComWrappersSupport.CreateRcwForComObject[T](IntPtr ptr)
   at WinRT.MarshalInspectable`1.FromAbi(IntPtr ptr)
   at WinRT.MarshalInterface`1.FromAbi(IntPtr ptr)
   at ABI.Windows.Devices.Enumeration.IDeviceInformationStaticsMethods.FindAllAsync(IObjectReference _obj)
   at Windows.Devices.Enumeration.DeviceInformation.FindAllAsync()
   at ConsoleAppAot.Program.Main(String[] args) in E:\smo\work\ConsoleApp33\ConsoleAppAot\Program.cs:line 9

image

Is this supposed to work? Am I missing some configuration?

You must be logged in to vote

Our public NuGet packages don't support AOT yet, but it is coming soon. Right now, all changes related to our AOT support are in our staging branch (staging/AOT).

Replies: 1 comment

Comment options

Our public NuGet packages don't support AOT yet, but it is coming soon. Right now, all changes related to our AOT support are in our staging branch (staging/AOT).

You must be logged in to vote
0 replies
Answer selected by smourier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.