mardi 7 mai 2019

Assembly in Script Component through reflections works for random cases

I have a weird problem. I have a SSIS package with multiple DataFlows and within them I am using a Script component as a destination to write AVRO files. Now for writing these AVRO files, I am using Microsoft.Hadoop.Avro.dll which I do not want to install to GAC and just refer using reflection. There is a cool guide here, which I have been following. Now all that worked in a demo project last week. However, today when I try to incorporate the same in my actual solution, some Dataflows work and everything goes fine but when the same script component is copied over to another dataflow and run using another dataset, it fails saying it can't find the assembly.

Point to note that - there is nothing wrong with the dataset, because the error is "loading the assembly".

Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Hadoop.Avro, Version=1.1.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

I am at my wits end to find the reason for this as it is baffling.

Here is the code for reflection that I used and works in one dataflow and not in the other (within the same package)

    public ScriptMain()
    {
        AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
    }
    public System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        string path =  @"C:\Program Files\Microsoft SQL Server\130\DTS\Binn\" ; //@"D:\AVRO Serialize and Deserialize\C#\bin\Debug\";
        if (args.Name.Contains("Microsoft.Hadoop.Avro"))
        {
            return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "Microsoft.Hadoop.Avro.dll"));
        }
        if (args.Name.Contains("Newtonsoft.Json"))
        {
            return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "Newtonsoft.Json.dll"));
        }
        return null;
    }

I have copied the assembly in the DTS\binn folder as my posts have suggested.

How, do I see a log of which paths the SSIS runtime is looking at, when it runs? I do not know what more info I can give because this is really weird but if anyone wants me to put in more details, please let me know and I can edit the question to include more details.

P.S: I also added it to GAC one time and then it worked but I do not want to do that on the server and also the fact that reflection did work in another project

One more details- last week when all dataflows worked in the test solution- It had the target version as 2017, which also showed up against the project name in Visual Studio. So, in the actual project where I have this weird problem of this working in one dataflow and not in the other, I tried to change the target server version to 2017 (from 2016), but the display against the project name still shows 2016. Could this be the problem? But then why does the display name of the project does not change to include 2017 even when change the target server version to 2017?

This is how it is in the solution where it all worked.

ProjectName (SQL Server 2017)

And this is how it is in the buggy project

ProjectName (SQL Server 2016)

Even changing the targer version to 2017 does nothing to the display but I doubt this to be the problem





Aucun commentaire:

Enregistrer un commentaire