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

DynamicLinkLibraryPathResolver() cctor crashes when single file publishing is used #52496

Closed
vadi2 opened this issue May 8, 2021 · 3 comments
Labels
area-Single-File untriaged New issue has not been triaged by the area owner

Comments

@vadi2
Copy link

vadi2 commented May 8, 2021

Description

I'm using a third-party library, QmlNet, which crashes when .NET 5 single file publishing is used. The culprit is the initialization of the NetNativeLibLoader.PathResolver.DynamicLinkLibraryPathResolver().

Configuration

.NET 5 both on Ubuntu 20.04 and Windows 10.

Regression?

Not sure.

Other information

Unhandled exception. System.TypeInitializationException: The type initializer for 'Qml.Net.Internal.Interop' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'NetNativeLibLoader.PathResolver.DynamicLinkLibraryPathResolver' threw an exception.
 ---> System.ArgumentException: Path cannot be the empty string or all whitespace. (Parameter 'path')
   at System.IO.Directory.GetParent(String path)
   at NetNativeLibLoader.PathResolver.LocalPathResolver..ctor()
   at NetNativeLibLoader.PathResolver.DynamicLinkLibraryPathResolver..cctor()
   --- End of inner exception stack trace ---
   at NetNativeLibLoader.PathResolver.DynamicLinkLibraryPathResolver..ctor(Boolean searchLocalFirst)
   at Qml.Net.Internal.Interop..cctor()
   --- End of inner exception stack trace ---
   at Qml.Net.Internal.Interop.get_QQuickStyle()
   at Qml.Net.QQuickStyle.SetStyle(String style)
   at Program.Main(String[] args)
Aborted (core dumped)
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label May 8, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost
Copy link

ghost commented May 8, 2021

Tagging subscribers to this area: @agocke, @vitek-karas, @VSadov
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

I'm using a third-party library, QmlNet, which crashes when .NET 5 single file publishing is used. The culprit is the initialization of the NetNativeLibLoader.PathResolver.DynamicLinkLibraryPathResolver().

Configuration

.NET 5 both on Ubuntu 20.04 and Windows 10.

Regression?

Not sure.

Other information

Unhandled exception. System.TypeInitializationException: The type initializer for 'Qml.Net.Internal.Interop' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'NetNativeLibLoader.PathResolver.DynamicLinkLibraryPathResolver' threw an exception.
 ---> System.ArgumentException: Path cannot be the empty string or all whitespace. (Parameter 'path')
   at System.IO.Directory.GetParent(String path)
   at NetNativeLibLoader.PathResolver.LocalPathResolver..ctor()
   at NetNativeLibLoader.PathResolver.DynamicLinkLibraryPathResolver..cctor()
   --- End of inner exception stack trace ---
   at NetNativeLibLoader.PathResolver.DynamicLinkLibraryPathResolver..ctor(Boolean searchLocalFirst)
   at Qml.Net.Internal.Interop..cctor()
   --- End of inner exception stack trace ---
   at Qml.Net.Internal.Interop.get_QQuickStyle()
   at Qml.Net.QQuickStyle.SetStyle(String style)
   at Program.Main(String[] args)
Aborted (core dumped)
Author: vadi2
Assignees: -
Labels:

area-Single-File, untriaged

Milestone: -

@vitek-karas
Copy link
Member

This is an issue in the NativeLibraryLibLoader:
https://github.com/pauldotknopf/net-native-lib-loader/blob/344a1df38aa6ec0d827c972375c6e2d7eac3d3b9/src/NetNativeLibLoader/PathResolver/LocalPathResolver.cs#L39

The call to GetExecutingAssembly().Location is not compatible with single-file. Assemblies in single-file are not files on disk since .NET 5 - they're loaded directly from the executable, so there's no path to return. The API returns empty string, which will cause the code using it to fail.

In .NET 6 we have an analyzer which can be enabled by setting EnableSingleFileAnalyzer=true in your project. It will issue a warning when it sees code which is not compatible with single-file. Note that this only works when you're compiling the affected code from source code, so it doesn't work for NuGet packages (as those are binaries only).

@ghost ghost locked as resolved and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Single-File untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

3 participants