Blish-HUD icon indicating copy to clipboard operation
Blish-HUD copied to clipboard

System.ArgumentException while trying to read the environment variables for the GW2 game process

Open WRMSRwasTaken opened this issue 2 years ago • 3 comments

https://github.com/blish-hud/Blish-HUD/blob/46a19061bcfe3569d2538ff67b20a543e82b62cb/Blish%20HUD/GameServices/GameIntegration/Gw2InstanceIntegration.cs#L197 is failing with the error:

System.ArgumentException: 'The output character buffer is too small for the encoded characters. Encoding of "Unicode" in fallback position "System.Text.DecoderReplacementFallback".
Parameter name: chars'

This exception was originally thrown at this call stack:
    System.Text.Encoding.ThrowCharsOverflow()
    System.Text.Encoding.ThrowCharsOverflow(System.Text.DecoderNLS, bool)
    System.Text.UnicodeEncoding.GetChars(byte, int, System.Text.DecoderNLS)
    System.Text.DecoderNLS.GetChars(byte[], int, int, char[], int, bool)
    System.Text.DecoderNLS.GetChars(byte[], int, int, char[], int)
    System.IO.BinaryReader.InternalReadOneChar()
    Gapotchenko.FX.Diagnostics.Implementation.ProcessBinaryReader.ReadCString()
    Gapotchenko.FX.Diagnostics.Implementation.Windows.ProcessEnvironment._ReadEnv(Gapotchenko.FX.Diagnostics.Implementation.ProcessBinaryReader)
    Gapotchenko.FX.Diagnostics.Implementation.Windows.ProcessEnvironment._ReadVariablesCore(System.IntPtr)
    Gapotchenko.FX.Diagnostics.Implementation.Windows.ImplementationAdapter.ReadProcessEnvironmentVariables(System.Diagnostics.Process)
    ...
    [Call Stack Truncated]

The error has been translated, although my Windows and Visual Studio are set to english. It seems, that there is something in my env vars, Blish HUD or .NET in general does not like. Adding

} catch (ArgumentException e) {
    Logger.Warn(e, "Failed to parse the Guild Wars 2 env variables.");
}

as new catch block to the try block around var envs = newProcess.ReadEnvironmentVariables(); seems to be a workaround on my machine, as Blish HUD seems to run fine with this.

Should I PR this "fix"?

WRMSRwasTaken avatar May 28 '22 18:05 WRMSRwasTaken

Before we move forward with that (we likely will want to) are you able to reliably replicate this issue when the additional catch isn't included?

I'd like to report this issue to the library's repo if we can with any information that you can provide that may help to narrow down the issue in our issue report.

dlamkins avatar May 29 '22 04:05 dlamkins

This error appears every time I am starting the project (doesn't matter if it's debug in VS or actually a release binary) on my machine. It's even persisting across reboots.

I haven't tried doing any updates to Visual Studio (using 2019 16.11.13) or .NET framework (building it with 4.7.2) so far. I'm on Win 10 21H2.

Happy to provide any additional needed information to get this sorted out.

WRMSRwasTaken avatar May 29 '22 18:05 WRMSRwasTaken

Sorry for not getting back to you sooner, @WRMSRwasTaken. I would certainly appreciate if you PR'd those changes. 👍 Otherwise, I can put them in if you don't have the time to.

I'll keep the issue open to help ensure I reach out to the library's owner about the issue.

dlamkins avatar Jun 24 '22 16:06 dlamkins

Fixed in #711.

Thank you!

dlamkins avatar Sep 05 '22 20:09 dlamkins