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.

Unhandled exception in method ReadLink(string path)

See original GitHub issue

Hello.

Unhandled exception throw in Avalonia.FreeDesktop.NativeMethods.ReadLink(String path).

“The output byte buffer is too small to contain the encoded data, encoding ‘Unicode (UTF-8)’ fallback ‘System.Text.EncoderReplacementFallback’.”

Input parameter: “/dev/disk/by-label/Зарезервировано\x20системой”

Maybe instead of var symlinkMaxSize = Encoding.ASCII.GetMaxByteCount(path.Length);

use

var symlinkMaxSize = Encoding.UTF8.GetMaxByteCount(path.Length);

Thanks.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kekekekscommented, Feb 22, 2020

@jmacato you should use realpath instead since it already implements proper path resolving logic.

0reactions
kekekekscommented, Feb 22, 2020

Just declare it as

        [DllImport("libc", SetLastError = true)]
        private static IntPtr realpath(string path, IntPtr unused);
        [DllImport("libc"]
        private static void free(IntPtr mem);
var resolvedPtr = realpath(pathString, IntPtr.Zero);
if(resolvedPtr == IntPtr.Zero)
    throw new Win32Exception();
var rv = Marshal.PtrToStringAnsi(resolvedPtr);
free(resolvedPtr)
return rv;

Marshaller will do all of UTF8 conversions automatically without extra manual work that you were doing incorrectly anyway

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Read text file return 'System.NotSupportedException' ...
The issue is that there is an invisible character in your string. I don't know how they get there, others have guessed that...
Read more >
readlink on Windows cannot read app exec links
msg349486 ‑ (view) Author: Steve Dower (steve.dower) * Date: 2019‑08‑12 18:49 msg349499 ‑ (view) Author: Steve Dower (steve.dower) * Date: 2019‑08‑12 21:20 msg349501 ‑ (view)...
Read more >
readlink - Manual
Returns the contents of the symbolic link path or false on error. Note: The function fails if path is not a symlink, except...
Read more >
Python os.readlink() Method - GeekBits
The os.readlink() function takes the path to the symbolic link and returns a string representing the path to the actual file or directory....
Read more >
Node.js v20.5.1 Documentation
operator <string> The operator property on the error instance. stackStartFn <Function> If provided, the generated stack trace omits frames before this function.
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