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

Experimental CoreRT support #1476

Closed
jmacato opened this issue Apr 6, 2018 · 45 comments
Closed

Experimental CoreRT support #1476

jmacato opened this issue Apr 6, 2018 · 45 comments

Comments

@jmacato
Copy link
Member

jmacato commented Apr 6, 2018

We will be tracking here all of the relevant info regarding AvaloniaUI's compile and runtime compatibility with CoreRT.

@jmacato
Copy link
Member Author

jmacato commented Apr 6, 2018

Current Progress

Our sample app (courtesy of @wieslawsoltes) compiles successfully with some warnings on Windows, Linux CoreRT builds however are not fully tested due to MIT Kerberos library DSO's not being detected in Ubuntu by the ILCompiler.

On runtime however, we encountered a fatal exception regarding BooleanConverter in System.ComponentModel.TypeConverter namespace.

@jmacato jmacato changed the title Experimental .NET Native/CoreRT support Experimental CoreRT support Apr 6, 2018
@wieslawsoltes
Copy link
Collaborator

Exception when trying to run compiled executable:

Exception has been thrown by the target of an invocation.
   at Core2D.Avalonia!<BaseAddress>+0x1d4678
   at Core2D.Avalonia!<BaseAddress>+0x16d01a
   at Core2D.Avalonia!<BaseAddress>+0x95559
   at Core2D.Avalonia!<BaseAddress>+0x30590d
   at Portable.Xaml.Schema.XamlTypeInvoker.<>c__DisplayClass18_0.<CreateAddDelegate>b__0(Object, Object) + 0x4c
   at Portable.Xaml.Schema.XamlTypeInvoker.AddToCollection(Object, Object) + 0x12a
   at Portable.Xaml.XamlObjectWriterInternal.AddToCollectionIfAppropriate(XamlType, XamlMember, Object, Object, Object) + 0xf0
   at Portable.Xaml.XamlObjectWriterInternal.StoreAppropriatelyTypedValue(XamlWriterInternalBase.ObjectState, XamlWriterInternalBase.MemberAndValue, Object, Object) + 0x1c5
   at Portable.Xaml.XamlObjectWriterInternal.OnWriteEndObject() + 0x25b
   at Portable.Xaml.XamlWriterInternalBase.WriteEndObject() + 0x29
   at Portable.Xaml.XamlServices.Transform(XamlReader, XamlWriter, Boolean) + 0x4e
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.LoadFromReader(XamlReader, AvaloniaXamlContext) + 0x33
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Stream, Object, Uri) + 0xb7
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Type, Object) + 0x156
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Object) + 0x4c
   at Avalonia.Controls.AppBuilderBase`1.Setup() + 0xda
   at Core2D.Avalonia!<BaseAddress>+0x88e53c
   at Core2D.Avalonia.App.Main(String[]) + 0x22

Error loading xaml at resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Uri, Uri, Object) + 0x143
   at Avalonia.Markup.Xaml.Styling.StyleInclude.get_Loaded() + 0x3b
   at Avalonia.Markup.Xaml.Styling.StyleInclude.Avalonia.Styling.ISetStyleParent.NotifyResourcesChanged(ResourcesChangedEventArgs) + 0xc
   at Avalonia.Styling.Styles.<.ctor>b__2_0(IStyle) + 0x62
   at Avalonia.Collections.AvaloniaListExtensions.<>c__DisplayClass1_0`1.<ForEachItem>g__Add|0(Int32, IList) + 0x92
   at Avalonia.Collections.AvaloniaList`1.NotifyAdd(IList, Int32) + 0x51
   at Core2D.Avalonia!<BaseAddress>+0x8b1ef8
   at Core2D.Avalonia!<BaseAddress>+0x1d4494

Exception has been thrown by the target of an invocation.
   at Core2D.Avalonia!<BaseAddress>+0x1d4678
   at Core2D.Avalonia!<BaseAddress>+0x16d01a
   at Core2D.Avalonia!<BaseAddress>+0x95559
   at Core2D.Avalonia!<BaseAddress>+0x30590d
   at Portable.Xaml.Schema.XamlTypeInvoker.<>c__DisplayClass18_0.<CreateAddDelegate>b__0(Object, Object) + 0x4c
   at Portable.Xaml.Schema.XamlTypeInvoker.AddToCollection(Object, Object) + 0xbf
   at Portable.Xaml.XamlObjectWriterInternal.AddToCollectionIfAppropriate(XamlType, XamlMember, Object, Object, Object) + 0xf0
   at Portable.Xaml.XamlObjectWriterInternal.StoreAppropriatelyTypedValue(XamlWriterInternalBase.ObjectState, XamlWriterInternalBase.MemberAndValue, Object, Object) + 0x1c5
   at Portable.Xaml.XamlObjectWriterInternal.OnWriteEndObject() + 0x25b
   at Portable.Xaml.XamlWriterInternalBase.WriteEndObject() + 0x29
   at Portable.Xaml.XamlServices.Transform(XamlReader, XamlWriter, Boolean) + 0x4e
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.LoadFromReader(XamlReader, AvaloniaXamlContext) + 0x33
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Stream, Object, Uri) + 0xb7
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Uri, Uri, Object) + 0x84

Error loading xaml at resm:Avalonia.Themes.Default.CheckBox.xaml?assembly=Avalonia.Themes.Default
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Uri, Uri, Object) + 0x143
   at Avalonia.Markup.Xaml.Styling.StyleInclude.get_Loaded() + 0x3b
   at Avalonia.Markup.Xaml.Styling.StyleInclude.Avalonia.Styling.ISetStyleParent.NotifyResourcesChanged(ResourcesChangedEventArgs) + 0xc
   at Avalonia.Styling.Styles.<.ctor>b__2_0(IStyle) + 0x62
   at Avalonia.Collections.AvaloniaListExtensions.<>c__DisplayClass1_0`1.<ForEachItem>g__Add|0(Int32, IList) + 0x92
   at Avalonia.Collections.AvaloniaList`1.NotifyAdd(IList, Int32) + 0x51
   at Core2D.Avalonia!<BaseAddress>+0x8b1ef8
   at Core2D.Avalonia!<BaseAddress>+0x1d4494

Set value of member '{clr-namespace:Avalonia.Styling;assembly=Avalonia.Styling}Setter.Value' threw an exception
   at Portable.Xaml.XamlObjectWriterInternal.SetValue(XamlMember, Object, Object) + 0x8b
   at Portable.Xaml.XamlWriterInternalBase.WriteEndMember() + 0x1e
   at Portable.Xaml.XamlServices.Transform(XamlReader, XamlWriter, Boolean) + 0x4e
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.LoadFromReader(XamlReader, AvaloniaXamlContext) + 0x33
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Stream, Object, Uri) + 0xb7
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Uri, Uri, Object) + 0x84

False is not a valid value for Boolean.
   at System.ComponentModel.BooleanConverter.ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) + 0xcc
   at Avalonia.Markup.Xaml.Converters.SetterValueTypeConverter.ConvertSetterValue(ITypeDescriptorContext, XamlSchemaContext, CultureInfo, Setter, Object) + 0x98
   at Avalonia.Markup.Xaml.PortableXaml.PropertyXamlMember.PropertyInvoker.SetValue(Object, Object) + 0x77
   at Portable.Xaml.XamlObjectWriterInternal.SetValue(XamlMember, Object, Object) + 0x4a

String was not recognized as a valid Boolean.
   at System.Boolean.Parse(ReadOnlySpan`1) + 0x4f
   at System.Boolean.Parse(String) + 0x2c
   at System.ComponentModel.BooleanConverter.ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) + 0x4c

