Open lifuhua123 opened 3 years ago
This reproduces in 4.8.
This seems to be a bug in the compiler actually. When Application.StartupUri
is not in App.xaml, the compiler does not generate and include app.baml in the assembly resources.
...which seems to be an intentional optimization:
@lifuhua123 and this code also hints a workaround: set any property on the Application
element, for example explicitly include ShutdownMode="OnLastWindowClose"
.
I think this issue is a duplicate of this one: https://github.com/dotnet/wpf/issues/4457. As I said in this comment: https://github.com/dotnet/wpf/issues/4457#issuecomment-827078499, the issue is caused by PresentationBuildTasks.dll so it will only apply to SDK-style csproj (.Net Framework or .Net Core) but this issue does not reproduce when using the old csproj style of .Net Framework.
This one reproduces for me with the old project file. That said, I agree this looks caused by the same underlying issue.
@miloush You're right, just tested it again and I was able to reproduce this issue and #4457 using the old project style. I think I just forgot to remove StartupUri in my test.
@ryalanms I think this is meant to be a bug report rather than a question, but perhaps can be closed as duplicate.
@ThomasGoulet73 This problem is different from # 4457. Please look at the sample WpfApp2.zip
@miloush You're right, I added shutdownMode =" onLastWindowClose "and the program starts, but why?
@lifuhua123 The problem is different but the cause is the same. You can also use the same workaround in #4457 of adding another style to your resource dictionary in App.xaml. The bug is that it should generate the InitializeComponent method even if there is only one Style in the resource dictionary. By adding a property, you trigger the generation of InitializeComponent that was already suppose to occur when there is on style.
Okay, so is this a problem or a bug? I tried another method, the program can also start. Set shutdownMode =" onLastWindowClose ", but don't know why? @ThomasGoulet73
This bug should be fixed by dotnet/wpf#8853. For now, you can workaround this issue by adding a dummy item in <Application.Resources>
.
In.NET 5.0 WPF, a window in a container cannot call a style resource in app.xaml , as shown in the figure :