Visual Studio error CS1504: Source file 'App.xaml' could not be opened - App.g.i.cs

I have a three project solution that uses a WPF project with two other projects. One of these projects calls the WPF project for prototyping and another is a Prism project that is used to demonstrate the WPF project. I converted the WPF project from an application project type to a WPF class library type, which worked well up until I went to build the solution as a release when I received two errors saying:
Visual Studio error CS1504: Source file 'App.xaml' could not be opened
Visual Studio error CS1504: Source file 'MainWindow.xaml' could not be opened
The error referenced the App.g.i.cs
file and stated that this file could no longer open the the App.xaml
or MainWindow.xaml
files, despite them no longer being needed now that the project has been converted from a WPF application to a WPF class library type.
Why is this still referencing the App.g.i.cs
file when it should no longer be needed? I've tried restarting VS and cleaning & rebuilding the project, but none of these have worked.
Answer
The problem seems to have stemmed from the WPF project having been converted from a WPF project to a WPF control library. The fix was to manually delete the App.g.i.cs
file, at which point everything started compiling.
Weirdly, if I restored the App.g.i.cs after that point, it was completely ignored. It seems that VS was trying to reach it, even though it was no longer needed for that project type, but once it realised it no longer needed it, it completely ignored it.
Enjoyed this article?
Check out more content on our blog or follow us on social media.
Browse more articles