@wieslawsoltes
Copy link
Collaborator

The rd.xml file used:

<Directives>
    <Application>
        <Assembly Name="System.ComponentModel.TypeConverter" Dynamic="Required All" />
        <Assembly Name="Avalonia.Animation" Dynamic="Required All" />
        <Assembly Name="Avalonia.Base" Dynamic="Required All" />
        <Assembly Name="Avalonia.Controls" Dynamic="Required All" />
        <Assembly Name="Avalonia.DesignerSupport" Dynamic="Required All" />
        <Assembly Name="Avalonia.Diagnostics" Dynamic="Required All" />
        <Assembly Name="Avalonia.Input" Dynamic="Required All" />
        <Assembly Name="Avalonia.Interactivity" Dynamic="Required All" />
        <Assembly Name="Avalonia.Layout" Dynamic="Required All" />
        <Assembly Name="Avalonia.Logging.Serilog" Dynamic="Required All" />
        <Assembly Name="Avalonia.Visuals" Dynamic="Required All" />
        <Assembly Name="Avalonia.Styling" Dynamic="Required All" />
        <Assembly Name="Avalonia.Themes.Default" Dynamic="Required All" />
        <Assembly Name="Avalonia.Markup" Dynamic="Required All" />
        <Assembly Name="Avalonia.Markup.Xaml" Dynamic="Required All" />
        <Assembly Name="Avalonia.DotNetCoreRuntime" Dynamic="Required All" />
        <Assembly Name="Avalonia.Win32" Dynamic="Required All" />
        <Assembly Name="Avalonia.Direct2D1" Dynamic="Required All" />
        <Assembly Name="Avalonia.Skia" Dynamic="Required All" />
        <Assembly Name="Avalonia.Gtk3" Dynamic="Required All" />
        <Assembly Name="Avalonia.MonoMac" Dynamic="Required All" />
        <Assembly Name="Core2D.Avalonia" Dynamic="Required All" />
        <Assembly Name="Newtonsoft.Json" Dynamic="Required All" />
        <Assembly Name="mscorlib" Dynamic="Required All" />
        <Assembly Name="System.Memory" Dynamic="Required All" />
        <Assembly Name="System.Runtime" Dynamic="Required All" />
    </Application>
