Showing posts with label gac. Show all posts
Showing posts with label gac. Show all posts

Wednesday, March 21, 2012

Script Task errors

I have a custom .dll that I put in MS.Net framework 2.0 + Gac for my development environment to create packages. I have a script task that references this dll and the precompile option is set to "False". When I change the precompile option to "True" and remove the dll from .net framework 2.0, I get errors. My question is why doesn't dtexecui.exe utility check GAC since I have set my precompile property for script tasks from false to true?

Is it possible that the script task is not getting refereshed in the package? I checked the .dtsx in notepad and found the binary listed right below the actual script. Any help would be appreciated.

After changing the PreCompile option to true, please open the script editor and close it. At this moment the precompilation should happen and you should no longer need the .dll in .NET framework folder (well, at least not until you need to modify the script again).

If you are still getting the errors after this, could you be more specific about what errors do you get?

|||

I replced my script tasks and everything works fine. So the only thing I can think of now is that when I started developing the package, we were on June cpt then Sept. CTP. With RTM, I cannot get the package to compile and work without errors unless I remove the script task, readd it, and reset the reference. Any thoughts?

sql

Script task DLL reference w/o being in GAC

I need to add a reference to a DLL from a script task. But I do not have the ability to put the DLL in the GAC. The DLL is a 3rd party DLL and they do not want to strong name it because that creates a chain effect having to strong name all DLL's that are used in their projects that share the DLL I need to refernce.

Ok my question is.. Can i reference that DLL somehow in the script task by manually adding the reference at runtime? I found this next snippet of code on the internet, i cant get it to work though.

Public Overridable Function CreateReferenceItem(ByVal itemName As String, ByVal assemblyName As String) As IVsaReferenceItem
Debug.Assert(Not (itemName Is Nothing) AndAlso Not (itemName = String.Empty))
Me.AssertEngineItemUnique(itemName)
Dim item As IVsaReferenceItem = CType(_engine.Items.CreateItem(itemName, VsaItemType.Reference, VsaItemFlag.None), IVsaReferenceItem)
item.AssemblyName = assemblyName
Return item
End Function

Have you thought about using Assembly.LoadFrom()?

I think that would be a lot easier. You can use any assembly you have access to, and don't need to reference it.

|||OK? how do i do that? in a script task? dts.assembly.loadfrom()? What do i need to import in order to get that assembly.loadfrom? do you have a sample code snippet? Thanks!|||Look at System.Reflection namespace, MSDN has lots of documentation and samples:
http://msdn2.microsoft.com/en-us/library/system.reflection.assembly.loadfrom.aspx|||Here is a script task that uses the Assembly object from the System.Reflection namespace. It loads a plane assembly that has not been strong named or put in the GAC and calls a method on it passing it a single String as a parameter. I tested this code with real values on one of my assemblies first. The names have been changed to protect the innocent. ;-)
It's a lot of code however.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Reflection
Imports System.Windows.Forms

Public Class ScriptMain

Public Sub Main()
'
' Add your code here
'
Dim myAssembly As Assembly
'load the assembly
myAssembly = Assembly.LoadFrom("C:\Path\To\The\Assembly.dll")

'get a reference to the type
Dim t As Type = myAssembly.GetType("Namespace.Name.Of.Class")

' create an instance of the object
Dim obj As Object = Activator.CreateInstance(t, True)

' create an array Type objects for the parameters
' This method only accepts one parameter that is a string
Dim argtype(0) As Type
argtype(0) = "".GetType()

'get the method
Dim mi As MethodInfo = t.GetMethod("MethodName", argtype)

'similar to above. No specifying an array of the
' parameter values
Dim params(0) As Object
params(0) = "my parameter value"

'invoke the method and get the results
Dim results As Object = mi.Invoke(obj, params)

' Display the results as a string
MessageBox.Show(results.ToString())

Dts.TaskResult = Dts.Results.Success
End Sub

End Class|||Thanks that is just what I am looking for. Very helpful I will try this out. Thanks All!