// Kentico libraries aren't loaded into the AppDomain directly. For some reason all referenced assemblies // are outside the working folder of the azure function. We can load them but we need to find the proper location. // This method ensures Kentico assemblies only. Custom assembly can be loaded thru AssemblyDiscoveryHelper.RegisterAdditionalAssemblies method. private static void RegisterCmsAssemblies() { // In this case we count with fact that assembly file name is identical with assembly name var assemblyLocation = Path.GetDirectoryName(Assembly.Load("CMS.Core").Location); var cmsAssemblies = Directory.EnumerateFiles(assemblyLocation, "CMS.*.dll"); var assemblyNames = cmsAssemblies.Select(path => Path.GetFileNameWithoutExtension(path)); var assemblies = assemblyNames.Select(name => Assembly.Load(name)).ToArray(); AssemblyDiscoveryHelper.RegisterAdditionalAssemblies(assemblies); }
// Custom libraries aren't loaded into the AppDomain directly. For some reason all referenced assemblies // are outside the working folder of the azure function. We can load them but we need to find the proper location. // This method ensures custom assemblies are also loaded. Custom assembly can be loaded thru AssemblyDiscoveryHelper.RegisterAdditionalAssemblies method. private static void RegisterCustomAssemblies() { // Can use Wildcards as well List <Tuple <string, string> > AssemblyAndFiles = new List <Tuple <string, string> >() { new Tuple <string, string>("Xperience.CustomClasses", "Xperience.CustomClasses.dll"), // Add other libraries here }; foreach (Tuple <string, string> AssemblyAndFile in AssemblyAndFiles) { // In this case we count with fact that assembly file name is identical with assembly name var assemblyLocation = Path.GetDirectoryName(Assembly.Load(AssemblyAndFile.Item1).Location); var cmsAssemblies = Directory.EnumerateFiles(assemblyLocation, AssemblyAndFile.Item2); var assemblyNames = cmsAssemblies.Select(path => Path.GetFileNameWithoutExtension(path)); var assemblies = assemblyNames.Select(name => Assembly.Load(name)).ToArray(); AssemblyDiscoveryHelper.RegisterAdditionalAssemblies(assemblies); } }