CommunityToolkit/WindowsCommunityToolkit

Null reference error from PrintHelper

Open

#3465 aperta il 4 set 2020

Vedi su GitHub
 (9 commenti) (0 reazioni) (0 assegnatari)C# (1403 fork)batch import
bug :bug:good first issuehelp wantedhelpers :raised_hand:

Metriche repository

Star
 (5708 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Describe the bug

We are occasionally getting null reference errors from users in our logging, originating from the PrintHelper.

I haven't been able to reproduce the issue, only seen in the logs, I have provided the stack trace.

Is the fix as simple as adding a null ref check in the PrintHelper class?

    System.NullReferenceException: Object reference not set to an instance of an object.

    Microsoft.Toolkit.Uwp.Helpers    PrintHelper.<DetachCanvas>b__39_0 () /_/Microsoft.Toolkit.Uwp/Helpers/PrintHelper/PrintHelper.cs at 227:21
    System    Action.Invoke ()
    Microsoft.Toolkit.Uwp.Helpers.DispatcherHelper    <>c__DisplayClass11_0.<AwaitableRunAsync>b__0 () /_/Microsoft.Toolkit.Uwp/Helpers/DispatcherHelper.cs at 258:21
    Microsoft.Toolkit.Uwp.Helpers.DispatcherHelper.<>c__DisplayClass10_0$1<System    __Canon>.<AwaitableRunAsync>b__0 () /_/Microsoft.Toolkit.Uwp/Helpers/DispatcherHelper.cs at 235:21
    System.Runtime.ExceptionServices    ExceptionDispatchInfo.Throw ()
    System.Runtime.CompilerServices    TaskAwaiter.ThrowForNonSuccess (Task)
    System.Runtime.CompilerServices    TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task)
    System.Runtime.CompilerServices    TaskAwaiter.ValidateEnd (Task)
    System.Runtime.CompilerServices    TaskAwaiter.GetResult ()
    Microsoft.Toolkit.Uwp.Helpers.PrintHelper    <DetachCanvas>d__39.MoveNext () /_/Microsoft.Toolkit.Uwp/Helpers/PrintHelper/PrintHelper.cs at 238:13
    System.Runtime.ExceptionServices    ExceptionDispatchInfo.Throw ()
    System.Runtime.CompilerServices    TaskAwaiter.ThrowForNonSuccess (Task)
    System.Runtime.CompilerServices    TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task)
    System.Runtime.CompilerServices    TaskAwaiter.ValidateEnd (Task)
    System.Runtime.CompilerServices    TaskAwaiter.GetResult ()
    Microsoft.Toolkit.Uwp.Helpers.PrintHelper.<>c__DisplayClass40_1    <<PrintTaskRequested>b__2>d.MoveNext () at 16707566
    System.Runtime.ExceptionServices    ExceptionDispatchInfo.Throw ()
    System.Runtime.CompilerServices.AsyncMethodBuilderCore    <>c.<ThrowAsync>b__7_0 (Object)
    System    Action`1.Invoke (T)    
    System.Threading.WinRTSynchronizationContext
    Invoker.InvokeCore ()    System.Runtime.InteropServices    McgMarshal.ThrowOnExternalCallFailed (Int32, RuntimeTypeHandle)
    __Interop    ComCallHelpers.Call ($__ComObject __this, RuntimeTypeHandle __typeHnd, Int32 __targetIndex) Call at 15732480
    __Interop.ForwardComStubs    Stub_11<System.__Canon> (Void* InstParam, $__ComObject __this, Int32 __targetIndex) Stub_11 at 16707566
    Microsoft.AppCenter.Utils    ApplicationLifecycleHelper.<ctor>b__17_1 (Object sender, $UnhandledErrorDetectedEventArgs eventArgs)

Environment

It doesn't seem to be specific to any device, Toolkit or Windows verison.

Guida contributor