Reputation: 8357
I have a problem with a BitmapImage in wpf. When i create it it gives a filenotfound exception, which says it's missing the PresentationCore.resources assembly. But i've added it to my references list and it still throws the same exception
Uri filename = new Uri(@"D:\barcode_zwart_wit.jpg", UriKind.Absolute);
BitmapImage image = new BitmapImage(filename); //<-- FileNotFound Exception
Does anyone have any idea what's the problem? Does PresentationCore.resources have any dependencies i don't know about?
Upvotes: 0
Views: 1122
Reputation: 101
The problem might be with the image's color profile being unavailable. Use BitmapImage.CreateOptions property to ignore color profile information as below:
var bmp = new BitmapImage();
bmp.BeginInit();
bmp.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
bmp.UriSource = uri;
bmp.EndInit();
// Use the bmp variable for further processing and dispose it
I had the same issue with a few of .jpg
images and this resolved it.
Upvotes: 1
Reputation: 8357
I've solved it by using AppDomain.CurrentDomain.AssemblyResolve. it's an event which is called if a certain assembly can't be found.
in constructor:
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
CurrentDomain_AssemblyResolve:
Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string missingAssemblyName = args.Name.Remove(args.Name.IndexOf(',');
if ( missingAssemblyName == "PresentationCore.resources" )
{
string s = "C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PresentationCore.resources.dll";
return Assembly.LoadFile(s);
}
return;
}
Upvotes: 0