1

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,

enter image description here 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;
 }
Samuel Lelièvre
  • 3,212
  • 1
  • 14
  • 27
David B
  • 315
  • 3
  • 13
  • 1
    I'd wager your project references a different version than what's in the gac. Turn on fusion logging and see what versions of their assemblies are being loaded. –  Jun 06 '18 at 14:04
  • @Will You are right its version 17.2.0.0 in the cache but in my project I am reference 17.0.0.1 but how do I reference or find out where those where added from in the GAC to get the right and correct file? – David B Jun 06 '18 at 14:08
  • Because I am sure if I just added the version in from the project that it complain about something is as there would then be two version of the dll in the cache hopefully this might be the fix – David B Jun 06 '18 at 14:15
  • If I were you, I'd "copy local" the reference in your project and deliver it with your application. If the same assembly exists in the gac, the CLR will use the gac version (which is shared among applications, about the only benefit to gac'ing references). If it doesn't exist there, it rolls with your version in your application folder. –  Jun 06 '18 at 18:15

0 Answers0