2009-07-13 3 views
2

나는 정의 :

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

오전 : 나는이 사용자 정의 "MyTestProp"를 포함하는 클래스를 직렬화 할 때

[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" } }; 
    } 
} 

가 나에게 그 메시지를 준 그 속성을 정의하는 것이 잘못되었거나 배열을 사용자 정의 클래스로 정의하는 특별한 방법이 있습니까? 배열을 예를 들어 string에 직렬화하는 것은 그런 식으로 충돌을 일으키지 않지만 작동하는 것에 유의하십시오.

전체 소스 :

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 was unhandled Message="Object reference not set to an instance of an object." Source="NC3A.SI.Rowlex" StackTrace: at NC3A.SI.Rowlex.RdfPropertyAttribute.ExtractRange(MemberInfo memberInfo, Int32& minCardinality, Int32& maxCardinality) at NC3A.SI.Rowlex.RdfPropertyAttribute.ExtractRange(MemberInfo memberInfo) at NC3A.SI.Rowlex.Rdfizer.AppendProperty(RdfDocument doc, MemberInfo memberInfo, RdfPropertyAttribute attribute, Object item, String resourceUri) at NC3A.SI.Rowlex.Rdfizer.AppendSingleRdfSerializableObject(RdfDocument doc, Object item) at NC3A.SI.Rowlex.Rdfizer.ProcessItem(RdfDocument doc, Object item, String[] rangeTypeUris) at NC3A.SI.Rowlex.Rdfizer.ExecuteSerialization(IEnumerable objects) at NC3A.SI.Rowlex.Rdfizer.Serialize(IEnumerable objects, Boolean tolerateUnserializebleObjects) at NC3A.SI.Rowlex.Rdfizer.Serialize(Object item) at ROWLEXtest1.Program.Main(String[] args) in C:\ROWLEXtest1\ROWLEXtest1\Program.cs:line 40 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

+0

나는 전체 소스와 예외 정보를 추가했습니다. 문제를 조사하는 데 도움이되기를 바랍니다. –

답변

2

확인을 보이지만 하나의 오류가 : MyTestProp가 아니므로 RdfProperty 선언 MyTestProp은 "false"를해야 데이터 형식 속성이지만 개체 속성 (개체 및 리터럴을 반환하지 않음).

그러나 이것이 문제의 근원인지 확신 할 수 없습니다. 그리고 그것이 맞다하더라도, 당신은 a decent error message with meaningful text instead of silly NullReferenceException을 얻어야합니다. 따라서 가능한 경우 오류를 재현하고 수정 사항을 제공하려고합니다. 당신은 구체적으로 기재 할 수

  • 클래스와 MyTestProp를 호스팅의 장식,
  • 해당 클래스를 인스턴스화 코드 및
  • 당신이 직렬화에 사용하는 코드.
  • 어셈블리 레벨 속성을 적용했다면 (온톨로지 - 네임 스페이스 매핑을 위해),이를 명시 해주십시오.

[admin at rowlex.net]에 코드 샘플을 보내주십시오.

편집 : 예외를 재현 할 수 있습니다. ROWLEX의 버그입니다. 이제 고정 2.0.1 버전을 ROWLEX 사이트에서 다운로드 할 수 있습니다.

+0

고마워! 나는 그것을 시험 할 것이다. –