title: How to find the exact line that caused an error in C# code?
body: <p>I am executing a c# script (inside SSIS, an ETL tool) in a modified visual studio 2008 (actually called BIDS). I get an error, but the error message does not let me trace the line that caused the error. How do I find out which line is causing the problem. </p>
  
  <p>I tried using, try catch and my SSIS package ran without errors. But, when I remove the try catch, the package execution shows an error. Anyway, all this talk about SSIS is not really needed. Its the error/exception catching which matters here.</p>
  
  <pre><code>    try
      {            
          //my code here
      }
  
      catch (Exception e)
      {
          Console.WriteLine("{0} Exception caught.", e);
      }
  </code></pre>
  
  <p>The error info is given below - </p>
  
  <pre><code>Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&gt; System.NullReferenceException: Object reference not set to an instance of an object.
     at ST_LongCodeNameHere.csproj.ScriptMain.Main()
     --- End of inner exception stack trace ---
     at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct&amp; sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
     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>