The code you have displayed has no problem whatsoever, it is really what you should use (as in V9) to open the engine and the company. The problem is that the references are not registered in the system, as was the case with the COM references in earlier versions (for this you would need to manually register all the references / dependencies in the GAC ).
In this case we have two possible solutions:
Create an assembly resolve so that all DLLs will load when launching the application
If you want to use the 2 option, simply place the following (static) class in your project:
static class AssemblyResolve
{
const string PRIMAVERA_FILES_FOLDER = "PRIMAVERA\SG100\Apl";
public static void Resolve() => AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
System.Reflection.AssemblyName assemblyName = new System.Reflection.AssemblyName(args.Name);
string assemblyFullName = assemblyFullName = System.IO.Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), PRIMAVERA_FILES_FOLDER), assemblyName.Name + ".dll");
if (System.IO.File.Exists(assemblyFullName))
return System.Reflection.Assembly.LoadFile(assemblyFullName);
else return null;
}
}
Then, in the Program.cs
class, where your application starts, just invoke the Resolve()
method of the AssemblyResolve
class:
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
AssemblyResolve.Resolve();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
Please note that all references you have in the project should have the Copy Location and Specific Version properties of the false
.