Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submit of report with CustomInfo fails #69

Open
Eiszapfen opened this issue Apr 8, 2016 · 5 comments
Open

Submit of report with CustomInfo fails #69

Eiszapfen opened this issue Apr 8, 2016 · 5 comments

Comments

@Eiszapfen
Copy link

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
Copy link
Owner

soygul commented Apr 8, 2016

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
Copy link
Author

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
Copy link
Owner

soygul commented Apr 8, 2016

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
Copy link

biship commented Dec 31, 2016

@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
Copy link
Owner

soygul commented Dec 31, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants