Trying to use the .NET ACCPAC.Advantage library in a console app and it's saying I need a ref to windows.forms DLL? Is this normal? Do I really need win forms?
Hm, any ideas on why it's saying I need this DLL when I hit this line?
Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0
I don't know. I've been using the Sage COMAPI with Dotnet C# and VB for many years, and have never had that problem. Here is a snippet:
AccpacSessionMgr sessionmgr = new AccpacSessionMgr(); // As New AccpacSessionMgr
Int32 sid = 0;
sessionmgr.AppID = "XY";
sessionmgr.ProgramName = "XY1000";
sessionmgr.AppVersion = "60A";
sessionmgr.CreateSession("", sid, out Program.Globals.session);
Program.Globals.a4wLink = Program.Globals.session.OpenDBLink(tagDBLinkTypeEnum.DBLINK_COMPANY, tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE);
Program.Globals.a4wLinkRead = Program.Globals.session.OpenDBLink(tagDBLinkTypeEnum.DBLINK_COMPANY, tagDBLinkFlagsEnum.DBLINK_FLG_READONLY);
Thanks. What is the best documentation you've found on this API? I've been using these articles, but assume there's something more detailed
smist08.wordpress.com/.../
That's all the documentation I know of.
Last question. Maybe I pulled the DLL's from the wrong spot. Where do you find the DLL's required? I found mine in C:\Windows\Microsoft.NET\assembly\GAC_32
I get all my DLLs from the RUNTIME folder.
I opened up the ACCPAC.Advantage.dll and it does have a reference to Windows.Forms
That seems odd. I wonder if anyone else has used the .net API with C# and had this issue?
Well, I just happen to have two C# DotNet projects open that I've been working on.
The first project runs from a form, so Windows.Forms is there:
But on the 2nd, a console project, there's no Forms reference:
Here is how I start it in #2:
static bool OpenSession()
{
try
{
session = new AccpacSession();
session.Init("", "XY", "XY1000", "62A");
session.Open(ACCPACUSER, ACCPACPW, Properties.Settings.Default.AccpacCompany, DateTime.Today, 0, "");
a4wLink = session.OpenDBLink(tagDBLinkTypeEnum.DBLINK_COMPANY, tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE);
a4wLinkRead = session.OpenDBLink(tagDBLinkTypeEnum.DBLINK_COMPANY, tagDBLinkFlagsEnum.DBLINK_FLG_READONLY);
return true;
}
catch (Exception e)
{
// Console.WriteLine("Error in function OpenSession");
iErrorCount++;
Console.WriteLine(e.ToString());
return false;
}
}
You're only using the COMAPI though right? I'm using the ACCPAC.Advantage.dll
Yeah, the COMAPI fulfills all my programming needs.
No, you don't need forms. If you're adding a reference to the Advantage DLLs, you add them both (ACCPAC.Advantage.dll and ACCPAC.Advantage.Types.dll) from here:
C:\Program Files (x86)\Common Files\Sage\Sage 300 ERP\
Then see my other response to you regarding creating a session.
Thanks, so I think I figured it out. I'm using .NET 5 and it won't automatically pull Windows.Forms from GAC like .net framework apps do. Basically, it seems I may not be able to use .net core+ w/ Advantage.DLL
I think you're right. The last time I used the Advantage DLL was a VB6 project in 2005.
You can't use .NET Core with the Sage .NET API because they are Win32 DLLs and .NET Core is platform independent. Trying to reference the Win32 DLLs from a .NET Core project will break it because it will no longer be platform independent. You need to tell the project that the target platform is x86
*Community Hub is the new name for Sage City