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

Exception in MySqlConnector.Protocol.Serialization.ByteBufferWriter.Write #520

Closed
mzji opened this issue Jun 16, 2018 · 5 comments
Closed
Assignees
Labels

Comments

@mzji
Copy link

@mzji mzji commented Jun 16, 2018

Exception message:

[2018-06-16 17:32:31 084] System.ArgumentException: The output byte buffer is too small to contain the encoded data, encoding 'Unicode (UTF-8)' fallback 'System.Text.EncoderReplacementFallback'.
Parameter name: bytes
   at System.Text.Encoding.ThrowBytesOverflow()
   at System.Text.Encoding.ThrowBytesOverflow(EncoderNLS encoder, Boolean nothingEncoded)
   at System.Text.UTF8Encoding.GetBytes(Char* chars, Int32 charCount, Byte* bytes, Int32 byteCount, EncoderNLS baseEncoder)
   at System.Text.EncoderNLS.Convert(Char* chars, Int32 charCount, Byte* bytes, Int32 byteCount, Boolean flush, Int32& charsUsed, Int32& bytesUsed, Boolean& completed)
   at MySqlConnector.Protocol.Serialization.ByteBufferWriter.Write(ReadOnlySpan`1 chars) in C:\projects\mysqlconnector\src\MySqlConnector\Protocol\Serialization\ByteBufferWriter.cs:line 147
   at MySql.Data.MySqlClient.MySqlParameter.AppendSqlString(ByteBufferWriter writer, StatementPreparerOptions options, String parameterName) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlParameter.cs:line 191
   at MySqlConnector.Core.StatementPreparer.ParameterSqlParser.DoAppendParameter(Int32 parameterIndex, Int32 textIndex, Int32 textLength) in C:\projects\mysqlconnector\src\MySqlConnector\Core\StatementPreparer.cs:line 68
   at MySqlConnector.Core.SqlParser.Parse(String sql) in C:\projects\mysqlconnector\src\MySqlConnector\Core\SqlParser.cs:line 112
   at MySqlConnector.Core.StatementPreparer.ParseAndBindParameters() in C:\projects\mysqlconnector\src\MySqlConnector\Core\StatementPreparer.cs:line 27
   at MySqlConnector.Core.TextCommandExecutor.CreateQueryPayload(String commandText, MySqlParameterCollection parameterCollection) in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 121
   at MySqlConnector.Core.TextCommandExecutor.<ExecuteReaderAsync>d__3.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 65
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Core.TextCommandExecutor.<ExecuteScalarAsync>d__2.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 43
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteScalar() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlCommand.cs:line 66
   at SXLibraryCore.DbConnectionHelper.<>c.<GetObject>b__15_0(DbCommand cmd) in C:\Users\XXXX\Desktop\AreaPlatform\SXLibraryCore\SXLibraryCore\DBHelper.cs:line 465
   at SXLibraryCore.DbConnectionHelper.Common[T](DbConnection conn, String sqlStr, CommandType cmdType, IDictionary`2 arguments, Func`2 inner) in C:\Users\XXXX\Desktop\AreaPlatform\SXLibraryCore\SXLibraryCore\DBHelper.cs:line 264
   at SXLibraryCore.DbConnectionHelper.GetObject(DbConnection conn, String sqlStr, CommandType cmdType, Dictionary`2 arguments) in C:\Users\XXXX\Desktop\AreaPlatform\SXLibraryCore\SXLibraryCore\DBHelper.cs:line 465
   at SXLibraryCore.DbConnectionHelper.GetString(DbConnection conn, String sqlStr, CommandType cmdType, Dictionary`2 arguments) in C:\Users\XXXX\Desktop\AreaPlatform\SXLibraryCore\SXLibraryCore\DBHelper.cs:line 432
   at SXLibraryCore.DbConnectionHelper.GetString(DbConnection conn, String sqlStr, Dictionary`2 arguments) in C:\Users\XXXX\Desktop\AreaPlatform\SXLibraryCore\SXLibraryCore\DBHelper.cs:line 425
   at PTAdmin.SX.MP.GetTemplateId(String shortId, String name) in C:\Users\XXXX\Desktop\AreaPlatform\PTAdmin\PTAdmin\SX.cs:line 44
   at PTAdmin.Controllers.LoginController.LoginToken(String phoneNumber) in C:\Users\XXXX\Desktop\AreaPlatform\PTAdmin\PTAdmin\Controllers\LoginController.cs:line 133

The SQL statement, parameters and query results contain some Chinese characters, could that be the root of this issue?
.NET Core runtime: v2.0.5
MysqlConnector: 0.42.0

@mzji
Copy link
Author

@mzji mzji commented Jun 16, 2018

Seems like we could fallback to use the old code path to prevent using ReadOnlySpan<T> in .Net Stanard 2.0 .

@bgrainger
Copy link
Member

@bgrainger bgrainger commented Jun 16, 2018

Can you provide the SQL statement and parameters that cause this exception?

@bgrainger
Copy link
Member

@bgrainger bgrainger commented Jun 16, 2018

The docs say this exception is thrown when:

The output buffer is too small to contain any of the converted input.

This means we need to change the check here to reallocate if the buffer is potentially too small to contain one character (i.e., 4 UTF-8 bytes):

This will be fixed soon.

@bgrainger bgrainger self-assigned this Jun 16, 2018
@bgrainger bgrainger added the bug label Jun 16, 2018
@bgrainger
Copy link
Member

@bgrainger bgrainger commented Jun 16, 2018

Fixed in 0.42.1.

@mzji
Copy link
Author

@mzji mzji commented Jun 16, 2018

Confirmed, it's working now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants