简体   繁体   中英

Load Multiple Assemblies Using Reflection in SSIS Script Task

I came across a solution for loading an assembly in a script task using reflection such as this...

static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            if (args.Name.Contains("ssisHelper"))
            {
            string path = @"c:\temp\";
            return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "ssisHelper.dll"));

        }
        else if (args.Name.Contains("xxx"))
             {
            string path = @"c:\temp\";
            return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "xxx.dll"));


        };    return null;

That works great but my problem is that only works for one assembly. Is there a solution to load multiple assemblies?

I'm using Data Tools for Visual Studio 2015 and I'm trying to load two dlls that I can't add to a GAC. I'm using the 4.0 framework but I can go as high as 4.6.1 if need be.

Edit: Just in case it needs to be mentioned, The AssemblyResolve event handler can only be called once when the program starts. I call by

appDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

My problem was what I mentioned in the edit: The AssemblyResolve event handler is called for every missing Assembly, not once. If the 'IF' statement is correctly written, it should load the missing assemblies, including assemblies that reference other assemblies. Once my code was corrected, it worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM