soygul / NBug

Automated bug reporting library for .NET
http://soygul.com/nbug
MIT License
191 stars 78 forks source link

Submit of report with CustomInfo fails #69

Open Eiszapfen opened 8 years ago

Eiszapfen commented 8 years ago

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

soygul commented 8 years ago

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.

Eiszapfen commented 8 years ago

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!

soygul commented 8 years ago

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.

biship commented 7 years ago

@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() });

soygul commented 7 years ago

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