How to access embedded resources? 
Author Message
 How to access embedded resources?

I want to access an image in my WinForm UserControl project which I have
already added to the project and set it to "Embedded Resource".
Now tried to access this image with:

    Private imgTest As Image = Bitmap.FromStream( _
      Me.GetType().Assembly.GetManifestResourceStream("Test.gif"))

This gives no errors when writing it (no squiggly underlining), and it
compiles without any errors as well.
However, if I add it to the Toolbox (which also works without problems) and
then try to create an instance of it on a form, I only get the following
error message:

"An error has occurred trying to create an instance of blabla. The error
is: 'null' is not a valid value for 'stream'".

Looks like my declaration is wrong... so, how should the declaration look
like?

--
Tenchi (remove 'spam.be.gone' for emails)

My VB.net Download Manager (Version 1.21.1400.0)
Homepage: http://www.*-*-*.com/
Mailing list: http://www.*-*-*.com/



Sun, 10 Apr 2005 03:49:38 GMT  
 How to access embedded resources?
Hi,

To access embedded resources, you will need to qualifiy the resource name
with the project root namespace (can be seen in the project property pages)

So if the project root namespace is WindowsApplication1, you would use
Private imgTest As Image = Bitmap.FromStream( _

Me.GetType().Assembly.GetManifestResourceStream("WindowsApplication1.Test.gi
f"))

Hope that helps,

Ernest
VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.

Quote:
> I want to access an image in my WinForm UserControl project which I have
> already added to the project and set it to "Embedded Resource".
> Now tried to access this image with:

>     Private imgTest As Image = Bitmap.FromStream( _
>       Me.GetType().Assembly.GetManifestResourceStream("Test.gif"))

> This gives no errors when writing it (no squiggly underlining), and it
> compiles without any errors as well.
> However, if I add it to the Toolbox (which also works without problems)
and
> then try to create an instance of it on a form, I only get the following
> error message:

> "An error has occurred trying to create an instance of blabla. The error
> is: 'null' is not a valid value for 'stream'".

> Looks like my declaration is wrong... so, how should the declaration look
> like?

> --
> Tenchi (remove 'spam.be.gone' for emails)

> My VB.net Download Manager (Version 1.21.1400.0)
> Homepage: http://mitglied.lycos.de/downloadwunder/
> Mailing list: http://de.groups.yahoo.com/group/dw-net/



Mon, 11 Apr 2005 04:19:08 GMT  
 How to access embedded resources?
There are two gotchas when retrieving a resource.  The first is that even
though VB is not case sensitive, the frameworks function
GetManifestResourceStream() is, so you need to make sure the string case
matches the name in your project.  The other gotcha is that the name must be
fully qualified, e.g. "ProjectName.Test.gif"

Tyler
Vb.Net Development
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> I want to access an image in my WinForm UserControl project which I have
> already added to the project and set it to "Embedded Resource".
> Now tried to access this image with:

>     Private imgTest As Image = Bitmap.FromStream( _
>       Me.GetType().Assembly.GetManifestResourceStream("Test.gif"))

> This gives no errors when writing it (no squiggly underlining), and it
> compiles without any errors as well.
> However, if I add it to the Toolbox (which also works without problems)
and
> then try to create an instance of it on a form, I only get the following
> error message:

> "An error has occurred trying to create an instance of blabla. The error
> is: 'null' is not a valid value for 'stream'".

> Looks like my declaration is wrong... so, how should the declaration look
> like?

> --
> Tenchi (remove 'spam.be.gone' for emails)

> My VB.net Download Manager (Version 1.21.1400.0)
> Homepage: http://mitglied.lycos.de/downloadwunder/
> Mailing list: http://de.groups.yahoo.com/group/dw-net/



Mon, 11 Apr 2005 04:59:19 GMT  
 How to access embedded resources?

Quote:
> I want to access an image in my WinForm UserControl project
> which I have  already added to the project and set it to
> "Embedded Resource". Now tried to access this image with:

>     Private imgTest As Image = Bitmap.FromStream( _
>       Me.GetType().Assembly.GetManifestResourceStream("Test.gif"))

> This gives no errors when writing it (no squiggly underlining),
> and it  compiles without any errors as well.
> However, if I add it to the Toolbox (which also works without
> problems) and  then try to create an instance of it on a form, I
> only get the following  error message:

> "An error has occurred trying to create an instance of blabla.
> The error  is: 'null' is not a valid value for 'stream'".

> Looks like my declaration is wrong... so, how should the
> declaration look  like?

The full name of your resource is

"<project's root namespace>.Test.gif"

You can list the names in your assembly:

Dim assy As [Assembly]
assy = [Assembly].GetExecutingAssembly
MsgBox(String.Join(Environment.NewLine, ass.GetManifestResourceNames))

Armin



Thu, 14 Apr 2005 22:36:43 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Playing WAV from Embedded Resource

2. embedding resources

3. Help with loading embedded resources

4. Reference embedded resource

5. Embed sounds into VB resources

6. Embedded Resource (.ico or .bmp) and ListView

7. ImageList and an embedded resource file.

8. Using "embedded resources"

9. Web control using embedded resource

10. GIFs as Embedded Resources

11. Embedded Resources in VB

12. How does one display embedded AVI resources?

 

 
Powered by phpBB® Forum Software