Random NullReferenceException when accessing an adapter.

Ask general questions here.
johnsmith
Posts: 18
Joined: Sun Mar 18, 2012 1:13 am

Random NullReferenceException when accessing an adapter.

Post by johnsmith » Sun Mar 18, 2012 12:28 pm

Hi,

I have an ATag adapter that's stored in the repository. The problem occurs only for this particular adapter (I have a bunch of others). I'm using Internet Explorer 9.0.
Here's how the adapter is created in the code:

Code: Select all

var troublesomeAdapter = repo.myDiv.troublesomeAdapter;
troublesomeAdapter.PressKeys("newvalue", 100);     //This line throws an exception
The exception I'm getting is "NullReferenceException: Object reference not set to an instance of an object"

If I try to highlight the adapter from the repository, it's being highlighted correctly on the webpage. So I guess there's no problem with the ranorexpath.

I suppose that NullReferenceException means that (troublesomeAdapter == null).

I tried to test whether troublesomeAdapter is null or not in the following way, however the message isn't being logged.

Code: Select all

if (troublesomeAdapter == null) Report.Failure("troublesomeAdapter is null");

It's really strange that the exception is not being thrown every time I run my testsuite. It's appearing in 50-70% of the cases.

What's the reason and how can it be fixed?

Thanks!

johnsmith
Posts: 18
Joined: Sun Mar 18, 2012 1:13 am

Re: Random NullReferenceException when accessing an adapter.

Post by johnsmith » Mon Mar 19, 2012 1:11 pm

I solved the issue, it was a problem on my side - I was accessing a null property.