cancel
Showing results for 
Search instead for 
Did you mean: 

Object Reference not set to an instance of an object

Anonymous
Not applicable
The code stage has no errors compiled, while running it fires this error ==>Object Reference not set to an instance of an object

Why is not saying which is the error??

------------------------------
Cohen
RPA Developer

Romania
------------------------------
1 BEST ANSWER

Helpful Answers

evanchirger1
Level 2

An Object is an instance of a Class , it is stored some where in memory. A reference is what is used to describe the pointer to the memory location where the Object resides. The message "object reference not set to an instance of an object" means that you are referring to an object the does not exist or was deleted or cleaned up. It's usually better to avoid a NullReferenceException than to handle it after it occurs. To prevent the error, objects that could be null should be tested for null before being used.

if (mClass != null)
{
// Go ahead and use mClass
mClass.property = ...
}
else
{
// Attempting to use mClass here will result in NullReferenceException
}



------------------------------
evan chirger
------------------------------

View answer in original post

7 REPLIES 7

VivekGoel
Level 10
Object Reference related errors are run time errors not compiler errors. These errors normally come when you try to refer to a data item/variable which is null (Null Reference exception)  or else if you are trying to refer to a variable which is not yet initialized.  .

Can you please post your code so that we can guide you further?

------------------------------
Vivek Goel
RPA Architect
Asia/Singapore
+6594554364
https://www.rpatools.com/
"If you like this post, please press the "Recommend" Button.
------------------------------

Hi Vivek,

Could you guide me through my code related to the same issue:

Page page = System.Web.HttpContext.Current.Handler as Page;
str = "page doesn't exist";
if (page != null)
{ str = "page exists!!";
}
There is the same runtime exception - object reference not set. I have the dll and reference mentioned in the Init page though.

Along with the above if you could additionally help me with the below:
I am trying to run this code through code stage in BP to call a java script function "JSFUNCTION" - the JS function already exists in the webpage.
System.Web.UI.Page page = new System.Web.UI.Page();
ClientScriptManager cs = page.ClientScript;
cs.RegisterStartupScript(page.GetType(), "Javascript", "JSFUNCTION(false,this);", true);

The run is successful but nothing happens on the page, the function works when called from Console (dev tool in browser).

------------------------------
Rohan Shankar
Analyst
Ericsson
Asia/Kolkata
------------------------------

evanchirger1
Level 2

An Object is an instance of a Class , it is stored some where in memory. A reference is what is used to describe the pointer to the memory location where the Object resides. The message "object reference not set to an instance of an object" means that you are referring to an object the does not exist or was deleted or cleaned up. It's usually better to avoid a NullReferenceException than to handle it after it occurs. To prevent the error, objects that could be null should be tested for null before being used.

if (mClass != null)
{
// Go ahead and use mClass
mClass.property = ...
}
else
{
// Attempting to use mClass here will result in NullReferenceException
}



------------------------------
evan chirger
------------------------------

Hi,
I had similar issue. And problem appeared because bot user used to login to Windows, had temp windows profile.
Once I used other user at this VDI with normal profile, and also return bot user to use normal profile, issue disappeared. 
Best Regards
Piotr Wieczerzak

------------------------------
Piotr Wieczerzak
Senior developer and analyst
Brown Brothers Harriman
Europe/Warsaw
------------------------------

Hi Piotr - I am currently seeing this issue now on our bots. We use HTTP request to retrieve credentials from CyberArk and then send those credentials to Login Agent. I have suddenly started seeing this 'object reference not set to an instance..' error. Can you elaborate a bit more on what caused this issue on your end and how it got resolved?

What do you mean when you said bot user had temp profile and when you say return bot user to normal profile.

Thanks so much!



------------------------------
Maneesh Vemula
------------------------------

Hi Maneesh, 

temp profile means that during each login to Windows using this same user bot is creating new profile - something like bot1 during first login, then bot01.temp01, next bot01.temp02 etc... each login new profile. 

When I was able to login VDI using permanent profile issue disappeared. 

Best regards

Piotr



------------------------------
Piotr Wieczerzak
Senior developer and analyst
Brown Brothers Harriman
Europe/Warsaw
------------------------------

luismartinez888
Level 4

Let me share my solution in case it helps anyone in the future. I was receiving same error for microsoft graph sharepoint api object. What I did to get a more relevant error was find what function the code stage was calling. Then i went to Initialize page, found the function under global code. I removed the try/catch block so that the relevant error can actually come through instead of this reference not set error. This helped me narrow down my issue which turned out to be a timeout problem. I increased timeout and problem resolved.