I can't figure out why this line is throwing a null reference exception under
Mono for Android. The same code works fine for WPF, Silverlight, and Windows
Phone.

        public PossessionCollection Possessions
        {
            get { return GetNew<PossessionCollection>("Possessions"); }
<------
        }


The stack trace is showing an error before it gets into the GetNew function.
But for sake of completeness, here it is:

        protected T GetNew<T>([CallerMemberNameAttribute] string propertyName)
where T : new()
        {
                if (propertyName == null)
                        throw new ArgumentNullException("propertyName", 
"propertyName is null.");
                if (string.IsNullOrEmpty(propertyName))
                        throw new ArgumentException("propertyName is empty.", 
"propertyName");
                Contract.EndContractBlock();

                return Properties.GetNew<T>(propertyName);
        }


        public T GetNew<T>([CallerMemberName] string propertyName)
                        where T : new()
        {
            if (propertyName == null)
                throw new ArgumentNullException("propertyName",
"propertyName is null");
            if (String.IsNullOrEmpty(propertyName))
                throw new ArgumentException("propertyName is empty",
"propertyName");
            Contract.EndContractBlock();

            var result = GetValue(propertyName);
            if (result == Missing.Value)
            {
                result = Activator.CreateInstance<T>();
                Set(result, PropertySetModes.SetAsOriginal, propertyName);
            }
            try
            {
                return (T)result;
            }
            catch (NullReferenceException ex)
            {
                //This can occur if T is a non-nullable value type and the
parent class is mal-formed.
                throw new InvalidOperationException("Property " +
propertyName + " contains a null", ex);
            }
        }


 Full source code: 

http://toonrpg.codeplex.com/SourceControl/list/changesets
http://granite.codeplex.com/SourceControl/list/changesets


--
View this message in context: 
http://mono-for-android.1047100.n5.nabble.com/MonoDroid-Why-would-this-line-throw-a-NullReferenceException-tp5111089p5111089.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to