madskristensen / SvgViewer

Shows the rendered image of .svg files
Other
27 stars 10 forks source link

Cross-thread UI access error logged to VS output window #7

Open daiplusplus opened 3 years ago

daiplusplus commented 3 years ago

I'll preface this bug report with my own personal thank-you for making this extension - it's really helped me with switching from to SVG graphics when modernizing my web projects.

As for the bug report...

Repro steps:

  1. Have a .NET Core 3.1 class-library project (not an ASP.NET Core project) that contains .svg files.
  2. Mouse-over them in the Solution Explorer
  3. This appears in the Output > Extensions window:
System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
   at System.Windows.Threading.Dispatcher.VerifyAccess()
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at SvgViewer.SvgAdornment.<GenerateImageAsync>d__6.MoveNext() in C:\projects\svgviewer\src\Adornments\SvgAdornment.cs:line 77
   --- End of inner exception stack trace ---
---> (Inner Exception #0) System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
   at System.Windows.Threading.Dispatcher.VerifyAccess()
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at SvgViewer.SvgAdornment.<GenerateImageAsync>d__6.MoveNext() in C:\projects\svgviewer\src\Adornments\SvgAdornment.cs:line 77<---
madskristensen commented 3 years ago

I can't reproduce the issue, but I moved a try/catch block such that line 77 is now handled in case of exceptions. This should take care of the stack trace showing up in the output window