title: Why does the BIML ScriptTask fail until I open the script in VS and save the package
body: <p>I have this BIML Script, which creates a Master and child package.  The child package has a ScriptTask in it that maps the value of a parent package variable to a child package variable.  When I Generate the packages in SSIS (Visual Studio 2015, target Sql Server 2014) they generate fine.  If I run the master package, the child fails with this error:</p>
  
  <pre><code>DTS Script Task has encountered an exception in user code:
  Project name:  ST_GetJobLogIdHere
  Exception has been thrown by the target of an invocation.
  
  at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
  at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
  at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
  at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
  at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
  </code></pre>
  
  <p>When I open the ScriptTask in the child, then close it again, the package is dirty so I save it.  After that, running the packages works properly.</p>
  
  <p>Here's the BIML Script:</p>
  
  <pre><code>&lt;Biml xmlns="http://schemas.varigence.com/biml.xsd"&gt;
  
      &lt;ScriptProjects&gt;
          &lt;ScriptTaskProject ProjectCoreName="ST_GetJobLogId" Name="ST_GetJobLogIdScript" VstaMajorVersion="0"&gt;
              &lt;ReadOnlyVariables&gt;
                  &lt;Variable Namespace="User" VariableName="vMasterJobLogId" DataType="Int32" /&gt;
              &lt;/ReadOnlyVariables&gt;
              &lt;ReadWriteVariables&gt;
                  &lt;Variable Namespace="User" VariableName="vJobLogId" DataType="Int32" /&gt;
              &lt;/ReadWriteVariables&gt;
              &lt;AssemblyReferences&gt;
                  &lt;AssemblyReference AssemblyPath="Microsoft.SqlServer.ManagedDTS" /&gt;
                  &lt;AssemblyReference AssemblyPath="Microsoft.SqlServer.ScriptTask" /&gt;
                  &lt;AssemblyReference AssemblyPath="System" /&gt;
                  &lt;AssemblyReference AssemblyPath="System.Data" /&gt;
                  &lt;AssemblyReference AssemblyPath="System.Windows.Forms" /&gt;
                  &lt;AssemblyReference AssemblyPath="System.Xml" /&gt;
              &lt;/AssemblyReferences&gt;
              &lt;Files&gt;
                  &lt;File Path="AssemblyInfo.cs" BuildAction="Compile"&gt;
                      using System.Reflection;
  
                      [assembly: AssemblyTitle("ST_GetJobLogId")]
                      [assembly: AssemblyDescription("")]
                      [assembly: AssemblyConfiguration("")]
                      [assembly: AssemblyCompany("")]
                      [assembly: AssemblyProduct("ST_GetJobLogId")]
                      [assembly: AssemblyCopyright("Copyright @ BMI 2017")]
                      [assembly: AssemblyTrademark("")]
                      [assembly: AssemblyCulture("")]
                      [assembly: AssemblyVersion("1.0.*")]
                  &lt;/File&gt;
                  &lt;File Path="ScriptMain.cs" BuildAction="Compile"&gt;
                      using Microsoft.SqlServer.Dts.Runtime;
  
                      namespace ST_GetJobLogId
                      {
                          [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPoint]
                          public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
                          {
                              public void Main()
                              {
                                  int jobLogId = (int)Dts.Variables["User::vMasterJobLogId"].Value;
                                  if (jobLogId != 0)
                                      Dts.Variables["User::vJobLogId"].Value = jobLogId;
                                  Dts.TaskResult = (int)ScriptResults.Success;
                              }
                              enum ScriptResults
                              {
                                  Success = DTSExecResult.Success,
                                  Failure = DTSExecResult.Failure
                              };
                          }
                      }
                  &lt;/File&gt;
              &lt;/Files&gt;
          &lt;/ScriptTaskProject&gt;
      &lt;/ScriptProjects&gt;
  
      &lt;Packages&gt;
          &lt;Package Name="Master" ProtectionLevel="EncryptSensitiveWithUserKey"&gt;
              &lt;Variables&gt;
                  &lt;Variable Name="vMasterJobLogId" DataType="Int32"&gt;1&lt;/Variable&gt;
              &lt;/Variables&gt;
              &lt;Tasks&gt;
                  &lt;ExecutePackage Name="PKG - Execute FixMe"&gt;
                      &lt;ExternalProjectPackage Package="FixMe.dtsx" /&gt;
                  &lt;/ExecutePackage&gt;
              &lt;/Tasks&gt;
          &lt;/Package&gt;
          &lt;Package Name="FixMe" ProtectionLevel="EncryptSensitiveWithUserKey"&gt;
              &lt;Variables&gt;
                  &lt;Variable Name="vJobLogId" DataType="Int32"&gt;0&lt;/Variable&gt;
              &lt;/Variables&gt;
              &lt;Tasks&gt;
                  &lt;Script Name="SCR - Get vJobLogId from parent vMasterJobLogId" ProjectCoreName="ST_GetJobLogIdHere" &gt;
                      &lt;ScriptTaskProjectReference ScriptTaskProjectName="ST_GetJobLogIdScript" /&gt;
                  &lt;/Script&gt;
              &lt;/Tasks&gt;
          &lt;/Package&gt;
      &lt;/Packages&gt;
  
  &lt;/Biml&gt;
  </code></pre>
  
  <p>What am I missing?  Why is the package failing until I open the code window manually?
  Thanks in advance for your help,
  Simon</p>