0

Today I am facing a strange issue, I need to create a web API in ASP.NET, which will retrieve data from the Sage 50 desktop. for this implementation, I am using Sage 50 SDK assembly Sage.Peachtree.API.

Here is what I have written:

public static Company InitSageSession()
    {
        Company _company = null;
        PeachtreeSession _session = new PeachtreeSession();
        try
        {
            _session.Begin("");
            if (_session.SessionActive)
            {
                try
                {
                    CompanyIdentifierList CompanyList = _session.CompanyList();
                    CompanyIdentifier companyId = CompanyList.Find((CompanyIdentifier o) => o.CompanyName == "Bellwether Garden Supply");
                    if (companyId == null)
                    {
                        return _company;
                    }
                    Sage.Peachtree.API.AuthorizationResult authorizationResult = _session.RequestAccess(companyId);
                    if (authorizationResult == Sage.Peachtree.API.AuthorizationResult.Granted)
                    {
                        _company = _session.Open(companyId);
                        return _company;
                    }

But the issue I am facing is When I called the Sage assembly method, then I got an exception.

Could not load file or assembly 'Sage.Peachtree.Domain, Version=2023.0.0.222, Culture=neutral, PublicKeyToken=d06c16dde04d83e4' or one of its dependencies. The system cannot find the file specified.

At this point:

_session.Begin("");

For testing purposes, I created sample windows forms application and write the same code which I wrote for WEB API. but in Windows forms, my code is working without any exceptions. This issue is coming in ASP.NET WEB API, WCF Except for Windows forms and console projects.

And Sage.Peachtree.API.dll architecture is x86. and my application architecture is also the same.

There are very few resources related to Sage 50 Desktop on the internet as it is an old architecture desktop application.

I am using .Net Framework 4.8 because Sage 50 SDK is not supported .Net Core. and I have faced these issues in visual studio.

Please can anyone advise?

kcrisman
  • 4,374
  • 20
  • 41
MichangGo
  • 31
  • 1
  • 9
  • This has nothing to do with Sage itself. The error says that the DLL wasn't found, possibly because it wasn't deployed along with the web application. You didn't specify which .NET version you used, .NET Framework or .NET Core? .NET 5+ are .NET *Core* 5+ and can't load any .NET Framework DLL – Panagiotis Kanavos May 26 '23 at 13:21
  • I am using .NET Framework 4.8 as Sage 50 SDK is not supported. net core, I am facing this issue on visual studio. In my project, I have already added assembly references. I just want to say that I am facing this issue in web API, my same code is working in Windows form. – MichangGo May 26 '23 at 13:36
  • yes, I have already added the DLL to the web app. This problem is coming in cloud projects (ASP.NET WEB API, WCF), the project which is in Windows System Base (WPF, Windows Forms, Console Application), this issue is not coming in it. – MichangGo May 26 '23 at 13:42
  • Those aren't cloud projects, they're web apps. You keep repeating about desktop applications. This doesn't matter. Unless you deploy the DLL along with your web app, the web app won't find it. Web apps aren't something new, they exist since 2002. StackOverflow itself is an ASP.NET application – Panagiotis Kanavos May 26 '23 at 13:45
  • 1
    If you add an assembly reference to an assembly registered in the Global Assembly Cache, you won't get a copy of that assembly when you deploy to the web server. Did you make sure the assembly exists on the web server? – Panagiotis Kanavos May 26 '23 at 13:46

0 Answers0