STARIONGROUP / reqifsharp

A C# library for reading and writing reqif documents
https://reqifsharp.org
Apache License 2.0
24 stars 14 forks source link

System.NullReferenceException on Deserialization of sample files. #52

Closed cimba007 closed 11 months ago

cimba007 commented 11 months ago

Prerequisites

Description

When trying to deserialize a sample file I got an NullReferenceExeption. The file I used is from google "reqif example files". https://eclipse.googlesource.com/rmf/org.eclipse.rmf/+/44228c91a7b51612cf392a3e508334cac9c8e602/org.eclipse.rmf.reqif10.model.test/testdata/sample.reqif

Steps to Reproduce

public class ReqifTest
    {

        public ReqifTest()
        {
            Deserialize();
        }

        public void Deserialize()
        {
            var path = @"C:\Users\xxx\Downloads\Sample2.reqif";
            ILoggerFactory factory = LoggerFactory.Create(builder => builder.AddDebug().SetMinimumLevel(LogLevel.Trace));
            ReqIFDeserializer deserializer = new ReqIFDeserializer(factory);

            var reqif = deserializer.Deserialize(path);
            var first = reqif.First();
            var header = first.TheHeader;
            var content = first.CoreContent;

            Debug.WriteLine("Halt");
        }
    }

While executing the Deserialize-Method throws an exception.

Logging from stacktrace

   at System.Xml.Schema.XsdDateTime.Parser.Parse(String text, XsdDateTimeFlags kinds)
   at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)
   at System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption)
   at ReqIFSharp.Identifiable.ReadXml(XmlReader reader)
   at ReqIFSharp.DatatypeDefinitionString.ReadXml(XmlReader reader)
   at ReqIFSharp.ReqIFContent.DeserializeDataTypes(XmlReader reader)
   at ReqIFSharp.ReqIFContent.ReadXml(XmlReader reader)
   at ReqIFSharp.ReqIF.ReadXml(XmlReader reader)
   at ReqIFSharp.ReqIFDeserializer.DeserializeReqIF(Stream stream, SupportedFileExtensionKind fileExtensionKind, Boolean validate, ValidationEventHandler validationEventHandler)
   at ReqIFSharp.ReqIFDeserializer.Deserialize(String fileUri, Boolean validate, ValidationEventHandler validationEventHandler)
   at ReqifSharpExample.ReqifTest.Deserialize() in C:\Users\xxx\source\repos\ReqifSharpExample\ReqifSharpExample\Program.cs:line 35

Logging from Debug-Output

ReqIFSharp.ReqIFDeserializer: Trace: start deserializing from C:\Users\xxx\Downloads\Sample2.reqif
ReqIFSharp.ReqIFDeserializer: Trace: reading from reqif
ReqIFSharp.ReqIFDeserializer: Trace: starting to read xml
ReqIFSharp.Identifiable: Trace: read xml of DatatypeDefinitionString:3631dcd2-59d1-11da-beb2-6fbc179f63e3
Ausnahme ausgelöst: "System.NullReferenceException" in System.Xml.dll
Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

System Configuration

If this is not a bug I am very sorry for bothering you. I was successfull with another example file but as the sample file is pretty small I am not sure what should be wrong with it.

If you could point me in a direction where I could find other (known working an validated) sample files I would gladly try them. Thank you for making this library available!

Best regards

samatstariongroup commented 11 months ago

I will have a look at this tmrw

cimba007 commented 11 months ago

I think the main problem with this sample files is, that it does comply with the reqif.xsd. So that means that reqifsharp can only work with files that are compliant. No big deal as the documents that I will later work with in production envioronment should be compliant.

samatstariongroup commented 11 months ago

@cimba007 indeed, this particular reqif file is not compliant to the versions of ReqIF that reqifsharp supports. May i close this issue?

The test project contains a number of sample files that do work, please have a look at https://github.com/RHEAGROUP/reqifsharp/blob/8fa1ffdaca1d69de55aa1467680cba53bbb1f4a2/ReqIFSharp.Tests/ReqIFDeSerializerTestFixture.cs

cimba007 commented 11 months ago

Yeah. Thank you very much. This might still help other newbies in the future :-)