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

How to run an Avalonia project with mono #2504

Closed
apbertoletti opened this issue May 8, 2019 · 17 comments
Closed

How to run an Avalonia project with mono #2504

apbertoletti opened this issue May 8, 2019 · 17 comments
Labels

Comments

@apbertoletti
Copy link

apbertoletti commented May 8, 2019

Hi people.

Sorry if duplicated, but I can´t find any.

Explain my context:

I did a sample avalonia project using Visual Studio (windows 10), then I published the project (Rigth click on Project in solution explorer -> Publish option). So, I transfered the publish folder content to virtual machine with Ubuntu Linux (v18.04), and finally, run the app using the follow command:

dotnet AppName.dll

It works as expected.

But, I need to run this same app with Mono compiler. So I installed the mono (v5.20.1.19) in this VM and run the follow command:

mono AppName.dll

Here is the problem:

Unhandled Exception: System.DllNotFoundException: libSkiaSharp at (wrapper managed-to-native) SkiaSharp.SkiaApi.gr_glinterface_assemble_gl_interface(intptr,intptr) at SkiaSharp.GRGlInterface.AssembleGlInterface (System.Object context, SkiaSharp.GRGlGetProcDelegate get) [0x00010] in <f0c24c4dec0742d096b8ec67614c0af5>:0 at SkiaSharp.GRGlInterface.AssembleGlInterface (SkiaSharp.GRGlGetProcDelegate get) [0x00001] in <f0c24c4dec0742d096b8ec67614c0af5>:0 at Avalonia.Skia.PlatformRenderInterface..ctor () [0x00056] in <495233f1b3044dd08c7fe9b76254ab31>:0 at Avalonia.Skia.SkiaPlatform.Initialize () [0x00000] in <495233f1b3044dd08c7fe9b76254ab31>:0 at Avalonia.SkiaApplicationExtensions+<>c__01[T].b__0_0 () [0x00000] in <495233f1b3044dd08c7fe9b76254ab31>:0
at Avalonia.Controls.AppBuilderBase1[TAppBuilder].Setup () [0x00099] in <760632d2d12b408380559a5a34ba1e30>:0 at Avalonia.Controls.AppBuilderBase1[TAppBuilder].Start (Avalonia.Controls.AppBuilderBase1+AppMainDelegate[TAppBuilder] main, System.String[] args) [0x00000] in <760632d2d12b408380559a5a34ba1e30>:0 at TelaToten.Program.Main (System.String[] args) [0x00005] in <dac6b87b16f445889ec2af036aef11db>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: libSkiaSharp at (wrapper managed-to-native) SkiaSharp.SkiaApi.gr_glinterface_assemble_gl_interface(intptr,intptr) at SkiaSharp.GRGlInterface.AssembleGlInterface (System.Object context, SkiaSharp.GRGlGetProcDelegate get) [0x00010] in <f0c24c4dec0742d096b8ec67614c0af5>:0 at SkiaSharp.GRGlInterface.AssembleGlInterface (SkiaSharp.GRGlGetProcDelegate get) [0x00001] in <f0c24c4dec0742d096b8ec67614c0af5>:0 at Avalonia.Skia.PlatformRenderInterface..ctor () [0x00056] in <495233f1b3044dd08c7fe9b76254ab31>:0 at Avalonia.Skia.SkiaPlatform.Initialize () [0x00000] in <495233f1b3044dd08c7fe9b76254ab31>:0 at Avalonia.SkiaApplicationExtensions+<>c__01[T].b__0_0 () [0x00000] in <495233f1b3044dd08c7fe9b76254ab31>:0
at Avalonia.Controls.AppBuilderBase1[TAppBuilder].Setup () [0x00099] in <760632d2d12b408380559a5a34ba1e30>:0 at Avalonia.Controls.AppBuilderBase1[TAppBuilder].Start (Avalonia.Controls.AppBuilderBase1+AppMainDelegate[TAppBuilder] main, System.String[] args) [0x00000] in <760632d2d12b408380559a5a34ba1e30>:0 at TelaToten.Program.Main (System.String[] args) [0x00005] in <dac6b87b16f445889ec2af036aef11db>:0

@kekekeks
Copy link
Member

kekekeks commented May 8, 2019

For some reason MSBuild is failing to copy the native library to bin/Debug. You can do that manually from ~/.nuget/packages/avalonia.skia.linux.natives/1.68.0.2/runtimes/linux-x64/native/libSkiaSharp.so.

@kekekeks
Copy link
Member

