Reputation: 5409
Greetings
Problem
When i'm trying to add images to my silverlight project I get the error: "AG_E_NETWORK_ERROR"
.
Recreate
I create a new silverlight 4 project without a web part. So I only get MyApplication.
In MyApplication I add a map called "Images" and in that map I add a few images. Egg.png, Chicken.png.
Now I wish to load these images to my silverlight project. In the mainpage.xaml I place:
<Image Source="/Images/Egg.png" />
but this does't load.
So I try it from code behind:
var imag = new BitmapImage(new Uri(@"\Images\Egg.png", UriKind.Relative));
imag.ImageFailed += (s, ea) =>
{
throw new Exception(ea.ErrorException.Message);
};
This however keeps throwing the above error nomather what I try.
The images are set as a resource and "Do Not Copy".
[Edit]
After comments I noticed the image is loading in the original project.
But I have a user control in a different project to which I send the image. From there the loading still fails.
How can I fix this? Am I missing anything?
Upvotes: 1
Views: 1190
Reputation: 45083
This is a terrible generic error message but I believe the problem may simply be that the files can't be found. When you add items to your Silverlight project they don't get copied out to the ClientBin
folder of the hosting site (even on build, regardless of Copy to output directory
settings because this only dictates what makes it to the current project's bin
folder) - you'll need to copy these manually (or eventually use a post-build step), that is:
ClientBin
folder, alongside the .xap
file.Update:
So, there's no website part of the solution, are the resources making it to the bin
folder of the Silverlight project itself? If not, try this:
BuildAction
to Content
Copy to output directory
to Copy Always
, or Copy if newer
Upvotes: 2
Reputation: 70132
When your XAML is parsed:
<Image Source="/Images/Egg.png" />
The URI is converted into a suitable URI for locating your image. If you set the source in code-behind you have to do this conversion yourself. The URI is of this format:
/MyNameSpace;Images/Egg.png
See this related question:
How do you set Image.Source in Silverlight(Code behind)
Upvotes: 0