Null in stream

alaric

Well-known member
Joined
Oct 12, 2005
Messages
53
Programming Experience
Beginner
Hi,

everytime I call this piece of code, it end with an exepction
VB.NET:
[SIZE=2][COLOR=#0000ff]
Dim[/COLOR][/SIZE][SIZE=2] strm [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.IO.Stream = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].GetType().Assembly.GetManifestResourceStream("fullbuttonface.bmp")
_buttonFace = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Bitmap(strm)
[/SIZE]

the ex is:
Message "'null' is not a valid value for 'stream'." String

these are my imports
VB.NET:
[SIZE=2][COLOR=#0000ff]
Imports[/COLOR][/SIZE][SIZE=2] Microsoft.VisualBasic
[/SIZE][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System
[/SIZE][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Drawing
[/SIZE][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.IO
[/SIZE][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Reflection
[/SIZE][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Windows.Forms
[/SIZE]

I dont get it. I have both of the bmp's at the location where my app is located. (and to be sure also in \bin)

what Im I doing wrong (I call this form another form)
ideas?
 
Thanks for your reply,
I replaced it but... no luck.. same err ("'null' is not a valid value for 'stream'." )

hmmmm:(

Here are more details, hopefully this make sit more clear.

I try to make a button in a datagrid. so from my form (with the datagrid) like this:
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] tsCursFin [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataGridTableStyle
tsCursFin = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridTableStyle
[/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2]tsCursFin.RowHeadersVisible = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] colCount [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2]colCount = 0
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] buttonColStyle [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataGridButtonColumn = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][SIZE=2]buttonColStyle = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridButtonColumn(colCount) [/SIZE][SIZE=2][COLOR=#008000]'pass the column#[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]etcetc
[/COLOR][/SIZE]
then it will jump to a "NAMEPACE" called
VB.NET:
[SIZE=2][COLOR=#0000ff]
Imports[/COLOR][/SIZE][SIZE=2] System.IO
[/SIZE][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Reflection
[/SIZE][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Windows.Forms
[/SIZE][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] LetsDance.frmAdresboek[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Namespace[/COLOR][/SIZE][SIZE=2] DataGridButton
[/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] DataGridButtonColumn
[/SIZE][SIZE=2][COLOR=#0000ff]Inherits[/COLOR][/SIZE][SIZE=2] DataGridTextBoxColumn[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Event[/COLOR][/SIZE][SIZE=2] CellButtonClicked [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataGridCellButtonClickEventHandler
[/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] _buttonFace [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Bitmap
[/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] _buttonFacePressed [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Bitmap
[/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] _columnNum [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] _pressedRow [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
 
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] colNum [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2])
_columnNum = colNum
_pressedRow = -1
[/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strm [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.IO.Stream = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].GetType().Assembly.GetManifestResourceStream("fullbuttonface.bmp")
_buttonFace = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Bitmap(strm)
strm = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].GetType().Assembly.GetManifestResourceStream("fullbuttonfacepressed.bmp")
_buttonFacePressed = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Bitmap(strm)
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
Console.WriteLine(ex)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'New
[/COLOR][/SIZE]

Does this has something to do with throwing values from one piece to another? and back? (this part is still a bit fuzzy to me)
 
Last edited:
The only time i've had this error is when i havent typed the name of the bitmap correctly. I havent got time to go through this code at the moment but double check that the name of the bitmap is exactly what you have typed and that you have set the bitmap as an emmbedded resource. I'll check back later.
 
[resolved]

thanks vis781,

to avoid making typos I did "add existing item" and just picked to bmp files.
I changed the build action to "embedded resource"

still no luck (same null error)

meanwhile I solved it while doing:
VB.NET:
?Me.GetType().Assembly.GetManifestResourceNames
{Length=19}
(0): "LetsDance.fullbuttonfacepressed.bmp"
(1): "LetsDance.frmLogin.resources"
(2): "LetsDance.frmAdresboek.resources"
(3): "LetsDance.frmSplash.resources"
(4): "LetsDance.frmSetup.resources"
(5): "LetsDance.frmMain.resources"
(6): "LetsDance.FrmEmail.resources"
(7): "LetsDance.frmConfig.resources"
(8): "LetsDance.frmEmailOnly.resources"
(9): "LetsDance.DataGridButton.DataGridTextButtonColumn.resources"
(10): "LetsDance.frmLicentie.resources"
(11): "LetsDance.frmSendStatus.resources"
(12): "LetsDance.frmBase.resources"
(13): "LetsDance.DataGridButton.DataGridButtonColumn.resources"
(14): "LetsDance.usrCMenu.resources"
(15): "LetsDance.frmBedrijf.resources"
(16): "LetsDance.fullbuttonface.bmp"
(17): "LetsDance.frmSave.resources"
(18): "LetsDance.frmInschrijven.resources"

further a bit
VB.NET:
?Me.GetType().Assembly.GetManifestResourceStream("LetsDance.fullbuttonface.bmp")
{System.IO.__UnmanagedMemoryStream}
[System.IO.__UnmanagedMemoryStream]: {System.IO.__UnmanagedMemoryStream}
CanRead: True
CanSeek: True
CanWrite: False
Length: 5298
Null: {System.IO.Stream.NullStream}
Position: 0

WORKED!!!:)

so it seems that (when going to another namespace) you have to specify the namespace.

namespace are still unclear to me.
how to use it in your advantage? and or When to use it?

thanks in advance (for thinking with me)
 
Last edited:
Back
Top