</Directives>

@danwalmsley
Copy link
Member

I got past this by not doing -c Release

@danwalmsley
Copy link
Member

danwalmsley commented Apr 6, 2018

I'm having a further issue now with it not finding:

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. 
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. 
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. 
---> Portable.Xaml.XamlObjectWriterException: Set value of member '{clr-namespace:Avalonia.Controls;assembly=Avalonia.Controls}LayoutTransformControl.LayoutTransform' threw an exception 
---> EETypeRva:0x01654448: This object cannot be invoked because it was metadata-enabled for browsing only: 'System.Action<System.Object,System.EventArgs>.Invoke(System.Object,System.EventArgs)' For more information, please visit  http://go.microsoft.com/fwlink/?LinkID=616867

@danwalmsley
Copy link
Member

need to add

<Assembly Name="System.Private.CoreLib">
            <Type Name="System.Action`2[System.Object,System.EventArgs]`"> 
            <Method Name="Invoke" Dynamic="Required All" />
            </Type>
        </Assembly>

@danwalmsley
Copy link
Member

Method '[System.Drawing.Common]System.Drawing.UnsafeNativeMethods.IntGetDC(HandleRef)' requires non-trivial marshalling that is not yet supported by this compiler.
   at System.Drawing.UnsafeNativeMethods.IntGetDC(HandleRef) + 0x35
   at System.Drawing.UnsafeNativeMethods.GetDC(HandleRef) + 0x16
   at System.Drawing.Icon.Initialize(Int32, Int32) + 0x200
   at System.Drawing.Icon..ctor(Stream, Int32, Int32) + 0xe2
   at System.Drawing.Icon..ctor(Stream) + 0x24
   at Avalonia.Win32.Win32Platform.CreateIconImpl(Stream) + 0x38
   at Avalonia.Win32.Win32Platform.LoadIcon(Stream) + 0x20
   at Avalonia.Controls.WindowIcon..ctor(Stream) + 0x6b
   at Avalonia.Markup.Xaml.Converters.IconTypeConverter.CreateIconFromPath(ITypeDescriptorContext, String) + 0x131
   at Avalonia.Markup.Xaml.Converters.IconTypeConverter.ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) + 0x53
   at Portable.Xaml.XamlObjectWriterInternal.GetCorrectlyTypedValue(XamlMember, XamlType, Object) + 0x4e8

@danwalmsley
Copy link
Member

If you don't use Window Icons that doesn't happen (Windows only AFAIK)

@jmacato
Copy link
Member Author

jmacato commented Apr 7, 2018

Native build of Core2D running
@wieslawsoltes has successfully compiled and ran a native build (in debug configuration) of Draw2D with all features working (according to the author) thanks in part from the help given by @jkoritzinsky & @danwalmsley .

Generic types and reflection in general were not working in CoreRT. And due to a yet-to-find bug in either AvaloniaUI or CoreRT, we can't publish native builds in Release configuration as of the time when this progress report was written.

@wieslawsoltes
Copy link
Collaborator

I have disabled default theme, the error is still there in release publish.

Exception has been thrown by the target of an invocation.
   at Core2D.Avalonia!<BaseAddress>+0x8cc778
   at Core2D.Avalonia!<BaseAddress>+0x9111d4
   at Core2D.Avalonia.App.Main(String[]) + 0x22

Exception has been thrown by the target of an invocation.
   at Core2D.Avalonia!<BaseAddress>+0x1c0a5c
   at Core2D.Avalonia!<BaseAddress>+0x152f4e
   at Core2D.Avalonia!<BaseAddress>+0x8b2f1
   at Core2D.Avalonia!<BaseAddress>+0x6f5f2f
   at Core2D.Avalonia!<BaseAddress>+0x93f35
   at Portable.Xaml.XamlObjectWriterInternal.InitializeObjectIfRequired(Boolean, Boolean) + 0x362
   at Portable.Xaml.XamlObjectWriterInternal.OnWriteStartObject() + 0x8a
   at Portable.Xaml.XamlServices.Transform(XamlReader, XamlWriter, Boolean) + 0x4e
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.LoadFromReader(XamlReader, AvaloniaXamlContext) + 0x33
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Stream, Object, Uri) + 0xb7
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Type, Object) + 0x156
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Object) + 0x4c
   at Core2D.Avalonia.MainWindow..ctor() + 0x26
   at Core2D.Avalonia!<BaseAddress>+0x8cc6c3

Could not convert object 'False' (of type System.String) to {http://schemas.microsoft.com/winfx/2006/xaml}Boolean: False is not a valid value for Boolean.
   at Portable.Xaml.XamlObjectWriterInternal.GetCorrectlyTypedValue(XamlMember, XamlType, Object) + 0x3b1
   at Portable.Xaml.XamlObjectWriterInternal.StoreAppropriatelyTypedValue(XamlWriterInternalBase.ObjectState, XamlWriterInternalBase.MemberAndValue, Object, Object) + 0x1fa
   at Portable.Xaml.XamlObjectWriterInternal.OnWriteValue(Object) + 0x73
   at Portable.Xaml.XamlServices.Transform(XamlReader, XamlWriter, Boolean) + 0x4e
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.LoadFromReader(XamlReader, AvaloniaXamlContext) + 0x33
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Stream, Object, Uri) + 0xb7
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Type, Object) + 0x156
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Object) + 0x4c
   at Core2D.Avalonia.Views.MainView..ctor() + 0x5b
   at Core2D.Avalonia!<BaseAddress>+0xaa66bd
   at Core2D.Avalonia!<BaseAddress>+0x1c08c1

False is not a valid value for Boolean.
   at System.ComponentModel.BooleanConverter.ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) + 0xcc
   at Portable.Xaml.XamlObjectWriterInternal.GetCorrectlyTypedValue(XamlMember, XamlType, Object) + 0x26f

String was not recognized as a valid Boolean.
   at System.Boolean.Parse(ReadOnlySpan`1) + 0x4f
   at System.Boolean.Parse(String) + 0x2c
   at System.ComponentModel.BooleanConverter.ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) + 0x4c

@wieslawsoltes
Copy link
Collaborator

wieslawsoltes commented Apr 7, 2018

Managed to run partial control catalog using release publish.

Code: https://github.com/wieslawsoltes/Avalonia/tree/ef8f19c82dada5a5055e739c22bf1c3931192d54

From command-line in Avalonia\samples\ControlCatalog.NetCore directory:

dotnet publish -c Release -r win-x64 -o bin/win-x64-release -v m

copy %UserProfile%\.nuget\packages\skiasharp\1.57.1\runtimes\win7-x64\native\libSkiaSharp.dll

.\bin\win-x64-release\ControlCatalog.NetCore.exe

2018-04-07_18-30-07

@wieslawsoltes
Copy link
Collaborator

wieslawsoltes commented Apr 7, 2018

So my current finding is that setting Boolean property IsEnabled="False" on e.g. Button control in Xaml causes exceptions in release publish.

Could not convert object 'False' (of type System.String) to {http://schemas.microsoft.com/winfx/2006/xaml}Boolean: False is not a valid value for Boolean.
   at Portable.Xaml.XamlObjectWriterInternal.GetCorrectlyTypedValue(XamlMember, XamlType, Object) + 0x3b1
   at Portable.Xaml.XamlObjectWriterInternal.StoreAppropriatelyTypedValue(XamlWriterInternalBase.ObjectState, XamlWriterInternalBase.MemberAndValue, Object, Object) + 0x1fa
   at Portable.Xaml.XamlObjectWriterInternal.OnWriteValue(Object) + 0x73
   at Portable.Xaml.XamlServices.Transform(XamlReader, XamlWriter, Boolean) + 0x4e
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.LoadFromReader(XamlReader, AvaloniaXamlContext) + 0x33
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Stream, Object, Uri) + 0xb7
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Type, Object) + 0x156
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Object) + 0x4c
   at ControlCatalog.NetCore!<BaseAddress>+0xa2e8a5
   at ControlCatalog.NetCore!<BaseAddress>+0x1c1f55

False is not a valid value for Boolean.
   at System.ComponentModel.BooleanConverter.ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) + 0xcc
   at Portable.Xaml.XamlObjectWriterInternal.GetCorrectlyTypedValue(XamlMember, XamlType, Object) + 0x26f

String was not recognized as a valid Boolean.
   at System.Boolean.Parse(ReadOnlySpan`1) + 0x4f
   at System.Boolean.Parse(String) + 0x2c
   at System.ComponentModel.BooleanConverter.ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) + 0x4c
