Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug SilverLight 2 (RCO): Sys.InvalidOperationException (when image does not exist)
5 replies. Latest Post by frockyroshan on November 7, 2008.
(1)
DrGriff
Member
16 points
51 Posts
10-09-2008 8:57 AM |
I have an image that is defined in the XAML:
<Image x:Name="ProductZero" Grid.Row="3" Grid.Column="3" Grid.RowSpan="12" Grid.ColumnSpan="12" Opacity="1" />
In my C# code, I set the source (from a value got from the database).
Uri uri = new Uri(_products.ElementAt((int)productZeroIndex).PictureUrl, UriKind.Absolute);ImageSource img = new BitmapImage(uri);this.ProductZero.SetValue(Image.SourceProperty, img);
If the product image can not be found (i.e. http://www.myCompany.com/images/products/myGraphic.jpg ) then this causes a JavaScript error:
From FireFox (IE doesn't give that much data)
Error: Sys.InvalidOperationException: ImageError error #4001 in control 'Xaml1': AG_E_NETWORK_ERROR
This is fired from :
function Sys$UI$Silverlight$Control$_pluginError(slSender, e)
Maybe this is acceptable behaviour ?
Griff
HarshBar...
Star
9908 points
1,719 Posts
10-09-2008 10:22 AM |
Hi,
I just tried your code and made a slight modification to run at my end and found it is working.
Uri uri = new Uri("http://localhost:1628/a03.jpg", UriKind.Absolute);ImageSource img = new BitmapImage(uri);myImage.SetValue(Image.SourceProperty,img);
This error" #4001 in control 'Xaml1': AG_E_NETWORK_ERROR" normally comes when it will niot find image at that Particular Path.
Make sure are you able to type your image String to Browser which you are setting in URI and able to see image...
10-09-2008 12:45 PM |
Hi
The problem is that the graphic will be on a different server beyond my control and it may not exist - in the cases where it does NOT exist, I get this JavaScript error. In "traditional" applications, I simply get a broken image. Whilst this looks less attractive, it does not cause an error that may worry some end users.
Maybe Silverlight could come with a default transparent graphic that it swaps if the image doesn't exist - that way, not "broken image" icons and no JavaScript errors ;-)
10-10-2008 3:21 AM |
Looks like you are not handling media failed event try to handle that.
Write your appropriate logic there .
Then you will not get this error.
10-10-2008 4:03 AM |
Fantastic - didn't know about this event ("ImageFailed" for an <Image/>)
frockyro...
10 points
9 Posts
11-07-2008 7:23 PM |
I ran into similar problem and was scrathing my head for more than a hour:
Following is what I did.
1) Place the image file in the webapplications ClientBin folder. Then you can directly use your code.
for e.g. I used the below code and it worked fine.
BitmapImage book1 = new BitmapImage(new Uri("book1.jpg", UriKind.Relative));
2) secondly, silverlight doesn't accept gif immage extensions. So I had to convert them to jpg.
Hope this helps you.