kekekeks commented May 8, 2019

Also make sure to chmod +x it, since you are copying from the windows machine.

@kekekeks
Copy link
Member

kekekeks commented May 8, 2019

Also, if you are planning to use Mono as the runtime, it's probably better to target net472 and use build output directly instead of publishing the app.

@kekekeks
Copy link
Member

kekekeks commented May 8, 2019

For old Mono versions it might be also required to add the directory with libSkiaSharp.so to LD_LIBRARY_PATH environment variable, but I'd recommend to download the recent Mono from mono-project.com instead.

@apbertoletti
Copy link
Author

Thanks for all tips...

Our strategic changes here, and maybe we won´t use more Mono.

Anyway, I do these tests that you mentioned

Thanks

@georgiuk
Copy link

Hello,
I try to run my app on Linux under Mono 6.4 .
However I get the following. Do you have any clue why is that. I have copied liskiasharp.so from avalonia.skia.linux.natives.1.68.0.2 in app directory and run chmod +x on it .
I would appreciate any hint.
Thank you

Unhandled Exception:
System.EntryPointNotFoundException: sk_refcnt_safe_unref assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) SkiaSharp.SkiaApi.sk_refcnt_safe_unref(intptr)
  at SkiaSharp.SKObjectExtensions.SafeUnRef (SkiaSharp.ISKReferenceCounted obj) [0x00017] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at SkiaSharp.SKObject.DisposeNative () [0x0000a] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at SkiaSharp.SKNativeObject.Dispose (System.Boolean disposing) [0x0002a] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at SkiaSharp.SKObject.Dispose (System.Boolean disposing) [0x00000] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at SkiaSharp.GRGlInterface.Dispose (System.Boolean disposing) [0x00000] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at SkiaSharp.SKNativeObject.DisposeInternal () [0x00000] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at SkiaSharp.SKNativeObject.Dispose () [0x00009] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at Avalonia.Skia.PlatformRenderInterface..ctor (Avalonia.Skia.ICustomSkiaGpu customSkiaGpu) [0x00096] in <ce02b2bc7000489688a2a9c0e02a5517>:0 
  at Avalonia.Skia.SkiaPlatform.Initialize (Avalonia.SkiaOptions options) [0x00012] in <ce02b2bc7000489688a2a9c0e02a5517>:0 
  at Avalonia.SkiaApplicationExtensions+<>c__0`1[T].<UseSkia>b__0_0 () [0x00013] in <ce02b2bc7000489688a2a9c0e02a5517>:0 
  at Avalonia.Controls.AppBuilderBase`1[TAppBuilder].Setup () [0x00086] in <1d8a69314a4143e69a4ba900292cd10e>:0 
  at Avalonia.Controls.AppBuilderBase`1[TAppBuilder].SetupWithLifetime (Avalonia.Controls.ApplicationLifetimes.IApplicationLifetime lifetime) [0x00007] in <1d8a69314a4143e69a4ba900292cd10e>:0 
  at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T] (T builder, System.String[] args, Avalonia.Controls.ShutdownMode shutdownMode) [0x0000d] in <1d8a69314a4143e69a4ba900292cd10e>:0 
  at SaveMyDLManager.Program.Main (System.String[] args) [0x00005] in <230e17ab755d4661b0a59091d68ff91a>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.EntryPointNotFoundException: sk_refcnt_safe_unref assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) SkiaSharp.SkiaApi.sk_refcnt_safe_unref(intptr)
  at SkiaSharp.SKObjectExtensions.SafeUnRef (SkiaSharp.ISKReferenceCounted obj) [0x00017] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at SkiaSharp.SKObject.DisposeNative () [0x0000a] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at SkiaSharp.SKNativeObject.Dispose (System.Boolean disposing) [0x0002a] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at SkiaSharp.SKObject.Dispose (System.Boolean disposing) [0x00000] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at SkiaSharp.GRGlInterface.Dispose (System.Boolean disposing) [0x00000] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at SkiaSharp.SKNativeObject.DisposeInternal () [0x00000] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at SkiaSharp.SKNativeObject.Dispose () [0x00009] in <8a8750ff63a849ac8143222434ac9e4c>:0 
  at Avalonia.Skia.PlatformRenderInterface..ctor (Avalonia.Skia.ICustomSkiaGpu customSkiaGpu) [0x00096] in <ce02b2bc7000489688a2a9c0e02a5517>:0 
  at Avalonia.Skia.SkiaPlatform.Initialize (Avalonia.SkiaOptions options) [0x00012] in <ce02b2bc7000489688a2a9c0e02a5517>:0 
  at Avalonia.SkiaApplicationExtensions+<>c__0`1[T].<UseSkia>b__0_0 () [0x00013] in <ce02b2bc7000489688a2a9c0e02a5517>:0 
  at Avalonia.Controls.AppBuilderBase`1[TAppBuilder].Setup () [0x00086] in <1d8a69314a4143e69a4ba900292cd10e>:0 
  at Avalonia.Controls.AppBuilderBase`1[TAppBuilder].SetupWithLifetime (Avalonia.Controls.ApplicationLifetimes.IApplicationLifetime lifetime) [0x00007] in <1d8a69314a4143e69a4ba900292cd10e>:0 
  at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T] (T builder, System.String[] args, Avalonia.Controls.ShutdownMode shutdownMode) [0x0000d] in <1d8a69314a4143e69a4ba900292cd10e>:0 
  at SaveMyDLManager.Program.Main (System.String[] args) [0x00005] in <230e17ab755d4661b0a59091d68ff91a>:0 

@kekekeks
Copy link
Member

kekekeks commented Jan 20, 2020

Probably SkiaSharp version mismatch. sk_refcnt_safe_unref only exists in SkiaSharp 1.68.1 which is not binary compatible with the previous version in terms of the native binary.

@georgiuk
Copy link

Thank you. That was the problem. I had also Mapsui with different skia requirement.

@andrfgs
Copy link

andrfgs commented Feb 11, 2021

So basically Avalonia is broken/unsupported for Mono from the looks of it.There are no docs concerning how to use Avalonia on Mono either so I'm assuming this is a .Net Core implementation only.

@kekekeks
Copy link
Member

kekekeks commented Feb 11, 2021

We are running our tests with legacy .NET TFM. Mono runtime is supported, we are also using it for iOS and Android.

Mono build ecosystem, however, is not supported. You need to manually copy required native bits and ensure that Mono P/Invoke loader finds them or supply LD_LIBRARY_PATH.

Basically we require Mono users to be proficient with Mono and Unix.

@andrfgs
Copy link

andrfgs commented Feb 19, 2021

There seems to be zero documentation to what you describe (Mono build not being supported). Also, what are the native bits required? I assume it's libSkiaSharp.so and libHarfBuzzSharp.so which I did manually include.

Except Avalonia segfaults on Linux with these libraries. So I'm guessing this wasn't made with Linux compatibility in mind? Either that or there was a breaking change for Linux.

The .Net Core version works fine on Linux but the mono version segfaults.

@kekekeks
Copy link
Member

Mkay, I've just checked and it turns out that Avalonia works with Mono mostly out of the box except for a bug in SkiaSharp and HarfbuzzSharp that overwrite native binaries with ones built for musl.
The workaround is to add

   <Target Name="SkiaSharpRemoveMusl" BeforeTargets="BeforeBuild">
      <ItemGroup>
         <Content Remove="@(Content)" Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('%(FullPath)', 'packages.*linux-musl.*so')) "/>
      </ItemGroup>
   </Target>

to csproj file.

You can find a working example here: https://github.com/kekekeks/AvaloniaMonoDemo

@kekekeks
Copy link
Member

mono/SkiaSharp#1637

@andrfgs
Copy link

andrfgs commented Feb 20, 2021

Ok that example project seems to work. But projects I have made using msbuild don't. Might I ask you how did you generate the project files? As I cannot build the project for mono since there seem to be no build systems available.

The projects I built were built with msbuild for .Net 5 and then downgraded to .Net 4.72, though I believe this is why it is not working on Mono, I don't know. Is there any way of building everything in Linux? I can't use Visual Studio to build the project.

@kekekeks
Copy link
Member

<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" /> enables legacy framework targeting for .NET 5 SDK.

@rstm-sf
Copy link
Contributor

rstm-sf commented Feb 21, 2021

<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" /> enables legacy framework targeting for .NET 5 SDK.

For .NET 5 SDK this is not needed, it is already included :)

Some things can even be run on Linux 😏

@mattleibow
Copy link
Contributor

Thanks for reporting this and sorry for the long delay. I was doing crazy things with MAUI. I see what I did was basically dumb. What would work in a typical case? Would you want to compile for both glibc and musl and have some runtime check (that I am not sure of the best way to do) or have a project property that you set, say <PreferMuslSkiaSharp>true</>?

@maxkatz6 maxkatz6 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants