Error: Could not load file or assembly 'Sage.Peachtree.Domain

SUGGESTED

I am using the 2015 .Net SDK in a simple Windows Forms application to test integrating with Sage 50.

I have Sage 50 installed on my development machine which is Windows 7 x64. My project is set to compile for x86 and targets .Net 4.0. I am running Visual Studio as Administrator.

At this point this is all the code I have:

        Dim Session As PeachtreeSession
        Sage.Peachtree.API.Resolver.AssemblyInitializer.Initialize()

        Session = New PeachtreeSession
        Session.Begin("")                           <------------- Error on this line

I can get past the error by adding a reference to Sage.Peachtree.Domain.dll from the C:\Program Files (x86)\Sage\Peachtree folder, but that is clearly not the recommended approach per this post: http://sagecity.na.sage.com/support_communities/sage50_accounting_us/f/136/t/51240.aspx

Other users have this issue, but with no clear solution:

http://sagecity.na.sage.com/support_communities/sage50_accounting_us/f/136/t/73219.aspx

What else needs to be done?

  • 0
    SUGGESTED

    Turns out this error happens if the Sage 50 code is in a class library and it is called by a Visual Studio unit test.

    If it is directly part of a Windows Forms application or if it is in a class library which is loaded into a Windows Form application using Reflection.Assembly.LoadFrom, it works OK, and the AssemblyInitializer.Initialize() call is not necessary.

    It would be helpful to have SDK samples that demonstrate how to make the connection work with a Visual Studio unit test. Even if I use Reflection.Assembly.LoadFrom within a test, the Session.Begin call fails with the same error.

    So, as far as I can tell, in order to unit test against Sage 50, you have to use the unit test Deployment option to copy ALL the Sage 50 dlls to the test directory. Which of course means you are testing a configuration that won't match runtime environment. Oh, and the test is deathly slow because it involves copying some 150 MB of files each time.

    Is there another solution?

  • 0 in reply to Judah Sali
    SUGGESTED

    The other approach to unit test is to reference Sage.Peachtree.Domain.dll in both the class library and in the unit test project. This works, but you have to remember to remove the reference to Sage.Peachtree.Domain.dll from the class library before deploying. That stinks.