I eventually found it Nic. Was a problem of refactoring code into a base class 
and inheriting from it.

class A
{
    private CreditCard creditCard;

    protected void Function()
    {
        string name = this.creditCard.FirstName;
    }
}

class B : A
{
    private CreditCard creditCard;

    private void SomeMethod()
    {
        this.creditCard = new CreditCard();    
        this.Function();
    }
}

If you break in "Function" with the above code, MonoDevelop reports that 
"this.creditCard" is a valid object via the hover tips etc, but in reality it's 
null. That's what got me.

In refactoring my code, I had not noticed the member variable in class B of the 
same name.

Dino

-----Original Message-----
From: Nic Wise [mailto:[email protected]] 
Sent: Thursday, August 30, 2012 09:00
To: Dean Cleaver
Cc: [email protected]
Subject: Re: [MonoTouch] Weird NullReference problem

What happens if you do

postValues.Add("x_zip", this.zip);
postValues.Add("x_first_name", this.creditCard.FirstName);

?

On Thu, Aug 30, 2012 at 2:28 PM, Dean Cleaver 
<[email protected]> wrote:
> I'm stumped. The second line of code is failing with a null reference 
> exception...
>
> postValues["x_zip"] = this.zip;
> postValues["x_first_name"] = "" + this.creditCard.FirstName;
>
> "this.creditCard" is valid. "this.creditCard.FirstName" is "DA". But 
> that line returns a null reference exception.
>
> How?
>
> postValues cannot be null or the previous line would have failed. It 
> is a hashtable, so it allows setting of values in this manner.
>
>
>
> Any ideas what could be causing a null reference exception?
>
>
>
> Dino
>
>
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
>



--
Nic Wise
t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
Earnest: Self-employed? Track your business expenses and income.
http://earnestapp.com
Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p 
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to