1
Hello. I have a console application that runs in a different folder than the folder where the ERP PRIMAVERA core assemblies I need to use are located. The problem is that when you run my application, it says it does not find dependencies.
I have an Assembly resolve to indicate the folder where my dependencies are but it never gets called. What’s wrong?
class Program
{
static void Main(string[] args)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
EnumTipoPlataforma Plat = EnumTipoPlataforma.tpEmpresarial;
string Empresa = "Demo";
string User = "Teste";
string Password = "";
ErpBS Erp = new ErpBS();
StdBETransaccao objStdTransac = new StdBETransaccao();
Erp.AbreEmpresaTrabalho(Plat, Empresa, User, Password, objStdTransac, "DEFAULT");
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string assemblyFullName;
System.Reflection.AssemblyName assemblyName;
const string PRIMAVERA_API_FILES_FOLDER = @"PRIMAVERA\SG100\Apl"; //pasta da API do Primavera
assemblyName = new System.Reflection.AssemblyName(args.Name);
assemblyFullName = System.IO.Path.Combine(System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), PRIMAVERA_API_FILES_FOLDER), assemblyName.Name + ".dll");
if (System.IO.File.Exists(assemblyFullName))
return System.Reflection.Assembly.LoadFile(assemblyFullName);
else
return null;
}
}