I have a project that is attempting to connect to Sage 200. However it is complaining that the type initialisation has failed now usually that is to do with assembly not being in the cache however this time it is. I have restarted,
The error that I am receiving I also ran the gac utility to ensure that it was in the assembly cache and as you see below it is Sage.
The main error is:
{"The type initializer for 'Sage.MMS.SAA.Client.SAAClientAPI' threw an exception."}
But when debugging further the below is revealed
"Cannot cast the underlying exported value of type 'Sage.MMS.SAA.Client.ISAAClient (ContractName=\"Sage.MMS.SAA.Client.ISAAClient\")' to type 'Sage.MMS.SAA.Client.ISAAClient'."
This code works in other imports so I think it is something to do with the assembly file.
public bool ConnectToSage()
{
try
{
application = new Sage.Accounting.Application();
// Use the Connect method (no parameters required)
application.Connect();
foreach (var item in application.Companies)
{
if (((Sage.Accounting.Company)item).Name == Properties.Settings1.Default.CompanyName)
{
application.ActiveCompany = (Sage.Accounting.Company)item;
log.Info("Connected to company: " + Properties.Settings1.Default.CompanyName);
return true;
}
}
}
catch(TypeInitializationException ex)
{
}
return false;
}