Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 正在尝试从程序集加载png_C#_Wpf - Fatal编程技术网

C# 正在尝试从程序集加载png

C# 正在尝试从程序集加载png,c#,wpf,C#,Wpf,我试图用一个helper类编写helper程序集,该helper类使用一个从资源加载图像的静态方法 这是密码 public static BitmapImage GetImageFromResource(Assembly assembly, string file) { BitmapImage src = new BitmapImage(); src.BeginInit(); src.UriSource = new U

我试图用一个helper类编写helper程序集,该helper类使用一个从资源加载图像的静态方法

这是密码

        public static BitmapImage GetImageFromResource(Assembly assembly, string file)
       {
        BitmapImage src = new BitmapImage();
        src.BeginInit();
        src.UriSource = new Uri(@"pack://application:,,,/" + assembly.GetName().Name + @";component/" + file, UriKind.Absolute);
        src.CacheOption = BitmapCacheOption.OnLoad;
        src.EndInit();

        return src;
       }
我试图从另一个程序集调用此函数,该程序集的png文件以Build Action作为资源(也尝试过,嵌入了资源和内容)

我得到以下错误

Additional information: Cannot locate resource 'coffee.png'.
我做错了什么?同样,C是大写的,但在错误消息中,它似乎试图定位coffee.png而不是coffee.png


有人知道我在这里遗漏了什么吗?

确保正在加载的程序集具有更新的
dll
。尝试对具有
图像的
类库
文件执行
重建
。你所拥有的应该有用。只是,
图像
实际上不在
dll