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

[native_assets] Spaces in paths #56053

Closed
dcharkes opened this issue Jun 20, 2024 · 2 comments
Closed

[native_assets] Spaces in paths #56053

dcharkes opened this issue Jun 20, 2024 · 2 comments
Labels
area-native-interop issues in the native interop area

Comments

@dcharkes
Copy link
Contributor

I can confirm this works in all but one use case, and that's when there is a space in the path of the resolved executable. In that case, the spaces appear as %20 in the LoadLibraryW call which Windows is not happy about. This can happen, for example, when the resolved executable lives in Program Files.

The following example demonstrates this behavior (using native_add_app again):

$ dart --enable-experiment=native-assets build --output="native output" .\bin\native_add_app.dart
$ New-Item -Path .\native_add_app.exe -ItemType SymbolicLink -Value ".\native output\native_add_app.exe"
$ .\native_add_app.exe
Invoking a native function to calculate 1 + 2.
Unhandled exception:
Invalid argument(s): Couldn't resolve native function 'add' in 'package:native_add_library/native_add_library.dart' : Failed to load dynamic library 'lib\native_add_library.dll': Failed to load dynamic library 'c:/workspace/native/pkgs/native_assets_cli/example/build/native_add_app/native%20output/lib/native_add_library.dll': The specified module could not be found.
 (error code: 126).

#0      Native._ffi_resolver.#ffiClosure0 (dart:ffi-patch/ffi_patch.dart)
#1      Native._ffi_resolver_function (dart:ffi-patch/ffi_patch.dart:1523)
#2      add (package:native_add_library/native_add_library.dart)
#3      main (file:///c:/workspace/native/pkgs/native_assets_cli/example/build/native_add_app/bin/native_add_app.dart:9)
#4      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297)
#5      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184)

This is running against the current main:

Dart SDK version: 3.5.0-edge.09e87e6d7bd18e3b08cc96c3a42b8e3f37a096d6 (main) (Wed Jun 19 14:50:30 2024 +0000) on "windows_x64"

Originally posted by @dnys1 in #55207 (comment)

@dcharkes dcharkes added the area-native-interop issues in the native interop area label Jun 20, 2024
@lrhn
Copy link
Member

lrhn commented Jun 20, 2024

If there is a %20 then it's most likely because the path text was parsed as a URI, and not unparsed back to a system path.
The path using forward slashes together with a Windows drive name suggests the same thing.

Use File.fromUri(uri).path rather than uri.path. The latter can contain escaped characters, the former should be a valid file path, which may need to be quoted since it can contain spaces.
(If the path contained a %, or any URI delimiter character, that would probably be escaped too.)

@dcharkes
Copy link
Contributor Author

If there is a %20 then it's most likely because the path text was parsed as a URI, and not unparsed back to a system path. The path using forward slashes together with a Windows drive name suggests the same thing.

Correct.

Use File.fromUri(uri).path rather than uri.path. The latter can contain escaped characters, the former should be a valid file path, which may need to be quoted since it can contain spaces. (If the path contained a %, or any URI delimiter character, that would probably be escaped too.)

The error was in the C++ code, but the same logic applies. 👍

Fix: https://dart-review.googlesource.com/c/sdk/+/372421

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-native-interop issues in the native interop area
Projects
None yet
Development

No branches or pull requests

2 participants