Could not convert object 'false' (of type System.String) to {http://schemas.microsoft.com/winfx/2006/xaml}Boolean: false is not a valid value for Boolean.
   at Portable.Xaml.XamlObjectWriterInternal.GetCorrectlyTypedValue(XamlMember, XamlType, Object) + 0x3b1
   at Portable.Xaml.XamlObjectWriterInternal.StoreAppropriatelyTypedValue(XamlWriterInternalBase.ObjectState, XamlWriterInternalBase.MemberAndValue, Object, Object) + 0x1fa
   at Portable.Xaml.XamlObjectWriterInternal.OnWriteValue(Object) + 0x73
   at Portable.Xaml.XamlServices.Transform(XamlReader, XamlWriter, Boolean) + 0x4e
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.LoadFromReader(XamlReader, AvaloniaXamlContext) + 0x33
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Stream, Object, Uri) + 0xb7
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Type, Object) + 0x156
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Object) + 0x4c
   at ControlCatalog.NetCore!<BaseAddress>+0xa2e8a5
   at ControlCatalog.NetCore!<BaseAddress>+0x1c1f55

false is not a valid value for Boolean.
   at System.ComponentModel.BooleanConverter.ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) + 0xcc
   at Portable.Xaml.XamlObjectWriterInternal.GetCorrectlyTypedValue(XamlMember, XamlType, Object) + 0x26f

