开发者

Getting DLLs in WinForms application

开发者 https://www.devze.com 2023-01-26 10:04 出处:网络
I have to create a class that will load all the dll\'s from repository and check whether they are inheriting from IMFServicePlugin interface and returns the

I have to create a class that will load all the dll's from repository and check whether they are inheriting from IMFServicePlugin interface and returns the valid dlls. that I have done using this...

using System;
using System.Collections.Generic;

using System.Diagnostics;
using System.Reflection;

using System.Window开发者_高级运维s.Forms.ComponentModel;
using MFDBAnalyser;

namespace MFDBAnalyserAssemblyValidator
 {
  public class MFDBAnalyserAssemblyValidator
  {
   static void Main(string[] args)
    {
        List<string> assemblyNames = new List<string>();
        Assembly[] oAssemblies = new Assembly[args.Length];

        for (int assemblyCount = 0; assemblyCount < args.Length; assemblyCount++)
        {
            oAssemblies[assemblyCount] = Assembly.LoadFile(args[assemblyCount]);

            try
            {
                foreach (Type oType in oAssemblies[assemblyCount].GetTypes())
                {
                    // Check whether class is inheriting from IMFServicePlugin.
                    if (oType.GetInterface("IMFDBAnalyserPlugin") == typeof(IMFDBAnalyserPlugin))
                    {
                        assemblyNames.Add(args[assemblyCount].Substring(args[assemblyCount].LastIndexOf("\\") + 1));
                    }
                }
            }
            catch (Exception ex) 
            {
                lblError.Text = "ERROR";
            }
        }

        // Passing data one application domain to another.
        AppDomain.CurrentDomain.SetData("AssemblyNames", assemblyNames.ToArray());
   }
  }
 }

but this was for loading the dll from the repository but I also want to store these dll in another ORM class.

Can anybody help me out... If possible plz provide some links so that I can get a sufficient idea of how dll works for an windows/desktop application.


At a first tip you should use Assembly.ReflectionOnlyLoad(). Cause if you load the assembly by using Assembly.LoadFile() the assembly will automatically be put into your local AppDomain!

0

精彩评论

暂无评论...
验证码 换一张
取 消