Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
object refrence not set what is the issue in else staetment getting issue


What I have tried:

<pre>                if (Request.Cookies["aa"] == null)
                {
                    Response.Cookies["aa"].Value = product_name.ToString() + "," + product_desc.ToString() + "," + product_price.ToString() + "," + product_qty.ToString() + "," + product_images.ToString() + "," + data_id.ToString();
                    Response.Cookies["aa"].Expires = DateTime.Now.AddDays(1);

                }
                else
                {
                    Response.Cookies["aa"].Value = Request.Cookies["aa"].Value.ToString() + "|" + product_id.ToString() + "," + product_name.ToString() + "," + product_desc.ToString() + "," + product_price.ToString() + "," + product_qty.ToString() + "," + product_images.ToString() + "," + data_id.ToString();
                    Response.Cookies["aa"].Expires = DateTime.Now.AddDays(1);

                }
Posted
Updated 10-Dec-17 5:08am
Comments
Mehdi Gholam 10-Dec-17 5:42am    
Debug your code and see which object is null.
Waqaskhan121 11-Dec-17 0:41am    
Thanks a lot finally solved it by debuggig

1 solution

Quote:
object refrence not set what is the issue in else staetment getting issue

This is not a problem in source code, this a problem at runtime, and we can't do anything for you.
Your only solution is using the debugger and inspect variables/objects at point of failure.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]
Debugging C# Code in Visual Studio - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900