I am trying to implement either the Postmark API or Nuget solution but receiving the same error. So it must be my environment?
The Nuget package returns the same result as below.
I tried this code to call Postmark API but the attached image it what is returning in my Visual Studio.
Public Async Function SendEmail() As Task(Of JObject)
Using client As HttpClient = New HttpClient()
Using res = New HttpRequestMessage(New HttpMethod("POST"), "ENDPOINT")
res.Headers.TryAddWithoutValidation("Accept", "application/json")
res.Headers.TryAddWithoutValidation("X-Postmark-Server-Token", "TOKENKEY")
Dim s As String = ""
s = s & "{"
s = s & """" & "From" & """" & ": " & """" & "MyFromEmail.something.com" & """" & ","
s = s & """" & "To" & """" & ": " & """" & "MyToEmail.something.com" & """" & ","
s = s & """" & "Subject" & """" & ": " & """" & "Test Email" & """" & ","
s = s & """" & "TextBody" & """" & ": " & """" & "Hope this works" & """" & ","
res.Content = New StringContent(s)
res.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json")
Try
Dim sendResult = Await client.SendAsync(res)
Catch ex As Exception
Dim a As String = ex.Message
End Try
End Using
End Using
End Function
These are these error in the Event Viewer under Application
ERROR 1
Faulting application name: w3wp.exe, version: 10.0.17763.1, time stamp: 0xa7ccada2
Faulting module name: KERNELBASE.dll, version: 10.0.17763.4720, time stamp: 0xd343834f
Exception code: 0xe0434352
Fault offset: 0x00125a12
Faulting process id: 0x177c
Faulting application start time: 0x01da187983c6577d
Faulting application path: C:\Windows\SysWOW64\inetsrv\w3wp.exe
Faulting module path: C:\Windows\System32\KERNELBASE.dll
Report Id: 2108f9a2-e7c5-4835-88ce-f59a602aef0e
Faulting package full name:
Faulting package-relative application ID:
ERROR 2
Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
at System.Web.ThreadContext.AssociateWithCurrentThread(Boolean)
at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean)
at System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(System.Threading.SendOrPostCallback, System.Object)
at System.Web.LegacyAspNetSynchronizationContext.CallCallback(System.Threading.SendOrPostCallback, System.Object)
at System.Web.LegacyAspNetSynchronizationContext.Post(System.Threading.SendOrPostCallback, System.Object)
at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.PostAction(System.Object)
at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback, System.Object, System.Threading.Tasks.Task ByRef)
at System.Threading.Tasks.AwaitTaskContinuation+<>c.<ThrowAsyncIfNecessary>b__18_0(System.Object)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
ERROR 3
An unhandled exception occurred and the process was terminated.
Application ID: /LM/W3SVC/1/ROOT/kbmo
Process ID: 6012
Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
StackTrace: at System.Web.ThreadContext.AssociateWithCurrentThread(Boolean setImpersonationContext)
at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext)
at System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state)
at System.Web.LegacyAspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state)
at System.Web.LegacyAspNetSynchronizationContext.Post(SendOrPostCallback callback, Object state)
at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.PostAction(Object state)
at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task& currentTask)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.AwaitTaskContinuation.<>c.<ThrowAsyncIfNecessary>b__18_0(Object s)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
ERROR 4
An unhandled exception occurred and the process was terminated.
Application ID: /LM/W3SVC/2/ROOT
Process ID: 20028
Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
StackTrace: at System.Web.ThreadContext.AssociateWithCurrentThread(Boolean setImpersonationContext)
at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext)
at System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state)
at System.Web.LegacyAspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state)
at System.Web.LegacyAspNetSynchronizationContext.Post(SendOrPostCallback callback, Object state)
at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.PostAction(Object state)
at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task& currentTask)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.AwaitTaskContinuation.<>c.<ThrowAsyncIfNecessary>b__18_0(Object s)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()