We run into an error that says: The name does not exist in the current context. How can we fix this?

When your report object and layout definitions do not match, you may run into the following error message returned by Document Creator:

A call to DocumentCreator.<MethodName> failed with this message: (<TextObjectName>): Error CS0103: The name '<DatasourceName>' does not exist in the current context.

Problem

Typically this error is raised when a column/field is referenced (e.g., in the TextObject whose name is referenced in the error message: <TextObjectName>) that is not available in the dataset of the report object. This is typically caused by either:

  1. Forgetting to update (the app that holds) the report objects, but importing a layout (package) that is already based on the new definition(s).
  2. Forgetting to update the layout after a report schema/dataset change has been applied in your Business Central environment.

Solution

Update your layout definitions to match the report object definitions/dataset. That could be, either editing the layout in the designer and resolving the errors (e.g., removing or updating the references to the fields), or updating your installed apps to have the reports match the layout definitions.