Problem loading embedded resource

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Drew

    #1

    Problem loading embedded resource

    Assembly asm = Assembly.GetExe cutingAssembly( );

    me = new Bitmap(asm.GetM anifestResource Stream("me.gif" ));

    I have used this before without any problem, but now I get:

    An unhandled exception of type 'System.Argumen tException' occurred in
    system.drawing. dll

    Additional information: 'null' is not a valid value for 'stream'.

    I've got the Build Action for me.gif set as Embedded Resource.

    Argh!

    Why can't it find the file?

    Thnx!

    Drew


  • 100

    #2
    Re: Problem loading embedded resource

    Hi Drew,
    Probably the the full name of the resource is not right. Use ILDasm to see
    the actual name of the resource.
    Normaly resources are named
    <Default Namespace>[.<subdir>].<resource-file name>

    where
    *Default Namespace* is the one set in the project properties.
    *subdir* if any is in the casses where you keep resource files in different
    forlders under your project.
    *<resource-file name>* is the name of the resource files.

    But my suggestion is to use ILDasm to see the name of the resources. You can
    find them in MANIFEST node in the main screen

    HTH
    B\rgds
    100
    "Drew" <someone@hotmai l.com> wrote in message
    news:O4Q7nGFtDH A.2448@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Assembly asm = Assembly.GetExe cutingAssembly( );
    >
    > me = new Bitmap(asm.GetM anifestResource Stream("me.gif" ));
    >
    > I have used this before without any problem, but now I get:
    >
    > An unhandled exception of type 'System.Argumen tException' occurred in
    > system.drawing. dll
    >
    > Additional information: 'null' is not a valid value for 'stream'.
    >
    > I've got the Build Action for me.gif set as Embedded Resource.
    >
    > Argh!
    >
    > Why can't it find the file?
    >
    > Thnx!
    >
    > Drew
    >
    >[/color]


    Comment

    • Drew

      #3
      Re: Problem loading embedded resource

      OK, it looks like I just forgot to include the namespace
      when trying to read the embedded resource. :)

      Now, I just want to remove the namespace altogether
      in Visual Studio, but just removing the namespace from
      the code doesn't seem to do the trick.

      What else has to be done to remove the namespace?

      Drew




      "100" <100@100.com> wrote in message
      news:O4dzjNFtDH A.3744@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Hi Drew,
      > Probably the the full name of the resource is not right. Use ILDasm to see
      > the actual name of the resource.
      > Normaly resources are named
      > <Default Namespace>[.<subdir>].<resource-file name>
      >
      > where
      > *Default Namespace* is the one set in the project properties.
      > *subdir* if any is in the casses where you keep resource files in[/color]
      different[color=blue]
      > forlders under your project.
      > *<resource-file name>* is the name of the resource files.
      >
      > But my suggestion is to use ILDasm to see the name of the resources. You[/color]
      can[color=blue]
      > find them in MANIFEST node in the main screen
      >
      > HTH
      > B\rgds
      > 100
      > "Drew" <someone@hotmai l.com> wrote in message
      > news:O4Q7nGFtDH A.2448@TK2MSFTN GP09.phx.gbl...[color=green]
      > > Assembly asm = Assembly.GetExe cutingAssembly( );
      > >
      > > me = new Bitmap(asm.GetM anifestResource Stream("me.gif" ));
      > >
      > > I have used this before without any problem, but now I get:
      > >
      > > An unhandled exception of type 'System.Argumen tException' occurred in
      > > system.drawing. dll
      > >
      > > Additional information: 'null' is not a valid value for 'stream'.
      > >
      > > I've got the Build Action for me.gif set as Embedded Resource.
      > >
      > > Argh!
      > >
      > > Why can't it find the file?
      > >
      > > Thnx!
      > >
      > > Drew
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • 100

        #4
        Re: Problem loading embedded resource

        Hi Drew,
        The only way I can thing of is to go in Project | <prj name> Properties |
        General and delete the *Default Namespace* and rebuild the project. Anyway,
        I don't thing is a good idea because that *Default Namespace* is used by the
        IDE when generates classes, forms, etc. If you delete this property you have
        to add the namespaces for the latter by hand. Thus, better decorate you
        resource names with the namespace when you read the resources. Otherwie
        IMHO the pain will be bigger.

        B\rgds
        100

        "Drew" <someone@hotmai l.com> wrote in message
        news:%23Z4lsWFt DHA.2416@TK2MSF TNGP10.phx.gbl. ..[color=blue]
        > OK, it looks like I just forgot to include the namespace
        > when trying to read the embedded resource. :)
        >
        > Now, I just want to remove the namespace altogether
        > in Visual Studio, but just removing the namespace from
        > the code doesn't seem to do the trick.
        >
        > What else has to be done to remove the namespace?
        >
        > Drew
        >
        >
        >
        >
        > "100" <100@100.com> wrote in message
        > news:O4dzjNFtDH A.3744@TK2MSFTN GP11.phx.gbl...[color=green]
        > > Hi Drew,
        > > Probably the the full name of the resource is not right. Use ILDasm to[/color][/color]
        see[color=blue][color=green]
        > > the actual name of the resource.
        > > Normaly resources are named
        > > <Default Namespace>[.<subdir>].<resource-file name>
        > >
        > > where
        > > *Default Namespace* is the one set in the project properties.
        > > *subdir* if any is in the casses where you keep resource files in[/color]
        > different[color=green]
        > > forlders under your project.
        > > *<resource-file name>* is the name of the resource files.
        > >
        > > But my suggestion is to use ILDasm to see the name of the resources. You[/color]
        > can[color=green]
        > > find them in MANIFEST node in the main screen
        > >
        > > HTH
        > > B\rgds
        > > 100
        > > "Drew" <someone@hotmai l.com> wrote in message
        > > news:O4Q7nGFtDH A.2448@TK2MSFTN GP09.phx.gbl...[color=darkred]
        > > > Assembly asm = Assembly.GetExe cutingAssembly( );
        > > >
        > > > me = new Bitmap(asm.GetM anifestResource Stream("me.gif" ));
        > > >
        > > > I have used this before without any problem, but now I get:
        > > >
        > > > An unhandled exception of type 'System.Argumen tException' occurred in
        > > > system.drawing. dll
        > > >
        > > > Additional information: 'null' is not a valid value for 'stream'.
        > > >
        > > > I've got the Build Action for me.gif set as Embedded Resource.
        > > >
        > > > Argh!
        > > >
        > > > Why can't it find the file?
        > > >
        > > > Thnx!
        > > >
        > > > Drew
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Drew

          #5
          Re: Problem loading embedded resource

          This seems to work pretty good:

          asm.GetManifest ResourceStream( asm.GetName().N ame+ ".me.gif")

          So, turns out it's not really the namespace it wants but the Assembly Name?

          I actually tried making the Default Namespace blank in the project
          properties but that didn't help.

          Would I have to remove the Assembly name in the project properties to be
          able to eliminate the naming decoration?

          Drew

          "100" <100@100.com> wrote in message
          news:e8HPKnFtDH A.1196@TK2MSFTN GP12.phx.gbl...[color=blue]
          > Hi Drew,
          > The only way I can thing of is to go in Project | <prj name> Properties |
          > General and delete the *Default Namespace* and rebuild the project.[/color]
          Anyway,[color=blue]
          > I don't thing is a good idea because that *Default Namespace* is used by[/color]
          the[color=blue]
          > IDE when generates classes, forms, etc. If you delete this property you[/color]
          have[color=blue]
          > to add the namespaces for the latter by hand. Thus, better decorate you
          > resource names with the namespace when you read the resources. Otherwie
          > IMHO the pain will be bigger.
          >
          > B\rgds
          > 100
          >
          > "Drew" <someone@hotmai l.com> wrote in message
          > news:%23Z4lsWFt DHA.2416@TK2MSF TNGP10.phx.gbl. ..[color=green]
          > > OK, it looks like I just forgot to include the namespace
          > > when trying to read the embedded resource. :)
          > >
          > > Now, I just want to remove the namespace altogether
          > > in Visual Studio, but just removing the namespace from
          > > the code doesn't seem to do the trick.
          > >
          > > What else has to be done to remove the namespace?
          > >
          > > Drew
          > >
          > >
          > >
          > >
          > > "100" <100@100.com> wrote in message
          > > news:O4dzjNFtDH A.3744@TK2MSFTN GP11.phx.gbl...[color=darkred]
          > > > Hi Drew,
          > > > Probably the the full name of the resource is not right. Use ILDasm to[/color][/color]
          > see[color=green][color=darkred]
          > > > the actual name of the resource.
          > > > Normaly resources are named
          > > > <Default Namespace>[.<subdir>].<resource-file name>
          > > >
          > > > where
          > > > *Default Namespace* is the one set in the project properties.
          > > > *subdir* if any is in the casses where you keep resource files in[/color]
          > > different[color=darkred]
          > > > forlders under your project.
          > > > *<resource-file name>* is the name of the resource files.
          > > >
          > > > But my suggestion is to use ILDasm to see the name of the resources.[/color][/color][/color]
          You[color=blue][color=green]
          > > can[color=darkred]
          > > > find them in MANIFEST node in the main screen
          > > >
          > > > HTH
          > > > B\rgds
          > > > 100
          > > > "Drew" <someone@hotmai l.com> wrote in message
          > > > news:O4Q7nGFtDH A.2448@TK2MSFTN GP09.phx.gbl...
          > > > > Assembly asm = Assembly.GetExe cutingAssembly( );
          > > > >
          > > > > me = new Bitmap(asm.GetM anifestResource Stream("me.gif" ));
          > > > >
          > > > > I have used this before without any problem, but now I get:
          > > > >
          > > > > An unhandled exception of type 'System.Argumen tException' occurred[/color][/color][/color]
          in[color=blue][color=green][color=darkred]
          > > > > system.drawing. dll
          > > > >
          > > > > Additional information: 'null' is not a valid value for 'stream'.
          > > > >
          > > > > I've got the Build Action for me.gif set as Embedded Resource.
          > > > >
          > > > > Argh!
          > > > >
          > > > > Why can't it find the file?
          > > > >
          > > > > Thnx!
          > > > >
          > > > > Drew
          > > > >
          > > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • 100

            #6
            Re: Problem loading embedded resource

            Hi Drew,[color=blue]
            > I actually tried making the Default Namespace blank in the project
            > properties but that didn't help.[/color]
            It worked for me. When I removed *Default Assembly* and rebuild the project
            the resources didn't have "decoration s" anymore.
            [color=blue]
            >
            > Would I have to remove the Assembly name in the project properties to be
            > able to eliminate the naming decoration?[/color]

            No you can't remove the assembly name because this is the name the compiler
            will give to the executable.
            The *Default Assembly* is what the IDE uses for resources.

            Did you keep your resources in a sub-folder under the the project's main
            folder. In this case IDE will add the sub-folder name before the resource
            file name. In this case AFAIK you can't do anything but put the resources in
            the main folder.
            Check the "Build Action" for the resources. It has to be "Embedded Resource"

            B\rgds
            100[color=blue]
            >
            > Drew
            >
            > "100" <100@100.com> wrote in message
            > news:e8HPKnFtDH A.1196@TK2MSFTN GP12.phx.gbl...[color=green]
            > > Hi Drew,
            > > The only way I can thing of is to go in Project | <prj name> Properties[/color][/color]
            |[color=blue][color=green]
            > > General and delete the *Default Namespace* and rebuild the project.[/color]
            > Anyway,[color=green]
            > > I don't thing is a good idea because that *Default Namespace* is used by[/color]
            > the[color=green]
            > > IDE when generates classes, forms, etc. If you delete this property you[/color]
            > have[color=green]
            > > to add the namespaces for the latter by hand. Thus, better decorate you
            > > resource names with the namespace when you read the resources. Otherwie
            > > IMHO the pain will be bigger.
            > >
            > > B\rgds
            > > 100
            > >
            > > "Drew" <someone@hotmai l.com> wrote in message
            > > news:%23Z4lsWFt DHA.2416@TK2MSF TNGP10.phx.gbl. ..[color=darkred]
            > > > OK, it looks like I just forgot to include the namespace
            > > > when trying to read the embedded resource. :)
            > > >
            > > > Now, I just want to remove the namespace altogether
            > > > in Visual Studio, but just removing the namespace from
            > > > the code doesn't seem to do the trick.
            > > >
            > > > What else has to be done to remove the namespace?
            > > >
            > > > Drew
            > > >
            > > >
            > > >
            > > >
            > > > "100" <100@100.com> wrote in message
            > > > news:O4dzjNFtDH A.3744@TK2MSFTN GP11.phx.gbl...
            > > > > Hi Drew,
            > > > > Probably the the full name of the resource is not right. Use ILDasm[/color][/color][/color]
            to[color=blue][color=green]
            > > see[color=darkred]
            > > > > the actual name of the resource.
            > > > > Normaly resources are named
            > > > > <Default Namespace>[.<subdir>].<resource-file name>
            > > > >
            > > > > where
            > > > > *Default Namespace* is the one set in the project properties.
            > > > > *subdir* if any is in the casses where you keep resource files in
            > > > different
            > > > > forlders under your project.
            > > > > *<resource-file name>* is the name of the resource files.
            > > > >
            > > > > But my suggestion is to use ILDasm to see the name of the resources.[/color][/color]
            > You[color=green][color=darkred]
            > > > can
            > > > > find them in MANIFEST node in the main screen
            > > > >
            > > > > HTH
            > > > > B\rgds
            > > > > 100
            > > > > "Drew" <someone@hotmai l.com> wrote in message
            > > > > news:O4Q7nGFtDH A.2448@TK2MSFTN GP09.phx.gbl...
            > > > > > Assembly asm = Assembly.GetExe cutingAssembly( );
            > > > > >
            > > > > > me = new Bitmap(asm.GetM anifestResource Stream("me.gif" ));
            > > > > >
            > > > > > I have used this before without any problem, but now I get:
            > > > > >
            > > > > > An unhandled exception of type 'System.Argumen tException' occurred[/color][/color]
            > in[color=green][color=darkred]
            > > > > > system.drawing. dll
            > > > > >
            > > > > > Additional information: 'null' is not a valid value for 'stream'.
            > > > > >
            > > > > > I've got the Build Action for me.gif set as Embedded Resource.
            > > > > >
            > > > > > Argh!
            > > > > >
            > > > > > Why can't it find the file?
            > > > > >
            > > > > > Thnx!
            > > > > >
            > > > > > Drew
            > > > > >
            > > > > >
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...