csharp-sparkpost
csharp-sparkpost copied to clipboard
Header problem on Mono
This library worked like a charm under Windows and .NET 4.5, but when trying to run the same app under Mono, it crashed somewhere inside the sending logic with a System.FormatException with this stacktrace:
[System.FormatException]: One of the identified items was in an invalid format.
at System.Net.Http.Headers.HttpHeaders.AddInternal (System.String name, System.Collections.Generic.IEnumerable`1[T] values, System.Net.Http.Headers.HeaderInfo headerInfo, System.Boolean ignoreInvalid) [0x0004c] in <3dff384e916e4a45850531402c5defd9>:0
at System.Net.Http.Headers.HttpHeaders.Add (System.String name, System.Collections.Generic.IEnumerable`1[T] values) [0x0001b] in <3dff384e916e4a45850531402c5defd9>:0
at System.Net.Http.Headers.HttpHeaders.Add (System.String name, System.String value) [0x00000] in <3dff384e916e4a45850531402c5defd9>:0
at SparkPost.RequestSenders.AsyncRequestSender+<Send>c__async0.MoveNext () [0x00095] in <6b893430194846f1b88010ebc191959b>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at SparkPost.Transmissions+<Send>c__async0.MoveNext () [0x000c4] in <6b893430194846f1b88010ebc191959b>:0
All I was trying is to do a sparkpostClient.Transmissions.Send(message).Wait();
@Evengard Hmmmmm..... the unit tests in CI are running against Mono. I have some integration tests started that call this method, so perhaps that will help to diagnose and fix.
In the meantime, can you try switching its mode from async to sync? It's something like:
client.CustomSettings.SendingMode = SendingModes.Sync;
If you switch to this mode, there is no need for the Wait()
I tried both modes. The problem is exactly the same.
Well fiddlesticks. When I check the integration tests in, I'll see what happens. Thank you for reporting.
Get Outlook for iOS
On Fri, Oct 7, 2016 at 10:00 AM -0500, "Evengard" [email protected] wrote:
I tried both modes. The problem is exactly the same.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
If it matters, Mono is running under Linux x64 (debian, Xamarin packages), versions 4.4.2 and 4.6.1 affected.
Thank you @evengard. I don't know what Travis uses by default but I'll try it there first. If it doesn't fail there I'll try running the tests thru docker.
After all the original problem was from my side - the api key was somehow null in the Mono config, that was the cause of this error. But the problem is that fixing it didn't helped.
The new stacktrace is even more weird than the previous. [System.MissingMethodException]: Method 'System.Net.WebHeaderCollection.AddValue'; not found. somewhere in the internals. What might be the cause of that I have no ideas.
[System.AggregateException]: One or more errors occurred.
at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00014] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) [0x00052] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Threading.Tasks.Task.Wait () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at SparkPost.RequestSenders.SyncRequestSender.Send (SparkPost.Request request) [0x0002c] in <6b893430194846f1b88010ebc191959b>:0
at SparkPost.RequestSenders.RequestSender.Send (SparkPost.Request request) [0x00006] in <6b893430194846f1b88010ebc191959b>:0
at SparkPost.Transmissions+<Send>c__async0.MoveNext () [0x00075] in <6b893430194846f1b88010ebc191959b>:0
[System.MissingMethodException]: Method 'System.Net.WebHeaderCollection.AddValue' not found.
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].Start[TStateMachine] (TStateMachine& stateMachine) [0x00031] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Net.Http.HttpClientHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00024] in <3dff384e916e4a45850531402c5defd9>:0
at System.Net.Http.HttpMessageInvoker.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00000] in <3dff384e916e4a45850531402c5defd9>:0
at System.Net.Http.HttpClient.<SendAsync>__BaseCallProxy0 (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00000] in <3dff384e916e4a45850531402c5defd9>:0
at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext () [0x00089] in <3dff384e916e4a45850531402c5defd9>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at SparkPost.RequestSenders.AsyncRequestSender+<GetTheResponse>c__async1.MoveNext () [0x00086] in <6b893430194846f1b88010ebc191959b>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at SparkPost.RequestSenders.AsyncRequestSender+<Send>c__async0.MoveNext () [0x00135] in <6b893430194846f1b88010ebc191959b>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
at SparkPost.RequestSenders.SyncRequestSender+<Send>c__AnonStorey6+<Send>c__async5.MoveNext () [0x0007a] in <6b893430194846f1b88010ebc191959b>:0
Hmm.... http://stackoverflow.com/questions/17187347/webheadercollection-httpwebrequest-on-xamarin#17267044