Skip to main content

Microsoft Silverlight

Answered Question SilverLight 2 (RCO): Sys.InvalidOperationException (when image does not exist)RSS Feed

(1)

DrGriff
DrGriff

Member

Member

16 points

51 Posts

SilverLight 2 (RCO): Sys.InvalidOperationException (when image does not exist)

 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 

HarshBardhan
HarshBar...

Star

Star

9908 points

1,719 Posts

Re: SilverLight 2 (RCO): Sys.InvalidOperationException (when image does not exist)

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...

Mark as answer if this post answered your question.

Harsh Bardhan

DrGriff
DrGriff

Member

Member

16 points

51 Posts

Re: SilverLight 2 (RCO): Sys.InvalidOperationException (when image does not exist)

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 ;-)

Griff

HarshBardhan
HarshBar...

Star

Star

9908 points

1,719 Posts

Answered Question

Re: SilverLight 2 (RCO): Sys.InvalidOperationException (when image does not exist)

Hi,

 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.

Mark as answer if this post answered your question.

Harsh Bardhan

DrGriff
DrGriff

Member

Member

16 points

51 Posts

Answered Question

Re: SilverLight 2 (RCO): Sys.InvalidOperationException (when image does not exist)

Fantastic - didn't know about this event ("ImageFailed" for an <Image/>)

Griff

frockyroshan
frockyro...

Member

Member

10 points

9 Posts

Re: SilverLight 2 (RCO): Sys.InvalidOperationException (when image does not exist)

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.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities