Accessing the Error List window of Visual Studio

This chapter describes how to get access to the Visual Studio Error List window. Because TwinCAT 3 integrates itself into the Visual Studio shell, reading the content of this window can be essential for debugging and diagnostic purposes. To read the content of this window, you need to access the Visual Studio COM interface. Because this COM interface is also needed to access TwinCAT XAE (e.g. as described in our article Accessing TwinCAT configuration), you don't need to add any additional references to your program code.

The following documentation describes how to access the Error List window, which can be very helpful, for example if you want to compile a PLC project and want to check the compile process for any error messages. The Error List window displays status messages for various features in the Visual Studio (and therefore TwinCAT) development environment. These features for example include build errors that occur when a project is compiled or licensing issues.

Accessing the Error List window of Visual Studio 1:

Reading the content of this window can be essential, e.g. to check if any errors occured while compiling a PLC project. The following code snippet shows how to read the content of this window using a C# application.

Code Snippet (C#):

ErrorItems errors = dte.ToolWindows.ErrorList.ErrorItems; 
for (int i = 1; i < errors.Count; i++)
{
  ErrorItem item = errors.Item(i);
}

Please note that the property “ToolWindows” is available in namespace EnvDTE80.DTE2.

Code Snippet (Powershell):

$errors = $dte.ToolWindows.ErrorList.ErrorItems
for ($i=1; $i –lt $errors.Count; $i++)
{
  $item = $errors.Item($i);
}

As you can see, the property ErrorItems returns a collection of all items in the Error List, where each item is of type ErrorItem. You can iterate through this collection for example by making use of its Count property. Each ErrorItem object has the following properties, which are identical to the columns in the ErrorList window (compare to screenshot above):

Property

Description

Description

Describes the error message.

FileName

Filename where the error occured.

Line

Line in which the error occured.

Column

Column in which the error occured.

Project

Project in which the error occured.

Please note that the last four properties are not always used or don't make sense in every situation. For example, when looking at the screenshot above, the error message "No license found" is not bound to a specific file, line or column because it is a general TwinCAT error message.