NBug icon indicating copy to clipboard operation
NBug copied to clipboard

Submit of report with CustomInfo fails

Open Eiszapfen opened this issue 8 years ago • 5 comments

Hi!

When creating a bug report with CustomInfo object set, NBug throws an exception when trying to submit this report. This problem was mentioned earlier here on StackOverflow.

In Report.cs the report class gets serialized in the ToString Methodwith this code: var serializer = this.CustomInfo != null ? new XmlSerializer(typeof(Report), new[] { this.CustomInfo.GetType() }) : new XmlSerializer(typeof(Report)); so if setting CustomInfo != null the XmlSerializer constructor with the "extraTypes" parameter gets called. See MSDN.

After restarting the application, NBug tries to submit the bug report, this leads to Dispatcher.cs method GetDataFromZip(Stream stream) the deserialization of the report file happens always with the following call: var deserializer = new XmlSerializer(typeof(Report));

Unfortunately this leads to a wrongly deserialized Xml so the CustomInfo member of the Report class gets deserialized to a XmlNode[] which in turn cannot be correctly serialized later when submitting the bugreport.

Kind regards, Andy

Eiszapfen avatar Apr 08 '16 10:04 Eiszapfen

Actually this:

var serializer = this.CustomInfo != null
? new XmlSerializer(typeof(Report), new[] { this.CustomInfo.GetType() })
: new XmlSerializer(typeof(Report));

can just be this:

var serializer = new XmlSerializer(typeof(Report), new[] { this.CustomInfo.GetType() });

since specifying extra type does not break the serialization/deserialization when that type does not appear in the data.

I don't have a Windows env. to test this idea but if you can, make a PR and I'll merge it.

Thanks for the report also.

soygul avatar Apr 08 '16 10:04 soygul

Yes, you are right but the problem here is: CustomInfo is of type object and I add an instance of type "MyCustomInfo". So when deserializing I need to specify typeof(MyCustomInfo) to deserialize correctly. Up to now I don't have a good idea how to "pass in" a custom type to the library. I will think about it during the weekend... thanks for the quick reply!

Eiszapfen avatar Apr 08 '16 11:04 Eiszapfen

Yeah, specifying only the base type CustomInfo as the extra type for deserializer might not be enough. Never needed the custom info myself so never looked for a solution.

Anyway, good luck. Stackoverflow might have some ideas on this.

soygul avatar Apr 08 '16 11:04 soygul

@soygul - I get this error with your change:

NBugTrace: 12:24:49  : Submitting bug report via Mantis.
NBugError: 12:24:49  : An exception occurred while submitting bug report with Mantis. Check the inner exception for details.
Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at NBug.Core.Reporting.Info.Report.ToString() in D:\Code\Other\NBug-master\NBug\Core\Reporting\Info\Report.cs:line 52
   at NBug.Core.Submission.Tracker.Mantis.Mantis.Send(String fileName, Stream file, Report report, SerializableException exception) in D:\Code\Other\NBug-master\NBug\Core\Submission\Tracker\Mantis\Mantis.cs:line 177
   at NBug.Core.Submission.Dispatcher.EnumerateDestinations(Stream reportFile, ExceptionData exceptionData) in D:\Code\Other\NBug-master\NBug\Core\Submission\Dispatcher.cs:line 133

Report.cs:line 52 is:

var serializer = new XmlSerializer(typeof(Report), new[] { CustomInfo.GetType() });

biship avatar Dec 31 '16 19:12 biship

Known issue. Don't use custom info until someone fixes it. I don't use Windows any more so can't work on it.

soygul avatar Dec 31 '16 20:12 soygul