Cannot locate resource

后端 未结 2 843
一个人的身影
一个人的身影 2021-02-04 14:38

I don\'t know exactly if it is a bug but i am getting all the time runtime IOException error saying Cannot locate resource.

I am loading some images in my app (c#, WPF)

相关标签:
2条回答
  • 2021-02-04 14:45

    I've had a similar issue: IOException, cannot locate a png resource which indeed existed in the assembly.

    I found the solution by explicitly specifying the assembly name, even though the caller was in the same assembly as the resource.

    Here's how it looks with a Pack URI syntax:

    pack://application:,,,/MyAssemblyName;component/MyResourcesFolder/MyImage.png
    

    (For more about Pack URIs see http://msdn.microsoft.com/en-us/library/aa970069.aspx)

    Edit: One more thing I had to do after specifying the assembly name was to Clean the project. The problem returns after build but was resolved after cleaning the intermediate products. This is definitely a bug in Visual Studio.

    0 讨论(0)
  • 2021-02-04 14:47

    You need to set the build action of the image to the type 'Resource'.

    Right-mouse click on the file >> Properties >> set 'Build Action' to 'Resource'

    0 讨论(0)
提交回复
热议问题