V10 ResourcesReference
ResourcesReference
Reference
Back | List of Articles

How to use the Resolver assembly in integration projects?

Last changed in 02/12/2020

The simplest way to use the API of PRIMAVERA applications is to use Visual Studio .NET, using the development language that is most convenient for you.

The correct way of make your developments is to reference the assemblies distributed with the PRIMAVERA ERP from the 'APL' folder.  During this task, we recommend setting the 'Copy Local' property to false, preventing referenced assemblies and their dependencies from being copied to the output folder while the project is building. This could lead to the existence of different versions of PRIMAVERA assemblies in the machine where the integrating application is installed.

To address this problem and avoid the need to make interventions on the integrating application due to ERP updates, it is important to always use the assemblies available in the 'APL' folder, which are guaranteed to be updated and compatible with the ERP, when developing the integrating application. To achieve this, you need to have a 'solve' method that handles the loading of assemblies. For this to happen, simply add a 'handler' during the application startup for the 'AssemblyResolve' event that exists in the application domain. During execution, when the necessary assembly does not exist in the application folder, the name of the 'assembly' is transferred to this method, and the loading can be handled locally in the most convenient way.

C#

///
/// APL folder Interops load example module.
///
static class Program 
{
	///
	/// The main entry point for the application.
	///
	[STAThread]
	static void Main() 
	{
		//This handler needs to be added before any reference to existing classes.
		//which means, in the application's Main() method THERE MUST BE NO VARIABLES DECLARED OF EXISTING ASSEMBLY TYPES.
		//With this method, in the application folder there must be no assemblies and references must be
		//added with Copy Local = False and Specific Version = false.
		AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
		//run the test method
		DoTest();
	}
		
	///
	/// Method for resolving assemblies.
	///
	static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) 
	{
		string assemblyFullName;
		System.Reflection.AssemblyName assemblyName;
		
		const string PRIMAVERA_FOLDER = “PRIMAVERA SG100 Apl”;
		
		assemblyName = new System.Reflection.AssemblyName(args.Name);
		assemblyFullName = System.IO.Path.Combine(System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), PRIMAVERA_FOLDER), assemblyName.Name + “.dll”);
		
		if (System.IO.File.Exists(assemblyFullName))
			return System.Reflection.Assembly.LoadFile(assemblyFullName);
		else
			return null;
	}
}

VB.NET

'
' APL folder Interops load example module.
' This example requires Interops references.
'
Module Program

	'Application start.
	Sub Main()
	
		'This handler needs to be added before any reference to existing classes.
		'which means, in the application's Main() method THERE MUST BE NO VARIABLES DECLARED OF EXISTING ASSEMBLY TYPES.
		'With this method, in the application's folder there must be no Interops and references must be
		'added with Copy Local = False and Specific Version = false.
		AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf CurrentDomain_AssemblyResolve
	  
		'Calls the test method
		DoTest()
	  
	End Sub

	'Method to resolve assemblies.
	Public Function CurrentDomain_AssemblyResolve(sender As Object, args As ResolveEventArgs) As System.Reflection.Assembly

		Dim assemblyFullName As String
		Dim assemblyName As System.Reflection.AssemblyName

		Const PRIMAVERA_FOLDER As String = “PRIMAVERASG100Apl”;

		assemblyName = New System.Reflection.AssemblyName(args.Name)
		assemblyFullName = System.IO.Path.Combine(System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), PRIMAVERA_FOLDER), assemblyName.Name + “.dll”)

		If (System.IO.File.Exists(assemblyFullName)) Then
			Return System.Reflection.Assembly.LoadFile(assemblyFullName)
		Else
			Return Nothing		
		End If

	End Function

End Module
Bookmark or share this article
Esta página foi útil?
Obrigado pelo seu voto.

login para deixar a sua opinião.

Obrigado pelo seu feedback. Iremos analisá-lo para continuarmos a melhorar!
Artigos Relacionados
Características das entidades e serviços Conceito de integração Conceito de extensibilidade Como registar projetos de extensibilidade? Boas práticas de organização de projetos de integração