lepoco / lepoco/wpfui

`System.Windows.Markup.XamlParseException` was thrown in net6.0

Open
#501 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
9.6k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

i have tried 2.0.2 and 2.0.3 and i found the exception could only appear in net6.0 wpf app with 2.0.3
sometimes it wasn't thrown but render a unexcepted window

what's more, if i copied wpf.ui.dll into the folder of the application or didn't use Costura.Fody to compress wpf.ui.dll as resource into application, the exception was never thrown again

here is the expcetion log

C:\GitHub\Serein\Serein\WPF\bin\Debug\net6.0-windows>dotnet Serein-WPF.dll
Unhandled exception. System.Windows.Markup.XamlParseException: “设置 connectionId 时引发了异常。”,行号为“41”,行位 置为“14”。
 ---> System.InvalidCastException: [A]Wpf.Ui.Controls.TitleBar cannot be cast to [B]Wpf.Ui.Controls.TitleBar. Type A originates from 'Wpf.Ui, Version=2.0.3.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' in a byte array. Type B originates from 'Wpf.Ui, Version=2.0.3.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' in a byte array.
   at Serein.Windows.MainWindow.System.Windows.Markup.IComponentConnector.Connect(Int32 connectionId, Object target) in C:\GitHub\Serein\Serein\WPF\Windows\MainWindow.xaml:line 29
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetConnectionId(Object root, Int32 connectionId, Object instance)
   --- End of inner exception stack trace ---
   at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
   at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1_0(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run()
   at Serein.App.Main()

C:\GitHub\Serein\Serein\WPF\Windows\MainWindow.xaml:line 29:
https://github.com/Zaitonn/Serein/blob/c9d1718678c4235e83cec78f0af6f07912685e8e/Serein/WPF/Windows/MainWindow.xaml#L26-L32

To Reproduce

net6.0-windows.zip

  1. download this
  2. run the app
  3. close it
  4. goto 2 again and again
Expected behavior

Open corrrectly and render a correct window

Screenshots

screenshot of error window
image

expected

image

OS version

Windows 10 家庭版 21H2 19044.2486

.NET version
Microsoft.AspNetCore.App 6.0.13 [C:\Users\*\AppData\Local\dotnet-sdk-6.0.113-win-x64\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.13 [C:\Users\*\AppData\Local\dotnet-sdk-6.0.113-win-x64\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.13 [C:\Users\*\AppData\Local\dotnet-sdk-6.0.113-win-x64\shared\Microsoft.WindowsDesktop.App]
WPF-UI NuGet version

2.0.3

Additional context

my repo: https://github.com/Zaitonn/Serein

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Serein/WPF/Windows/MainWindow.xaml around line 29 and reproduce the failure using the linked net6.0-windows.zip, repeating the launch sequence described. Compare runs with wpf.ui.dll copied beside the application versus compressed through Costura.Fody, and verify that the application opens and renders the expected window without the XamlParseException.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.