зеркало из https://github.com/mono/mail-archives.git
127 строки
4.9 KiB
HTML
127 строки
4.9 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE> [mono-android] MonoDroid: Why would this line throw a NullReferenceException?
|
|
</TITLE>
|
|
<LINK REL="Index" HREF="index.html" >
|
|
<LINK REL="made" HREF="mailto:monodroid%40lists.ximian.com?Subject=%5Bmono-android%5D%20MonoDroid%3A%20Why%20would%20this%20line%20throw%20a%0A%09NullReferenceException%3F&In-Reply-To=">
|
|
<META NAME="robots" CONTENT="index,nofollow">
|
|
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
|
|
<LINK REL="Previous" HREF="008146.html">
|
|
<LINK REL="Next" HREF="008154.html">
|
|
</HEAD>
|
|
<BODY BGCOLOR="#ffffff">
|
|
<H1>[mono-android] MonoDroid: Why would this line throw a NullReferenceException?</H1>
|
|
<B>grauenwolf</B>
|
|
<A HREF="mailto:monodroid%40lists.ximian.com?Subject=%5Bmono-android%5D%20MonoDroid%3A%20Why%20would%20this%20line%20throw%20a%0A%09NullReferenceException%3F&In-Reply-To="
|
|
TITLE="[mono-android] MonoDroid: Why would this line throw a NullReferenceException?">grauenwolf at gmail.com
|
|
</A><BR>
|
|
<I>Fri Dec 30 16:27:20 EST 2011</I>
|
|
<P><UL>
|
|
<LI>Previous message: <A HREF="008146.html">[mono-android] Inflate does not display what is expected
|
|
</A></li>
|
|
<LI>Next message: <A HREF="008154.html">[mono-android] RedLaser bindings for MonoDroid
|
|
</A></li>
|
|
<LI> <B>Messages sorted by:</B>
|
|
<a href="date.html#8151">[ date ]</a>
|
|
<a href="thread.html#8151">[ thread ]</a>
|
|
<a href="subject.html#8151">[ subject ]</a>
|
|
<a href="author.html#8151">[ author ]</a>
|
|
</LI>
|
|
</UL>
|
|
<HR>
|
|
<!--beginarticle-->
|
|
<PRE>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:
|
|
|
|
<A HREF="http://toonrpg.codeplex.com/SourceControl/list/changesets">http://toonrpg.codeplex.com/SourceControl/list/changesets</A>
|
|
<A HREF="http://granite.codeplex.com/SourceControl/list/changesets">http://granite.codeplex.com/SourceControl/list/changesets</A>
|
|
|
|
|
|
--
|
|
View this message in context: <A HREF="http://mono-for-android.1047100.n5.nabble.com/MonoDroid-Why-would-this-line-throw-a-NullReferenceException-tp5111089p5111089.html">http://mono-for-android.1047100.n5.nabble.com/MonoDroid-Why-would-this-line-throw-a-NullReferenceException-tp5111089p5111089.html</A>
|
|
Sent from the Mono for Android mailing list archive at Nabble.com.
|
|
</PRE>
|
|
|
|
|
|
|
|
|
|
|
|
<!--endarticle-->
|
|
<HR>
|
|
<P><UL>
|
|
<!--threads-->
|
|
<LI>Previous message: <A HREF="008146.html">[mono-android] Inflate does not display what is expected
|
|
</A></li>
|
|
<LI>Next message: <A HREF="008154.html">[mono-android] RedLaser bindings for MonoDroid
|
|
</A></li>
|
|
<LI> <B>Messages sorted by:</B>
|
|
<a href="date.html#8151">[ date ]</a>
|
|
<a href="thread.html#8151">[ thread ]</a>
|
|
<a href="subject.html#8151">[ subject ]</a>
|
|
<a href="author.html#8151">[ author ]</a>
|
|
</LI>
|
|
</UL>
|
|
|
|
<hr>
|
|
<a href="http://lists.ximian.com/mailman/listinfo/monodroid">More information about the Monodroid
|
|
mailing list</a><br>
|
|
</body></html>
|