Sage 200 Connector: Error – The type initializer for ‘Sage.Accounting.Application’ threw an exception
At runtime the task fails with the following error shown in the event log:
The type initializer for 'Sage.Accounting.Application' threw an exception
Enable Use Extended Logging within the Sage 200 Connector tool global settings:
With extended logging now on, run the failed task again and check the event log. You may receive the following:
Detailed Error System.TypeInitializationException: The type initializer for 'Sage.Accounting.Application' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Sage.Common.Caching.EntlibCacheManager' threw an exception. ---> System.IO.IOException: The file exists. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.__Error.WinIOError() at System.IO.Path.InternalGetTempFileName(Boolean checkHost) at Sage.Common.Utilities.TempFile.GetTempFileName() at Sage.Common.Caching.EntlibCacheManager..cctor() --- End of inner exception stack trace --- at Sage.Common.Caching.EntlibCacheManager.GetCache(String name) at Sage.Common.Caching.CacheProvider.GetCache(String cachename) at Sage.Common.Caching.CacheManager.get_SystemCache() at Sage.Accounting.Application..cctor() --- End of inner exception stack trace --- at Sage.Accounting.Application..ctor() at Tool.ToolRuntime.ConnectToSage() at Tool.ToolRuntime.ProcessRequest(RuntimeStepData stepConfig, String requestXml) at Tool.ToolRuntime.Run()
This error is due to the max number of temporary files being created in C:\Windows\Temp or C:\Users\XXXXXX\AppData\Local\Temp if the task is using impersonation.
Whenever a connection to sage is established a file is created of the name “tmp####.tmp” where the “#” is a hexadecimal number. This means we are limited to 65536 files before the error you are receiving is thrown.
Delete the temporary files located in C:\Windows\Temp or C:\Users\XXXXXX\AppData\Local\Temp.
To prevent this error from occurring again, if the task schedule is very short or even continuous it may be worth putting a decision step before the Sage 200 connector step which says ODBCStep.RowsReturned<>0.
This assumes a Database Query step is being used to retrieve the data being input into Sage. If no rows are returned by the query then the logic of the decision will prevent the Sage 200 Connector step from initialising. This way the temporary file is only created when needed.
Another option is to create a rule on the system to simply delete this temporary file once a day.
Sage 200 Integration Brochure
Learn how integrating Sage 200 with on premise or cloud-based business software removes the risk of costly errors and improves the visibility of critical data.Download Brochure