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

Empty content exception #55

Open
zii-dmg opened this issue Jul 25, 2018 · 0 comments
Open

Empty content exception #55

zii-dmg opened this issue Jul 25, 2018 · 0 comments

Comments

@zii-dmg
Copy link

zii-dmg commented Jul 25, 2018

When generating empty content (for example, RepeatContent) library throws. Some lists can be empty in generated document so I think library should not throw but generate as hidden.

Stack:

Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: source
   at System.Linq.Enumerable.SelectMany[TSource,TResult](IEnumerable`1 source, Func`2 selector)
   at TemplateEngine.Docx.Container.<>c.<get_FieldNames>b__26_1(RepeatContent t)
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.<DistinctIterator>d__64`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at TemplateEngine.Docx.TableContent.get_FieldNames()
   at TemplateEngine.Docx.Processors.TableProcessor.FillContent(XContainer contentControl, IContentI
tem item)
   at TemplateEngine.Docx.Processors.TableProcessor.FillContent(XElement contentControl, IEnumerable
`1 items)
   at TemplateEngine.Docx.Processors.ContentProcessor.FillContent(XElement content, IEnumerable`1 da
ta)
   at TemplateEngine.Docx.TemplateProcessor.FillContent(Content content)
   at HiddenRepeatRepro.Program.Main(String[] args) in D:\Work\HiddenRepeatRepro\Program.cs:line 49

Template: EmptyContentTemplate.docx

Repro:

using System;
using System.IO;
using TemplateEngine.Docx;

namespace EmptyContentRepro
{
	static class Program
	{
		static void Main(string[] args)
		{
			string templateFile = "EmptyContentTemplate.docx";
			string outputFile = "EmptyContentRepro.docx";

			File.Delete(outputFile);
			File.Copy(templateFile, outputFile);

			var repeat = new RepeatContent("repeat1"); // empty
			var table = new TableContent("table1").AddRow(repeat);
			var content = new Content(table);

			using (var template = new TemplateProcessor(outputFile).SetRemoveContentControls(true))
			{
				template.FillContent(content);
				template.SaveChanges();
			}
		}
	}
}
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

1 participant