question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to run published Avalonia app

See original GitHub issue

A repro of the issue can be found here

I have a window with an Image control that renders a PNG from Assets folder. When I run the application from visual studio the Image renders fine on the window, but when I publish the dotnet app in Windows OS and run the exe, the application fails to start. I found the issue after doing dotnet Applicationname.dll and got the following exception:

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Portable.Xaml.XamlObjectWriterException: Could not convert object 'resm:DotnetPublishRepro.Assets.logo.png' (of type System.String) to {clr-namespace:Avalonia.Media.Imaging;assembly=Avalonia.Visuals}IBitmap: The type initializer for 'SkiaSharp.SKManagedStream' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SkiaSharp.SKManagedStream' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'libSkiaSharp': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at SkiaSharp.SkiaApi.sk_managedstream_set_delegates(IntPtr pRead, IntPtr pPeek, IntPtr pIsAtEnd, IntPtr pRewind, IntPtr pGetPosition, IntPtr pSeek, IntPtr pMove, IntPtr pGetLength, IntPtr pCreateNew, IntPtr pDestroy)
   at SkiaSharp.SKManagedStream..cctor()
   --- End of inner exception stack trace ---
   at Avalonia.Skia.PlatformRenderInterface.LoadBitmap(Stream stream)
   at Avalonia.Media.Imaging.Bitmap..ctor(Stream stream)
   at Avalonia.Markup.Xaml.Converters.BitmapTypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at Portable.Xaml.XamlObjectWriterInternal.GetCorrectlyTypedValue(XamlMember xm, XamlType xt, Object value)
   --- End of inner exception stack trace ---
   at Portable.Xaml.XamlObjectWriterInternal.GetCorrectlyTypedValue(XamlMember xm, XamlType xt, Object value)
   at Portable.Xaml.XamlObjectWriterInternal.StoreAppropriatelyTypedValue(ObjectState state, MemberAndValue ms, Object obj, Object keyObj)
   at Portable.Xaml.XamlObjectWriterInternal.OnWriteValue(Object value)
   at Portable.Xaml.XamlObjectWriter.WriteValue(Object value)
   at Portable.Xaml.XamlWriter.WriteNode(XamlReader reader)
   at Portable.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter, Boolean closeWriter)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.LoadFromReader(XamlReader reader, AvaloniaXamlContext context)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Stream stream, Object rootInstance, Uri uri)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Type type, Object rootInstance)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoaderPortableXaml.Load(Object obj)
   at DotnetPublishRepro.MainWindow.InitializeComponent() in C:\Users\Rayyan\Desktop\AvaloniaRepros\DotnetPublishRepro\MainWindow.xaml.cs:line 19
   at DotnetPublishRepro.MainWindow..ctor() in C:\Users\Rayyan\Desktop\AvaloniaRepros\DotnetPublishRepro\MainWindow.xaml.cs:line 11
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance[T]()
   at Avalonia.Controls.AppBuilderBase`1.Start[TMainWindow](Func`1 dataContextProvider)
   at DotnetPublishRepro.Program.Main(String[] args) in C:\Users\Rayyan\Desktop\AvaloniaRepros\DotnetPublishRepro\Program.cs:line 11

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
MV10commented, Jul 30, 2018

@danwalmsley Just for the record, that isn’t what win-x64 means. In the runtime ID docs I linked above, check out how it works in the RID graph – it’s what NuGet calls a fallback RID for when you want to publish to a version-specific target (like win7 or win10), but the library itself is not version-specific. I ran across a blog article yesterday, VS defaults to the less-specific fallback IDs because they want to encourage those over version-specific IDs wherever possible. (It’s particularly messy when you consider the explosion of Linux RIDs.)

WinRT doesn’t have an RID – you can’t use it as a publish target (which makes sense, as it has been discontinued). CoreRT is the new runtime targeting AOT (ahead-of-time compile) scenarios – basically taking over from WinRT as Microsoft’s end-game of getting rid of the Win32 API once and for all.

The first section of that article defines the full RID format as [os].[version]-[architecture]-[additional qualifiers] and one of the examples of an additional qualifier is corert so publishing for CoreRT would look like win-x64-corert.

You could confirm this with a self-contained publish targeting one of the version-specific Linux RIDs. You should still get the Linux version of libSkiaSharp because the avalonia.skia.linux.natives package specifies the linux-x64 fallback RID – the next one down the graph that is selected if a version-specific implementation can’t be found.

1reaction
MV10commented, Jul 30, 2018

This is probably a documentation issue, ultimately – both here and for SkiaSharp (I’ll open an issue over there and cross-reference this). By default, VS Publish only lists the fallback runtime IDs which is why I only saw the less-specific win-x64 target. NuGet can fallback from more-specific to less-specific, but not the other way around. To get a more-specific RID like win10-x64 in Visual Studio I added a <RuntimeIdentifiers> node to the csproj file:

<RuntimeIdentifiers>win10-x64;osx;linux-x64</RuntimeIdentifiers>

After this change, both the win10-x64 and the linux-x64 targets publish correctly (and probably somebody working on Avalonia has already thought about this issue given the existence of the avalonia.skia.linux.natives NuGet package).

However, publishing to the osx target still does not work, even though I see osx listed in SkiaSharp’s nuget package.

I’m new to Avalonia (and I understand Avalonia is still very much a work-in-progress), should I expect OSX to build and publish yet?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with Publish app for the webOS from Avalonia
My task is to publish the Avalonia browser.app so that it functions like a website. I use Jetbrains RIder IDE on the macOS....
Read more >
Avalonia, cannot run app compiled with NativeAOT. : r/csharp
It compiles with no errors using dotnet publish -r win-x64 -c release but the application won't start at all.
Read more >
macOS Distribution
macOS applications are typically distributed in a .app application bundle. To make .NET Core and Avalonia projects work in a .app bundle, some...
Read more >
.Net Core Avalonia UI Frozen - Raspberry Pi Forums
The application runs but the interface is unresponsive. In both examples above I can't interact with the on-screen controls, they are completely non-responsive....
Read more >
IDE Support
If your XAML file is showing a lot of errors, try right-clicking the file then selecting "Open With..." → "Avalonia XAML Editor". Design-Time...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found