Skip to content

Commit

Permalink
Restore OS-specific error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored and jasonleenaylor committed Jun 26, 2024
1 parent ae7b5bd commit 92b6512
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions source/icu.net/NativeMethods/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ static NativeMethods()
[DllImport(LIBDL_NAME, SetLastError = true)]
private static extern IntPtr dlsym(IntPtr handle, string name);

[DllImport(LIBDL_NAME, EntryPoint = "dlerror")]
private static extern IntPtr _dlerror();

private static string dlerror()
{
// Don't free the string returned from _dlerror()!
var ptr = _dlerror();
return Marshal.PtrToStringAnsi(ptr);
}

#endregion

#region Native methods for Windows
Expand Down Expand Up @@ -366,8 +376,13 @@ private static IntPtr GetIcuLibHandle(string basename, int icuVersion)
}

lastError = Marshal.GetLastWin32Error();
Trace.WriteLineIf(lastError != 0, $"Unable to load [{libPath}]. Error: {lastError}");
Trace.TraceWarning($"{loadMethod} of {libPath} failed with error {lastError}");
var errorMsg = IsWindows
? new Win32Exception(lastError).Message
: IsMac
? $"{lastError}"
: $"{lastError} ({dlerror()})";
Trace.WriteLineIf(lastError != 0, $"Unable to load [{libPath}]. Error: {errorMsg}");
Trace.TraceWarning($"{loadMethod} of {libPath} failed with error {errorMsg}");
icuVersion -= 1;
}
}
Expand Down

0 comments on commit 92b6512

Please sign in to comment.