【发布时间】:2009-07-13 21:14:56
【问题描述】:
我已经定义了:
[RdfSerializable]
public class SomeItem
{
// Unique identificator of the resource
[ResourceUri]
public string ID { get; set; }
[RdfProperty( true )]
public string SomeData { get; set; }
}
and in some other class:
[RdfProperty(true)]
public SomeItem[] MyTestProp
{
get
{
return new SomeItem[] { new SomeItem() { ID="1", SomeData="test1" }, new SomeItem() { ID="2", SomeData = "test2" } };
}
}
当我尝试序列化包含此自定义“MyTestProp”的类时,它给了我这条消息:
对象引用未设置为 对象的实例。
描述:未处理的异常 在执行过程中发生 当前的网络请求。请查看 堆栈跟踪以获取有关的更多信息 错误及其起源 编码。
异常详情: System.NullReferenceException:对象 引用未设置为 对象。
我在定义这些属性时是错误的,还是有一种特殊的方法可以将数组定义为自定义类?请注意,例如将数组序列化为字符串并不会让我崩溃,但它正在工作。
全部来源:
using System;
using NC3A.SI.Rowlex;
[assembly: Ontology("ROWLEXtest1", "http://www.test.com/MyOntology")]
namespace ROWLEXtest1
{
[RdfSerializable( HasResourceUri=false )]
public class Item
{
[RdfProperty(true)]
public string MyProp;
}
[RdfSerializable]
public class AllItems
{
[RdfProperty(true)] public string mTitle;
private int id = new Random().Next(0, 20);
[ResourceUri]
public string ResourceUri
{
get { return "This " + id.ToString(); }
}
[RdfProperty(false)]
public Item[] Items;
}
class Program
{
static void Main(string[] args)
{
var item = new AllItems();
item.mTitle = "Hello World!";
item.Items = new Item[] { new Item(){ MyProp = "test1" }, new Item(){ MyProp = "test2" } };
var doc = Rdfizer.Serialize(item);
System.Console.Out.Write(doc.ToString());
}
}
}
例外是:
System.NullReferenceException 是 未处理的 Message="对象引用 未设置为对象的实例。” 来源="NC3A.SI.Rowlex" 堆栈跟踪: 在 NC3A.SI.Rowlex.RdfPropertyAttribute.ExtractRange(成员信息 memberInfo, Int32& minCardinality, Int32& 最大基数) 在 NC3A.SI.Rowlex.RdfPropertyAttribute.ExtractRange(成员信息 会员信息) 在 NC3A.SI.Rowlex.Rdfizer.AppendProperty(RdfDocument doc, MemberInfo memberInfo, RdfPropertyAttribute 属性,对象 项目,字符串 resourceUri) 在 NC3A.SI.Rowlex.Rdfizer.AppendSingleRdfSerializableObject(RdfDocument 文档,对象项目) 在 NC3A.SI.Rowlex.Rdfizer.ProcessItem(RdfDocument 文档,对象项,字符串 [] rangeTypeUris) 在 NC3A.SI.Rowlex.Rdfizer.ExecuteSerialization(IEnumerable 对象) 在 NC3A.SI.Rowlex.Rdfizer.Serialize(IEnumerable 对象,布尔值 容忍UnserializebleObjects) 在 NC3A.SI.Rowlex.Rdfizer.Serialize(对象 物品) 在 ROWLEXtest1.Program.Main(String[] 参数)在 C:\ROWLEXtest1\ROWLEXtest1\Program.cs:行 40 在 System.AppDomain._nExecuteAssembly(程序集 程序集,字符串 [] 参数) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ExecutionContext.Run(ExecutionContext 执行上下文,上下文回调 回调,对象状态) 在 System.Threading.ThreadHelper.ThreadStart() 内部异常:
【问题讨论】:
-
我已经添加了完整的源代码和异常信息。我希望这能帮助您检查问题。