title: SSIS The variable cannot be found
body: <p>I want to execute package from visual studio solution </p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>private Microsoft.SqlServer.Dts.Runtime.Package pkgPaquete;
  private Application appAplicacion;
  
  public DTSExecResult EjecucionPaquete(string str_Paquete, List &lt; CatVariablesEtl &gt; Vars = null) {
  
    DTSExecResult respuesta;
    try {
      appAplicacion = new Application();
  
      appAplicacion.PackagePassword = "pass";
  
      pkgPaquete = appAplicacion.LoadPackage(str_Paquete, null);
      foreach(CatVariablesEtl item in Vars) {
        pkgPaquete.Variables[item.str_NombreVariable.ToString()].Value = item.str_ValorVariable.ToString();
      }
  
      respuesta = pkgPaquete.Execute();
  
      return respuesta;
    } catch (Exception ex) {
  
      throw new NotImplementedException();
    }
  
  }
  }
  }
  </code></pre>
  
  <p>It stop into foreach statement just in this line it throw catch:</p>
  
  <pre><code>pkgPaquete.Variables[item.str_NombreVariable.ToString()].Value = item.str_ValorVariable.ToString();
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/TeLgJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TeLgJ.png" alt="enter image description here"></a></p>
  
  <p><strong>str_NombredeVariable value:</strong>
  <a href="https://i.stack.imgur.com/aUNCW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aUNCW.png" alt="enter image description here"></a></p>
  
  <p><strong>item.str_ValorVariable value:</strong><a href="https://i.stack.imgur.com/SXuoY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SXuoY.png" alt="enter image description here"></a></p>
  
  <p><strong>Parameters into package:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/wbJmH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wbJmH.png" alt="enter image description here"></a></p>
  
  <p>Error:</p>
  
  <blockquote>
    <p>The variable cannot be found. This occurs when an attempt is made to retrieve a variable from the Variables collection on a container during execution of the package, and the variable is not there. The variable name may have changed or the variable is not being created.</p>
  </blockquote>
  
  <p>I read another relationed questions but I don´t found some correct answer to my problem. Help is very appreciated. Regards</p>
  
  <p><strong>Update:</strong> as Hadi comment I try to use  </p>
  
  <pre><code>var setValueParameters = new Collection&lt;PackageInfo.ExecutionValueParameterSet&gt;();
  </code></pre>
  
  <p>But I just get vs red mark, I need to import some reference?<a href="https://i.stack.imgur.com/jywS0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jywS0.png" alt="enter image description here"></a></p>
  
  <p>As the second answer of Hadi I cannot reference pkgPaquete.Variables:<a href="https://i.stack.imgur.com/Qeyw9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qeyw9.png" alt="enter image description here"></a></p>