Wpf: Could not locate icon.ico

Created on 24 Dec 2018  路  4Comments  路  Source: dotnet/wpf

  • .NET Core Version: 3.0 Preview1
  • Windows version: (Windows 10 64bit)
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: No

    Problem description:

Exception on application start:
IOException: Cannot locate resource 'icon.ico'.

Actual behavior:

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.LoadComponent(Object component, Uri resourceLocator)

Expected behavior:

Start successfully and accept icon path for window like it does in .NET framework.

Minimal repro:

  1. Create new .NET core 3.0 WPF project
  2. Right click on project -> properties -> "Icon and manifest" select an .ICO for the application. The selected icon file is now placed into root directory of the project
  3. On MainWindow.xaml add this line for window
    Icon="icon.ico"

IconIssue.zip

issue-type-bug

Most helpful comment

Add

  <ItemGroup>
    <None Remove="icon.ico" />
  </ItemGroup>
  <ItemGroup>
    <Resource Include="icon.ico" />
  </ItemGroup>

between <Project> and </Project> in the csproj, or set "Build Action" to "Resource" in Properties window in Visual Studio.
It (the change of csproj) is done in .Net Framework project automatically, but not in .Net Core project. Is it a Visual Studio issue?

All 4 comments

Add

  <ItemGroup>
    <None Remove="icon.ico" />
  </ItemGroup>
  <ItemGroup>
    <Resource Include="icon.ico" />
  </ItemGroup>

between <Project> and </Project> in the csproj, or set "Build Action" to "Resource" in Properties window in Visual Studio.
It (the change of csproj) is done in .Net Framework project automatically, but not in .Net Core project. Is it a Visual Studio issue?

Is solved

It should be fixed in VS2019.

I Got this issue in VS2019 16.7.2.

Added a new icon. didn't like it. So, I deleted it. Then added other icon with a different name.
It gives an error old icon cannot be found. So, I renamed new one to old name.
Now, it's giving the same error for new icon馃槕.

Was this page helpful?
0 / 5 - 0 ratings