Beispiel #1
0
        /// <summary>
        /// Loads the plugin assembly, applying either <c>Load</c> or <c>LoadFrom</c> context (see <see cref="PluginFolder.IsPrimary"/>).
        /// </summary>
        public static Assembly LoadPluginAssembly([NotNull] FileInfo file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            string sPluginName = Path.GetFileNameWithoutExtension(file.FullName);

            // Primary plugin: Load context, we assume that file name agrees to the assembly name
            if (PluginFolder.PrimaryPluginFolder.IsPluginUnderFolder(file))
            {
                return(Assembly.Load(sPluginName));
            }

            // Non-primary plugin: LoadFrom context, ensure file name agrees to the assembly name
            Assembly assembly = Assembly.LoadFrom(file.FullName);

            if (assembly.GetName().Name != sPluginName)
            {
                throw new InvalidOperationException(StringEx.FormatQuoted("The plugin assembly file {0} has an assembly name {1} that does not agree to the plugin name {2}.", file.FullName, assembly.GetName().Name, sPluginName));
            }
            return(assembly);
        }