String was not recognized as a valid Boolean.
   at System.Boolean.Parse(ReadOnlySpan`1) + 0x4f
   at System.Boolean.Parse(String) + 0x2c
   at System.ComponentModel.BooleanConverter.ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) + 0x4c

@wieslawsoltes
Copy link
Collaborator

So it seems the issue is with System.ComponentModel.BooleanConverter.

Avalonia\src\Markup\Avalonia.Markup.Xaml\PortableXaml\portable.xaml.github\src\Portable.Xaml\Portable.Xaml\XamlObjectWriter.cs

value = tc.ConvertFrom(service_provider, CultureInfo.InvariantCulture, value);

@jmacato
Copy link
Member Author

jmacato commented Apr 8, 2018

This issue is blocked by dotnet/corert#5661

@jmacato
Copy link
Member Author

jmacato commented Apr 9, 2018

The issue of Native Compilation in linux is fixed with dotnet/corert#5663. We'll just have to wait for a new ILCompiler package to be released

@jmacato
Copy link
Member Author

jmacato commented Apr 9, 2018

Tested Avalonia app (the plain avalonia.mvvm template) and it has compiled successfully in linux (Ubuntu 16.04); unfortunately, an issue with DLLImport loading has prevented Avalonia.Gtk from starting. (relevant issue in CoreRT: dotnet/corert#5664)

@jmacato
Copy link
Member Author

jmacato commented Apr 12, 2018

image
Avalonia is now running natively in linux! (Kubuntu 16.04)

@jmacato
Copy link
Member Author

jmacato commented Apr 12, 2018

image

Core2D on Kubuntu 16.04

@jmacato
Copy link
Member Author

jmacato commented Apr 12, 2018

tracking dotnet/corert#5690 and dotnet/corert#5691

@wieslawsoltes
Copy link
Collaborator

This bug dotnet/corert#5661 got closed today, I think this version includes fixes: https://dotnet.myget.org/feed/dotnet-core/package/nuget/Microsoft.DotNet.ILCompiler/1.0.0-alpha-26413-01
Still getting error:

Error loading xaml at resm:Avalonia.Themes.Default.CheckBox.xaml?assembly=Avalonia.Themes.Default
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Uri, Uri, Object) + 0x143
   at Avalonia.Markup.Xaml.Styling.StyleInclude.get_Loaded() + 0x3b
   at Avalonia.Markup.Xaml.Styling.StyleInclude.Avalonia.Styling.ISetStyleParent.NotifyResourcesChanged(ResourcesChangedEventArgs) + 0xc
   at Avalonia.Styling.Styles.<.ctor>b__2_0(IStyle) + 0x62
   at Avalonia.Collections.AvaloniaListExtensions.<>c__DisplayClass1_0`1.<ForEachItem>g__Add|0(Int32, IList) + 0x92
   at Avalonia.Collections.AvaloniaList`1.NotifyAdd(IList, Int32) + 0x51
   at Core2D.Avalonia!<BaseAddress>+0x93c69c
   at Core2D.Avalonia!<BaseAddress>+0x1c2e1c
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1f
   at Core2D.Avalonia!<BaseAddress>+0x421581
   at Core2D.Avalonia!<BaseAddress>+0x459cf1
   at System.Linq.Expressions.Interpreter.LightLambda.RunVoid(Object[]) + 0x7a
   at Core2D.Avalonia!<BaseAddress>+0x7252e8
   at Portable.Xaml.Schema.XamlTypeInvoker.AddToCollection(Object, Object) + 0xbf
   at Portable.Xaml.XamlObjectWriterInternal.AddToCollectionIfAppropriate(XamlType, XamlMember, Object, Object, Object) + 0xf0
   at Portable.Xaml.XamlObjectWriterInternal.StoreAppropriatelyTypedValue(XamlWriterInternalBase.ObjectState, XamlWriterInternalBase.MemberAndValue, Object, Object) + 0x1c5
   at Portable.Xaml.XamlObjectWriterInternal.OnWriteEndObject() + 0x25b
   at Portable.Xaml.XamlWriterInternalBase.WriteEndObject() + 0x29
   at Portable.Xaml.XamlServices.Transform(XamlReader, XamlWriter, Boolean) + 0x4e
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.LoadFromReader(XamlReader, AvaloniaXamlContext) + 0x33
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Stream, Object, Uri) + 0xb7
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Uri, Uri, Object) + 0x84

Set value of member '{clr-namespace:Avalonia.Styling;assembly=Avalonia.Styling}Setter.Value' threw an exception
   at Portable.Xaml.XamlObjectWriterInternal.SetValue(XamlMember, Object, Object) + 0x8b
   at Portable.Xaml.XamlWriterInternalBase.WriteEndMember() + 0x1e
   at Portable.Xaml.XamlServices.Transform(XamlReader, XamlWriter, Boolean) + 0x4e
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.LoadFromReader(XamlReader, AvaloniaXamlContext) + 0x33
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Stream, Object, Uri) + 0xb7
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Uri, Uri, Object) + 0x84

False is not a valid value for Boolean.
   at System.ComponentModel.BooleanConverter.ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) + 0xcc
   at Avalonia.Markup.Xaml.Converters.SetterValueTypeConverter.ConvertSetterValue(ITypeDescriptorContext, XamlSchemaContext, CultureInfo, Setter, Object) + 0xa0
   at Avalonia.Markup.Xaml.PortableXaml.PropertyXamlMember.PropertyInvoker.SetValue(Object, Object) + 0x77
   at Portable.Xaml.XamlObjectWriterInternal.SetValue(XamlMember, Object, Object) + 0x4a

String was not recognized as a valid Boolean.
   at System.Boolean.Parse(ReadOnlySpan`1) + 0x4f
   at System.Boolean.Parse(String) + 0x2c
   at System.ComponentModel.BooleanConverter.ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) + 0x4c

@MichalStrehovsky
Copy link

This bug dotnet/corert#5661 got closed today, I think this version includes fixes

The NuGet package description has the commit SHA in it. The package you're linking to is at commit 753b12932bf934605d40901d5e10c67e1e1a34fd and doesn't include the fix yet. The next package should have it.

