For the first time ever, I’ll be copying an article from the SDK to my blog. Usually it goes on my blog first before going into the knowledge base. Anyway, most of you probably didn’t notice the new knowledge base article titled “Extension Loading Error Logging” in the Vault 2013 SDK. My colleague, Dan Dulzo, wrote the article after adding a feature that lets you log the load errors for any of your Vault extensions.
Sometimes, Vault extensions are loaded into environments without a GUI, such as an event handler. Unfortunately, if the extension fails to load due to errors, it will fail silently. As an SDK programmer, this can cause confusion when trying to develop and deploy an extension. Fortunately, the SDK can be configured to log these errors, allowing developers to see (and hopefully fix) what went wrong when loading an extension.
To enable logging, deploy an xml file named ExtensionLogConfig.xml to the same directory that extensions are deployed to (ex. C:\Program Data\Autodesk\Vault 2013\Extensions). Upon loading an extension, this directory is checked for the configuration file, and if it is found, logging is enabled. The ExtensionLogConfig.xml file has a pretty simple format. An example can be seen below.
The BaseFileName element specifies the location of the output log file, as well as the base file name of the file. The DateFormat element tells the logger the how to format the date when appending it to the log file name. The KeepLogsFor sets the number of days to keep log files for. The logger will attempt to automatically delete log files with a date older than the specified number of days. Using a value of -1 will cause the logger to delete any previous log information each time an extension attempts to load. Finally, the FileExtension element is used to specify the file extension to use for the log files.
Note: If there are no extensions to load, logging will not be performed regardless of any configuration file. Also, if the configuration file cannot be read due to being malformed or any other reason, logging will not be enabled.
The logger will write out what extensions load successfully and various error messages for extensions that failed to load. Most errors will result in a descriptive message getting written to the error log. Problems, such as having incorrect assembly attributes or missing a public contractor for your extension class, should be easy to identify when reading the log.
Unfortunately, the logger will not be able to provide a useful message in certain situations when the extension loader doesn't know enough about why an extension failed to load. In these cases, the log will contain a generic message resembling "Could not load file or assembly..." or sometimes no message at all. Below are some descriptions of common problems and likely solutions to a few situations where the logger will be unable to provide specific information about why an extension failed to load.
Problem 1: No log file is created
If an extension is failing to load and there is no log file being created, double-check that your ExtensionLogConfig.xml file is properly formatted xml. Ensure that the configuration file has appropriate values for all of the configuration settings, i.e. the complete file name is valid, DateFormat is an appropriate date format string, Vault has permission to create files in the directory specified in BaseFileName, etc. Next, check that the ExtensionLogConfig.xml has been deployed to the correct directory. A common mistake here is deploying an ExtensionLogConfig.xml file to each extension's directory. There should be only one configuration file and it should be deployed to the Extensions directory(C:\Program Data\Autodesk\Vault 2013\Extensions\ExtensionLogConfig.xml), NOT to a specific extension's directory (C:\Program Data\Autodesk\Vault 2013\Extensions\[Some Extension's Name]\ExtensionLogConfig.xml). Finally, check to make sure at least one extension is configured to load because no log file is created if there will be nothing to log.
Problem 2: An extension failed to load but there is nothing about the failed extension in the log file
The log file will always output messages for extensions that successfully load and extensions that try to load. If there are no message of an extension in the log file, it essentially means that Vault is unaware of the extension, and in fact, didn't even try to load it. The key thing to check in this situation is the .vcet.config file that is supposed to be deployed along with each extension. Make sure this file has the right name, is well formed, contains all the necessary information about the extension, and is in the correct directory. It's important to remember that the .vcet.config file is what lets Vault know of each extension to load. Another issue to check is that all extension files are deployed to the correct directory as well.
Problem 3: The log contains the vague error message of "Could not load file or assembly..."
For whatever reason, the extension loader could not load some sort of file or assembly referenced by an extension. The most common root cause of this message is that something is missing. Usually, the first thing to check is that all assemblies referenced by an extension are deployed along-side it (unless they are available in the GAC). Please note that certain SDK assemblies referenced by an extension do not need to be deployed with each extension because they are already loaded by Vault. Another possible cause is that the failed extension references the wrong version of the SDK assemblies, so be sure to check this as well.