'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.GlobalizationImportsGrapeCity.Documents.Word '' This example shows how to deal with the 'data source with this name already exists' error.PublicClassDataTplFixNoDataSources'' Code demonstrating the problem:PrivateFunctionProblem() AsGcWordDocumentUsing oceans = File.OpenRead(Path.Combine("Resources", "data", "oceans.json"))Dim doc = NewGcWordDocument() doc.Body.Paragraphs.Add("{{ds.name}}")'' Incorrect: no data sources have been added when the DataTemplate.Process() method is called: doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"))Return docEndUsingEndFunction '' Code demonstrating the fix:PrivateFunctionFix() AsGcWordDocumentUsing oceans = File.OpenRead(Path.Combine("Resources", "data", "oceans.json"))Dim doc = NewGcWordDocument() doc.Body.Paragraphs.Add("{{ds.name}}") doc.DataTemplate.DataSources.Add("ds", oceans)'' Correct: the data source have been added prior to calling the DataTemplate.Process() method: doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"))Return docEndUsingEndFunction FunctionCreateDocx() AsGcWordDocumentDim doc AsGcWordDocumentTry'' This fails: doc = Problem()Catch ex As Exception'' This works: doc = Fix()'' Insert a brief explanation of the problem and the fix into the generated document: doc.Body.Paragraphs.Insert($"The error ""{ex.Message}"" occurred because the DataTemplate.Process() method was called before adding the data source. " +$"The fix is to add the data sources prior to calling the DataTemplate.Process() method.", doc.Styles(BuiltInStyleId.BlockText),InsertLocation.Start)EndTryReturn docEndFunctionEndClass