Accessing the Error List window of Visual Studio
This chapter describes how to access the Visual Studio Error List window. Because TwinCAT 3 integrates itself into the Visual Studio environment, reading the contents of this window is of great importance for debugging and diagnostics. To read the contents of this window, you must access the Visual Studio COM interface. Since this COM interface is also necessary for accessing TwinCAT XAE (e.g. as described in our article Accessing the TwinCAT configuration), you do not 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, e.g. if you want to compile a PLC project and want to monitor the compilation process for any error messages. Status messages for various properties of the Visual Studio (and therefore TwinCAT) development environment are displayed in the Error List window. These properties include, for example, compilation errors or license problems that occur when compiling a project.

Reading the contents of this window can be very important, e.g. to detect errors that occur when compiling a PLC project. The following code snippet shows how the content of this window can be read 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);
}Make sure that the "ToolWindows" property is available in the EnvDTE80.DTE2 namespace.
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 ErrorItems property returns a collection of all items present in the error list, where each item is of type ErrorItem. You can go through this collection by making use of its Count property, for example. Each ErrorItem object has the following properties, which correspond to the columns in the Error List window (compare with screenshot above):
Property | Description |
|---|---|
Description | Describes the error message. |
FileName | Name of the file in which the error occurred. |
Line | Line in which the error occurred. |
Column | Column in which the error occurred. |
Project | Project in which the error occurred. |
Note that the last four properties are not always used or do not make sense in every situation. For example, you can see in the screenshot above that the error message "No license found" is not linked to a specific file, line or column because it is a general TwinCAT error message.