문제

나는 정의했다 :

[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은 처리되지 않은 메시지 = "개체 참조는 객체의 인스턴스로 설정되지 않습니다." source = "nc3a.si.rowlex"stacktrace : at nc3a.si.rowlex.rdfpropertyattribute.extractrange (memberinfo memberinfo, int32 & mincardinality, int32 & maxcardinality) at nc3a.si.rowlex.rdfproperttript.extrange. rowlex.rdfizer.appendProperty (rdfdocument doc, memberinfo memberinfo, rdfpropertyattribute 속성, 객체 항목, 문자열 resourceuri) nc3a.si.rowlex.rdfizer.appendsinglerdfserializableObject (rdfdocument item) nc3a.sofic.srowfizer. doc, 객체 항목, String [] rangetypeuris)에서 nc3a.si.rowlex.rdfizer.executeserialization (ienumerable objects)에서 nc3a.si.rowlex.rdfizer.serialize (ienumerable objects, boolean tolerate tolecable 객체, boolean tolecable 객체)에서 nc3a.si.rowlex. c : rowlextest1 rowlextest1 rowlextest1 program.cs : system.appdomain._nexecuteaseMbly (어셈블리 어셈블리, String [] args)에서 c : rowlextest1 rowlextest1 program.cs : rowlextest1.program.main (string [] args)에서 Serialize (객체 항목)를 Serialize (개체 항목). .hostingprocess.hostproc.runusersassem system.threading.executioncontext.run의 bly () () system.threading.threadhelper.threadStart () innerexception에서 system.threading.threadHelper.ThreadHelper ()의 executionContext executionContext, ContextCallback Callback, Object State)의 bly () : innerexception :

도움이 되었습니까?

해결책

MyTestProp이 데이터 유형 속성이 아니라 객체 속성 (리터럴이 아닌 개체를 반환)이므로 MyTestProp에 대해 RDFPROPERTY 선언이 "False"를 취해야합니다.

그러나 이것이 당신의 문제의 근본인지 확실하지 않습니다. 그리고 그것이 있더라도, 당신은 얻어야합니다 어리석은 nullReferenceException 대신 의미있는 텍스트가있는 괜찮은 오류 메시지. 따라서 오류를 재현하고 해당되는 경우 수정 사항을 제공하려고합니다. 제발, 지정해 주시겠습니까?

  • MyTestProp을 주최하는 수업과 장식,
  • 해당 클래스를 인스턴스화하는 코드
  • 직렬화에 사용하는 코드.
  • 어셈블리 레벨 속성 (온톨로지 - 네임 스페이스 매핑)을 적용한 경우에도 표시하십시오.

코드 샘플을 [rowlex.net]에게 보내는 것을 고려할 수 있습니다.

편집 : 예외를 재현 할 수 있습니다. Rowlex의 버그입니다. 고정 2.0.1 버전은 이제로 다운로드 할 수 있습니다 Rowlex 대지.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top