@wieslawsoltes
Copy link
Collaborator

Finally managed to run Draw2D app in native release mode using Microsoft.DotNet.ILCompiler 1.0.0-alpha-26413-02:

2018-04-13_20-43-09

@m5x
Copy link

m5x commented Apr 15, 2018

Nice. How big is the executable? Is the startup time reduced significantly?

@wieslawsoltes
Copy link
Collaborator

About 29MB. Start-up time is greatly reduced, almost instant.

@m5x
Copy link

m5x commented Apr 15, 2018

Thanks, that's great to hear. 29MB is also very good result considering the size of standard release build publish binaries is around 80MB. Hopefully it will be even better in the future when CoreRT matures.

@MichalStrehovsky
Copy link

You can likely get to less than 29 MB by tweaking the RD.XML used.

The CoreRT compiler normally starts compilation from the Main() and proceeds generating native code and runtime artifacts for everything that Main() needs. Then it goes looking for dependencies of those dependencies, etc. As a result, the compiler would not normally compile things that are not statically used.

This is a problem if the app uses reflection to find things that are otherwise not used. CoreRT wouldn't compile those things and since there's no JIT (and we don't carry the original IL anyway), the code will fail at runtime.

Using RD.XML to say that everything in all assemblies should be considered used is a relatively quick fix, but comes with a cost - potentially compiling things that really aren't used.

It's possible to tweak RD.XML at a finer granularity (going down to individual types). This might be tedious, but the reward is a smaller executable that only has code and data that is really needed.

@wieslawsoltes
Copy link
Collaborator

Issue while running ControlCatalog.NetCore on xamlil branch:

Unhandled Exception: System.Exception: Method '[Avalonia.Win32]Avalonia.Win32.Interop.UnmanagedMethods.RegisterDragDrop(native int,IDropTarget)' requires non-trivial marshalling that is not yet supported by this compiler.
   at Avalonia.Win32.Interop.UnmanagedMethods.RegisterDragDrop(IntPtr, IDropTarget) + 0x34
   at Avalonia.Win32.OleContext.RegisterDragDrop(IPlatformHandle, IDropTarget) + 0x6c
   at Avalonia.Win32.WindowImpl.CreateDropTarget() + 0x43
   at Avalonia.Controls.TopLevel..ctor(ITopLevelImpl, IAvaloniaDependencyResolver) + 0x1c2
   at Avalonia.Controls.WindowBase..ctor(IWindowBaseImpl, IAvaloniaDependencyResolver) + 0x23
   at Avalonia.Controls.Window..ctor(IWindowImpl) + 0x83
   at ControlCatalog.NetCore.Program.AppMain(Application, String[]) + 0x2d
   at ControlCatalog.NetCore.Program.Main(String[]) + 0x118
   at ControlCatalog.NetCore!<BaseAddress>+0xc566a9

@jkoritzinsky
Copy link
Collaborator

The dialog issue is due to dotnet/corert#4219

@kekekeks
Copy link
Member

We might want to use SharpGenTools for COM interop on Windows. @jkoritzinsky Is it possible to define interfaces without C/C++ header files?

@jkoritzinsky
Copy link
Collaborator

You can manually define them but it’s not exactly pretty. You’d basically be writing the generated code. My suggestion would be for us to make another small project that maps the dialog interfaces from the headers and publishes to NuGet and then consume that library in Avalonia.

@kekekeks
Copy link
Member

We'd need to do that for IDropTarget too. And several other interfaces.
Generating castxml-like XML file from some kind of C# definition and passing it to SharpGenTools would be better, I think.

@Berrysoft
Copy link

I succeeded in compiling my project by CoreRT on Windows and Linux, but failed in Max OS X because of the delegate marshalling here:

field.SetValue(this, Marshal.GetDelegateForFunctionPointer(proc, prop.PropertyType));

And according to this issue, maybe the delegates should be marked with UnmanagedFunctionPointerAttribute.

@maxkatz6
Copy link
Member

I had exception with missing "clrcompression.dll".
Workaround: dotnet/corert#5496 (comment)

@maxkatz6
Copy link
Member

Also need to mention https://github.com/teobugslayer/AvaloniaCoreRTDemo
Sample project and configuration works on Avalonia 0.9 and Avalonia 0.10 (latest master, with workaround for clrcompression.dll)

@FrankenApps
Copy link

FrankenApps commented Oct 21, 2020

Only out of curiosity: Is there any reason why something like this is not implemented yet? It is really the only thing stopping me from compiling my app to CoreRT...

@FoggyFinder
Copy link
Contributor

You can use managed dialogs for now.

@gleblebedev
Copy link

Is it possible to use Avalonia in an old style UWP project?

I have errors like this when I try to build it:
1>C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\microsoft.net.native.compiler\2.2.8-rel-28605-00\tools\Microsoft.NetNative.targets(801,5): error : Field 'XamlIlContext.Context._sp' from assembly 'Avalonia.Themes.Default' was not included in compilation, but was referenced in method 'XamlIlContext.Context.Avalonia.Markup.Xaml.IRootObjectProvider.get_RootObject$PST32()'. There may have been a missing assembly, or a dependency on a more recent Windows SDK release.
1>C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\microsoft.net.native.compiler\2.2.8-rel-28605-00\tools\Microsoft.NetNative.targets(801,5): error : Field 'XamlIlContext.Context._parentStackEnumerable' from assembly 'Avalonia.Themes.Default' was not included in compilation, but was referenced in method 'XamlIlContext.Context.Avalonia.Markup.Xaml.XamlIl.Runtime.IAvaloniaXamlIlParentStackProvider.get_Parents$PST34()'. There may have been a missing assembly, or a dependency on a more recent Windows SDK release.
1>C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\microsoft.net.native.compiler\2.2.8-rel-28605-00\tools\Microsoft.NetNative.targets(801,5): error : Field 'XamlIlContext.Context._baseUri' from assembly 'Avalonia.Themes.Default' was not included in compilation, but was referenced in method 'XamlIlContext.Context.get_BaseUri()'. There may have been a missing assembly, or a dependency on a more recent Windows SDK release.
1>C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\microsoft.net.native.compiler\2.2.8-rel-28605-00\tools\Microsoft.NetNative.targets(801,5): error : Field 'XamlIlContext.Context._innerSp' from assembly 'Avalonia.Themes.Default' was not included in compilation, but was referenced in method 'XamlIlContext.Context.GetService(Type)'. There may have been a missing assembly, or a dependency on a more recent Windows SDK release.

Setting

doesn't help :(

@maxkatz6
Copy link
Member

@gleblebedev we don't officially support embedding Avalonia in UWP because of .NET Native limitations.
Most likely it is possible if you setup ".rd.xml" file correctly, but I don't know if anybody achieved doing it successfully.
CoreRT experiments might help you, but it's not the same as .NET Native.

@gleblebedev
Copy link

FYI: I was able to reduce number of errors from 440+ to only 62 by making all fields in Avalonia.Themes.Default.dll, Avalonia.Themes.Fluent.dll, Avalonia.Dialogs.dll public....

@gleblebedev
Copy link

Ok, I'm at last 20 errors and most of them look like this:

Error Method 'XamlIlHelpers.Avalonia.Data.TemplateBinding,Avalonia.Markup.Converter!Property()' will always throw an exception due to the missing method 'XamlIlHelpers.Avalonia.Data.TemplateBinding,Avalonia.Markup.Converter!Getter(object)' in assembly 'Avalonia.Themes.Default'. There may have been a missing assembly, or a dependency on a more recent Windows SDK release.

Why would the method be missing?

@gleblebedev
Copy link

Actually... making methods public also solves the problem. So I only have 2 errors left, the root one is:

C:\Users\gleb.nuget\packages\microsoft.net.native.compiler\2.2.8-rel-28605-00\tools\Microsoft.NetNative.targets(801,5): error : RHBIND : error RHB0011: Internal error: 'ch == L':'' at 'f:\dd\ndp\rh\src\tools\rhbind\makepdb.cpp:1136'

I guess this one should be reported to the native.compiler. Do you know where it is? Is it https://github.com/dotnet/corert/issues ?

@jkoritzinsky
Copy link
Collaborator

For .NET Native, you need to report on the VS Feedback site: https://developercommunity.visualstudio.com

@gulshan
Copy link

gulshan commented May 16, 2021

This repo is successor to CoreRT I guess-
https://github.com/dotnet/runtimelab/tree/feature/NativeAOT

@jmacato
Copy link
Member Author

jmacato commented Jun 22, 2022

NativeAOT obsoletes this issue, closing now

@jmacato jmacato closed this as completed Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests