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

Trying to run on macos using blazor provides missing dll issue #240

Open
justasxz opened this issue Oct 22, 2024 · 12 comments
Open

Trying to run on macos using blazor provides missing dll issue #240

justasxz opened this issue Oct 22, 2024 · 12 comments

Comments

@justasxz
Copy link

justasxz commented Oct 22, 2024

Hi,

So I am trying to build the application (that already runs on windows) on mac, it builds successfully everything seems to work, but when the application opens up it throws netvips.dll exception. Is there any fix to this ? I have all the native-arm packages installed. It only fails when it tries to run netvips code, it functions normally besides that. I am running VS Code blazor hybrid

@kleisauke
Copy link
Owner

Did you see #189 (comment) ?

I have all the native-arm packages installed.

You could try to install the NetVips.Native NuGet package, it will automatically choose the appropriate NetVips.Native.* package based on which OS/bitness it's running on. This can be useful for cross-platform deployments.

@justasxz
Copy link
Author

justasxz commented Oct 22, 2024

Did you see #189 (comment) ?

I have all the native-arm packages installed.

You could try to install the NetVips.Native NuGet package, it will automatically choose the appropriate NetVips.Native.* package based on which OS/bitness it's running on. This can be useful for cross-platform deployments.

Thanks, for quick reply. Yes I tried various combinations such as netvips and netvips.native only. netvips native and arm64 version at the same time. Only arm64 version, neither works. Here is the full error:

Exception has occurred: CLR/System.DllNotFoundException

Exception thrown: 'System.DllNotFoundException' in NetVips.dll: 'libvips.so.42'
at NetVips.Internal.Vips.Init(String argv0)
at NetVips.NetVips.Init()
at NetVips.ModuleInitializer.Initialize()
at .cctor()
at PSPerformance.Domain.Editor.EditorImage.b__33_0() in /Users/diana/Documents/ProSystemos/PSPerformance/PSPerformance.Domain/Editor/EditorImage.cs:line 66
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.<>c.<.cctor>b__281_0(Object obj)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
at System.Threading.Tasks.Task.ExecuteEntryUnsafe(Thread threadPoolThread)
at System.Threading.Tasks.Task.ExecuteFromThreadPool(Thread threadPoolThread)
at System.Threading.ThreadPoolWorkQueue.DispatchWorkItem(Object workItem, Thread currentThread)
at System.Threading.ThreadPoolWorkQueue.DispatchItemWithAutoreleasePool(Object workItem, Thread currentThread)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerDoWork(PortableThreadPool threadPoolInstance, Boolean& spinWait)
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
at System.Threading.Thread.StartHelper.RunWorker()
at System.Threading.Thread.StartHelper.Run()
at System.Threading.Thread.StartCallback()

If that helps I had similar issue with MagickNet until I added this to my csproj
< MagickCopyNativeMacOS >true< /MagickCopyNativeMacOS >

Just to reiterate this is blazor hybrid project (so basically maui + blazor)
It works fine on windows, just on macos keeps throwing that error. I have not tried, but I believe manually adding the dll might help ?

@kleisauke
Copy link
Owner

kleisauke commented Oct 22, 2024

On macOS, it should look for libvips.42.dylib instead of libvips.so.42. Could you try updating to the release candidates of NetVips 3.0.0 and NetVips.Native 8.16.0?
https://www.nuget.org/packages/NetVips/3.0.0-rc1
https://www.nuget.org/packages/NetVips.Native/8.16.0-rc1

If that works, it seems that the wrong NetVips DLL for Linux (from the runtimes/unix/lib/netstandard2.0 directory) is being used on macOS, when it should be loading the macOS-specific DLL (from the runtimes/osx/lib/netstandard2.0 directory) instead. Fortunately, after commit 1448040, only a single DLL is now required, with re-mapping handled at runtime using NativeLibrary.SetDllImportResolver().

@justasxz
Copy link
Author

On macOS, it should look for libvips.42.dylib instead of libvips.so.42. Could you try updating to the release candidates of NetVips 3.0.0 and NetVips.Native 8.16.0? https://www.nuget.org/packages/NetVips/3.0.0-rc1 https://www.nuget.org/packages/NetVips.Native/8.16.0-rc1

If that works, it seems that the wrong NetVips DLL for Linux (from the runtimes/unix/lib/netstandard2.0 directory) is being used on macOS, when it should be loading the macOS-specific DLL (from the runtimes/osx/lib/netstandard2.0 directory) instead. Fortunately, after commit 1448040, only a single DLL is now required, with re-mapping handled at runtime using NativeLibrary.SetDllImportResolver().

I updated it to the newest versions but I seem to be getting the same issue. To clarify the target is maccatalyst. I don't think you can target macOS directly on blazor hybrid. Unless I am missing something.

@kleisauke
Copy link
Owner

It appears that this issue is related to dotnet/runtime#104160. As a workaround, you could try symlinking or renaming libvips.42.dylib to libvips.so.42, although I'm unsure if this would work on Mac Catalyst without further adjustments.

Additionally, I'm uncertain whether NetVips, or any other that relies on unmanaged/native code, would function correctly in a Blazor Hybrid environment. It's probably unsupported in Blazor components, as P/Invoke isn't natively supported there.

@kleisauke kleisauke added the triage This issue is being investigated label Oct 27, 2024
@kleisauke
Copy link
Owner

@justasxz Are you able to test commit 8308801? Testing can be done by using the nightly version of NetVips. Add the https://ci.appveyor.com/nuget/net-vips feed in the <packageSources> section of your NuGet.config:

<packageSources>
  <add key="netvips-nightly" value="https://ci.appveyor.com/nuget/net-vips" />
</packageSources>

And update NetVips to 3.0.0 (build number 605 - prerelease).

@kleisauke
Copy link
Owner

Hmm, looking at PortableRuntimeIdentifierGraph.json, I'm unsure if the above commit will work with the NetVips.Native* packages, since the maccatalyst RIDs inherit from ios rather than osx.

graph TD;
    unix --> unix-x64 & ios & unix-arm64;
    unix-x64 --> ios-x64;
    unix-arm64 --> ios-arm64;
    ios --> ios-x64 & maccatalyst & ios-arm64;
    ios-x64 & maccatalyst --> maccatalyst-x64;
    ios-arm64 & maccatalyst --> maccatalyst-arm64;
Loading

@justasxz
Copy link
Author

@justasxz Are you able to test commit 8308801? Testing can be done by using the nightly version of NetVips. Add the https://ci.appveyor.com/nuget/net-vips feed in the <packageSources> section of your NuGet.config:

<packageSources>
  <add key="netvips-nightly" value="https://ci.appveyor.com/nuget/net-vips" />
</packageSources>

And update NetVips to 3.0.0 (build number 605 - prerelease).

I would for sure be able to, I greatly appreciate your effort to add support to maccatalyst. But you just responded that you doubt it would work. Do you want me to test it or wait for another commit ?

@kleisauke
Copy link
Owner

Do you want me to test it or wait for another commit ?

Feel free to test that commit; hopefully it will now look for libvips.42.dylib instead of libvips.so.42.

Support for iOS (and .NET MAUI) is being tracked in issue #154.

@kleisauke
Copy link
Owner

@justasxz Were you able to make any progress with this?

@justasxz
Copy link
Author

Hi, sorry it was put on hold for a bit, I will get back to it when I can. I was having trouble downloading the preview version (never done it, and following tutorials, adding the link you provided into .nuget file did not allow me to pick preview version, might be me not knowing how to, might be just visual studio code, not working as intended), and then some other things came up with higher priority. Should come back with an answer in a few weeks if I get it working.

@kleisauke
Copy link
Owner

I'm removing the triage label as I lack access to a macOS (or iOS) device, making it difficult to debug further.

@kleisauke kleisauke removed the triage This issue is being investigated label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants