.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

NULL value exception when trying to save to stream

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :ASP.Net

Im trying to resize an image. I have the original file and then try to resize it and save it to a new image.
However, I get an exception because the value of stream cannot be null. This makes sense, but I dont know how to prevent it:

Value cannot be null.
Parameter name: stream

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: stream

Source Error:

Line 395:
Line 396:        Dim toStream As System.IO.Stream
Line 397:        thumbnailBitmap.Save(toStream, origimage.RawFormat)
Line 398:        thumbnailGraph.Dispose()
Line 399:        thumbnailBitmap.Dispose()

Dim origimage As Image=System.Drawing.Image.FromStream(FU.PostedFile.InputStream)
        Dim thumbnailBitmap = New Bitmap(newWidth, newHeight)
        Dim t

View Complete Post

More Related Resource Links

Page.FindControl Causing Null Reference Exception


Hi guys,

I developed a page in VWD 2008 and it works perfectly locally, but when I deployed it on the server every Page.FindControl() call is causing the NullReference Exception "Object reference not set to an instance of an object. " Can anyone help me out? Code is below


Mike Marshall

            For i As Integer = 1 To 10
                If (CType(Page.FindControl("last_" & i), TextBox).Text.Length > 0) Or (CType(Page.FindControl("first_" & i), TextBox).Text.Length > 0) Or (CType(Page.FindControl("dob_" & i), TextBox).Text.Length > 0) Then
                    Dim person_entry(7) As String
                    person_entry(0) = info_list.Count - 1
                    person_entry(1) = CType(Page.FindControl("last_" & i), TextBox).Text
                    person_entry(2) = CType(Page.FindControl("first_" & i), TextBox).Text
                    person_entry(3) = CType(Page.FindControl("dob_" & i), TextBox).Text
                    person_entry(4) = CType(Page.FindControl("appear_" & i), TextBox).Text
                    person_entry(5) = CType(Page.FindControl("mental_" & i), TextBox).Text
                    person_entry(6) = CType(Page.FindControl("behave_" & i), TextB

FileNotFound exception trying to open a site - Farm.local is Null - x64

  Hello I've created a simple asp.net application to open a site and display the title of the corresponding web. But i'm getting FileNotFoundException while trying to open the site. The same code works perfectly when i run it in a console app. My spec Windows Server 2008 R2 x64 SharePoint 2007 x64 Visual Studio 2005 My target for the asp.net app is set to 'Any CPU'. As far as permissions is considered i've checked that the current identity using which VS2005 hosts the asp.net app has full rights. In fact i've used the same identity for app pools in IIS. As an asp.net web application As a console application Any ideas? Regards NLV Visit SharePoint User group - India

Null reference exception

Hi.. I'm trying to retreive values from the textboxes in the footer row of the grid view. My code is : -         con.Open();        SqlCommand com = new SqlCommand("select count(*) from prod", con);        int c = (Int32)com.ExecuteScalar();                if (c == 0)        {            DataTable dt = new DataTable();            DataColumn c1 = new DataColumn("ID");            dt.Columns.Add(c1);            DataColumn c2 = new DataColumn("DESCRIPTION");            dt.Columns.Add(c2);            DataColumn c3 = new DataColumn("QUANTITY");            dt.Columns.Add(c3);            DataColumn c4 = new DataColumn("DATE");          &nbs

Null Reference Exception was not handled by user Object Reference not set to instance of an object

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Security.Principal;using System.Data;using System.Data.SqlClient;using System.Windows;using System.Collections; public partial class Default2 : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {     }    private bool tableCopied = false;    private DataTable originalDataTable;     protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)    {         if (e.Row.RowType == DataControlRowType.DataRow)        {            //string sValue = e.Row.Cells[3].Text;             if (!tableCopied)            {                originalDataTable = ((System.Data.DataRowView)e.Row.DataItem).Row.Table.Copy();                ViewState["originalDataTable"] = originalDataTable;      &nbs

Accessing a published web service gives null ref exception. Won't occur in test though?

I have an Asp.net web service that I created using Visual Studio 2005. I can acess the web service in my testenvironment, call methods and return data as expected. If this web service is published to the outside world (Outside of the company firewall), it will return a null reference exception. Does anyone have any idea why this might be happening? The same code is being used,against thesame database. The only difference is that the published website is giving back the null reference exception. If I type in the URL for the web service "https://secure.theSiteGeist.com/wsIndigo.asmx" a list of methods forthe web service is displayed in my browser. Yet if I try and call any methods on the web service I getback the null reference exception. Note that the URL I posted above is not the real name of my web service, but isjust used for reference sake.

CLR Profiler for the .NET Framework 2.0 : A bug (with possible fix!) - It throws exception - null ob

CLR Profiler for the .NET Framework 2.0   I tied to profile a service on my machine. But when I try to see the heap data (during reading of the log file) it throws exception that the object reference is not set (null object).   I debugged the CLR profiler and found that in class ReadNewLog, there is method "ReadFile" internal void ReadFile(long startFileOffset, long endFileOffset, ReadLogResult readLogResult, int requestedIndex) ...     if (matched > 0 && c != -1)     {         /* use some other stack trace as a reference */         int otherStackTraceId = ReadInt();         otherStackTraceId = stacktraceTable.MapTypeSizeStacktraceId(otherStackTraceId);         int[] stacktrace = stacktraceTable.IndexToStacktrace(otherStackTraceId);         if (matched > stacktrace.Length - hadTypeId)             matched = stacktrace.Length - hadTypeId;         for(int i = 0; i < matched; i++)         {             int funcId = stacktrace[i + hadTypeId];             Debug.Assert

error: null is not valid value for stream


Dim strm As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream("fullbuttonface.bmp")

_buttonFace = New Bitmap(strm)

May be the  bitmap file is not part of the assembly, how do I put it in the assembly


How to avoid null pointer exception when you use invoke member in c#?

Hi ,

I am working on one of the projects where I have to use the Reflection. I have a file which has values of datatype double,string, date and time as well as empty data (null). When I import the data using invoke method, it returns the null value as one of the data in the file is empty and throws "null reference exception".
value =object.GetType().InvokeMember(string, BindingFlags.GetProperty, null, object, null);
catch {
        if (value == null) {                    
           value = null;
I catch the exception and forcefully make it null than crashing my project. When I do this, the performance of the import is very slow. The data fetch is very slow as it goes like 419  times into the catch. How to avoid this the slowness of the fetch.?  try and catch will take a lot of time in fetch as I am  catching the exception and making it null. But if I do not catch it then it will crash in the middle. I need some input on this issue. Please help me out with this.... The data fetch is perfect but it has become slow due to the try and catch..  

Value of 'null' is not valid for 'stream'.


hi all,

i've got problem with load image PNG

my code :

Me.PictureBox_PngSource.Image = Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("SISOLUSI.logo.png"))

ty before

Script Component: Null value Exception



When I ran the 2008 SSIS package I am getting error at Script component (Script Component: RunTime Error  The column has NULL Value).

at Microsoft.SqlServer.Dts.Pipeline.PipelineBuffer.CheckStatusAndNull(Int32 columnIndex)

at Microsoft.SqlServer.Dts.Pipeline.PipelineBuffer.GetInt32(Int32 columnIndex)

at ScriptComponent_14ee8da369a64bce8aff81b1e175b6b0.vbproj.Input0Buffer.get_RedemptionItem()

at ScriptComponent_14ee8da369a64bce8aff81b1e175b6b0.vbproj.ScriptMain.Input0_ProcessInputRow(Input0Buffer Row)

at ScriptComponent_14ee8da369a64bce8aff81b1e175b6b0.vbproj.UserComponent.Input0_ProcessInput(Input0Buffer Buffer)

at ScriptComponent_14ee8da369a64bce8aff81b1e175b6b0.vbproj.UserComponent.ProcessInput(Int32 InputID, PipelineBuffer Buffer)

at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer)

Please Suggest the best way to handle the NULL values in Script component (like is there any setting which can allow NULL values in Script component OUTput Buffer).

Thanks in advance



How do i solve the Genuine Channel Operation Exception : cannot connect to remote host "gtcp://null:

I am trying to register my application which uses remoting. When i pass in the needed parameters i get this exception. Can anyone explain me what GTCP is ? How do i register my application with this protocol ?
Shoeb Sayyed

Null Reference Exception while trying to initialise an Integer array


Hi ,

I am getting System.NullReferenceException:Object reference not set to an instance of an object

while executing the below code..!!

Dim arr() As Integer

Dim g,j As Integer



While g > 0
                arr(j) =0
                g = g - 1
                j = j + 1
End While

Could anybody help me out..!!!

Thanks in advance


Every self-respected programmer should include exception handling techniques. Sometimes your application will generate an error. Regardless of who was responsible for this error, the programmer or the user, it is up to the first to include the necessary exception handling techniques to keep his/her program from crashing. The .Net environment provides useful techniques for avoiding disastrous errors such as try-catch statements and user-defined exceptions.

Global Exception Handling with ASP.NET

After your global exception handler has done its work, you'll want to redirect the users of your website to a friendly page that tells them that something has gone wrong, and then provide them with customer support information as well as a link back to your web application's home page.

SQL Server 2005 Try and Catch Exception Handling

I'm pretty excited to see that there is some real error handling for T-SQL code in SQL Server 2005. It's pretty painful to have your wonderfully architected .NET solution tainted by less-than-VBScript error handling for stored procedures in the database. The big difference being the addition of TRY..CATCH blocks. Let's take a look:

Save images to SQL CE

Storing binary objects (such as image, office document etc.) into database is a little cumbersome when it comes to retrieval. Hence the most commonly accepted way is only store the file path in the database, and to store the documents on a file share.

How to check for null/empty strings on dynamic objects?


What is the proper way to check for null or empty strings on dynamic objects? This is the only solution I've found so far:

if (admin.PasswordHash.GetType() == typeof(DBNull) || admin.PasswordHash == string.Empty)

If the field is null, the object returned is DBNull.Value, but if the field is empty string, it's return as a System.String object. This makes it impossible to do regular "admin.PasswordHash == DBNull.Value" check, as that will fail whenever the field has been set to empty string. Is my example the right (and only) way to go?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend