I tried to connect SAGE 200 from a Windows App. It was working as accepted but all of sudden a threw an exception. It is the code used to connect.
public string Connect(string companyName)
{
application = null;
try
{
application = new Sage.Accounting.Application();
application.Connect();
foreach (Sage.Accounting.Company item in application.Companies)
{
if (item.Name == companyName)
{
application.ActiveCompany = item;
}
}
if (application.ActiveCompany == null)
throw new SageServiceException($"The configured company name {companyName} could not be found in Sage Financials");
return application.ActiveCompany.Name;
}
catch (Exception ex)
{
string inner = "";
if (ex.InnerException != null)
inner = ex.InnerException.Message;
throw new SageServiceException(ex.ToString() + Environment.NewLine + Environment.NewLine + inner);
}
}
And this is the exception
System.TypeInitializationException: The type initializer for 'Sage.Accounting.Application' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Sage.MMS.SAA.Client, Version=19.0.0.0, Culture=neutral, PublicKeyToken=b2daa66d74953d11' or one of its dependencies. The system cannot find the file specified.
at Sage.Accounting.Application..cctor()
--- End of inner exception stack trace ---
at Sage.Accounting.Application..ctor()
at SageLibrary.SageService.Connect(String companyName) in C:\Sage\HuntersSageImporter\SageLibrary\SageService.cs:line 24
Could not load file or assembly 'Sage.MMS.SAA.Client, Version=19.0.0.0, Culture=neutral, PublicKeyToken=b2daa66d74953d11' or one of its dependencies. The system cannot find the file specified.
Any idea.