Postmark - API 或 Nuget 包 null 引用错误

Postmark - API or Nuget package null reference error

提问人:Paul Glover 提问时间:11/16/2023 最后编辑:Brian Tompsett - 汤莱恩Paul Glover 更新时间:11/17/2023 访问量:24

问:

我正在尝试实现 Postmark API 或 Nuget 解决方案,但收到相同的错误。所以它一定是我的环境?

Nuget 包返回与下面相同的结果。

我尝试了这段代码来调用 Postmark API,但附加的图像在我的 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

这些是“应用程序”下的“事件查看器”中的这些错误

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()
.NET vb.net Visual-Studio 邮戳

评论


答: 暂无答案