Skip to Content
0
Former Member
Jun 16, 2009 at 10:48 AM

Add comments result in 'Buffer too small for string or missing null byte'

208 Views

When I fill the SummaryInfo.ReportComments property of the ReportDocument object with a string, an COMException occurs: 'Buffer too small for string or missing null byte'.

This is the C#.net code:

private CrystalDecisions.CrystalReports.Engine.ReportDocument _ReportDoc;
...
_ReportDoc = new ReportDocument();
_ReportDoc.Load(reportFileName);
...
var reportInfo = new ReportInfo();
reportInfo.Id = 1000
... (etc).

var infoXml = string.Empty;
var xmlSer = new XmlSerializer(typeof(ReportInfo));
var writer = new StringWriter(CultureInfo.InvariantCulture);
xmlSer.Serialize(writer, reportInfo);
infoXml = writer.ToString();
 // COMException on following line.
writer.Close();ReportDoc.SummaryInfo.ReportComments = infoXml;

Variable infoXml (of type string) looks something like this:

<?xml version="1.0" encoding="utf-16"?>
<ReportInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Id>10000</Id>
  <ProdigyKey>a1c4c3f8-702a-403d-bce0-0687b86bf2ce</ProdigyKey>
  <TemplateCategoryId>0</TemplateCategoryId>
  <Name>b</Name>
  <Number>1</Number>
  <Description>b</Description>
  <IsDashboardItem>false</IsDashboardItem>
  <Entities>
    <long>1</long>
    <long>2</long>
  </Entities>
</ReportInfo>

ReportInfo class:

   [Serializable()]
   public class ReportInfo
   {
      public long Id { get; set; }
      public Guid ProdigyKey { get; set; }
      public long TemplateCategoryId { get; set; }
      public string Name { get; set; }
      public long Number { get; set; }
      public string Description { get; set; }
      public bool IsDashboardItem { get; set; }
      public Collection<long> Entities {
         get {
            if (_Entities == null) {
               _Entities = new Collection<long>();
            }
            return _Entities;
         }
      }
      private Collection<long> _Entities;
   {

I do not think the message is to big because when I paste the result string directly in a report summary using Crystal Reports, it 'fits'.