Not a valid resource name of assembly

Flavius96Flavius96 Member

Hello,

I'm using Xamarin Studio and GTK#(.NET). I have the following problem:
I made an app, and i need to(dinamically) download web images(favicons) and display them in a Gtk.Image widget. When i do this, I get the following error:

System.ArgumentException: 'myfile.ico' is not a valid resource name of assembly 'myApp, Version=1.0.6742.24722, Culture=neutral, PublicKeyToken=null'.
at at Gdk.PixbufLoader.InitFromAssemblyResource(Assembly assembly, String resource)
at at Gdk.PixbufLoader..ctor(Assembly assembly, String resource)
at at Gdk.Pixbuf..ctor(Assembly assembly, String resource)
at at Gdk.Pixbuf.LoadFromResource(String resource)

It works if i add then in the resource folder, BUT I need to make this dinamically(if i add a new site, i want to see it's icon there..).
The code that triggers error:

using (WebClient client = new WebClient())
{
client.DownloadFile(new Uri("somesite/favicon.ico"), Directory.GetCurrentDirectory() + "\\..\\..\\Res\\google.ico");
}
faviconImage.Pixbuf = Gdk.Pixbuf.LoadFromResource("myApp.Res.myfile.ico");

The image is in the folder(i can see it, it's everything ok) but i cannot use it if i dont include it(manually) in the resource folder....

Please help me :'(

Answers

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @Flavius96

    yes, if you are using LoadFromResource() method you need to load the pixbuf from a resource. If you want to load from a file, why not create a new Gdk.Pixbuf from a file with:

    faviconImage = new Gdk.Pixbuf(filename);
    

    where filename is the full path to the file. So I think this should work:

    using (WebClient client = new WebClient())
    {
        client.DownloadFile(new Uri("somesite/favicon.ico"), Directory.GetCurrentDirectory() + "\\google.ico");
    }
    faviconImage = new Gdk.Pixbuf(Directory.GetCurrentDirectory() + "\\google.ico");
    
Sign In or Register to comment.