title: Error thrown by Fitnesse while executing a C# method that creates an Excel
body: <p>I have an application test framework developed in C# which stores the result in an Excel file after each step. When executed inside the solution everything works fine. But when I am integrating the solution with Fitnesse and calling the method, an error is thrown. I have added the stack trace from Fitness below.</p>
  
  <p>The code segment is here:</p>
  
  <pre><code>public class ExcelReports : IReporter
  {
      private Excel.Application xlReport;
      public ExcelReports()
      {
          xlReport = new Excel.Application();
          Excel.Workbook xlWorkbook = xlReport.Workbooks.Add();
          ***xlWorkbook.SaveAs(ExecutionContext.RESULTFILE);***
      }
    }
  </code></pre>
  
  <p>The error is reported at xlWorkbook.SaveAs(ExecutionContext.RESULTFILE)</p>
  
  <p>I am using the fit and fitsharp dlls for the .NET 4.0 release.</p>
  
  <pre><code>    System.Reflection.TargetInvocationException: Exception has been thrown by the
      target of an invocation. ---&gt; System.Reflection.TargetInvocationException:
      Exception has been thrown by the target of an invocation. ---&gt;
      System.Runtime.InteropServices.COMException: Microsoft Excel cannot access the file
     'C:\0452CB00'. There are several possible reasons:
      • The file name or path does not exist.
      • The file is being used by another program.
      • The workbook you are trying to save has the same name as a currently open 
      workbook.
      at Microsoft.Office.Interop.Excel._Workbook.SaveAs(Object Filename, Object    
      FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, 
      Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, 
      Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local)
      at EF.UIAutomation.Commons.ExcelReports..ctor() in
             C:\EF.Automation\EF.UIAutomation.PageLibrary\Libraries\EF.UIAutomation.Commons.Reports.cs:l ine 25
  
      at EF.UIAutomation.Launcher.Program.Test() in
      C:\EF.Automation\EF.Automation\Program.cs:line 26
  
       --- End of inner exception stack trace ---
       at fitSharp.Machine.Model.TypedValue.ThrowExceptionIfNotValid()
       at fitSharp.Fit.Operators.CompareDefault.Compare(TypedValue actualValue, Tree`1
       expected)
       at fitSharp.Machine.Engine.ProcessorBase`2.&lt;&gt;c__DisplayClass3.
       &lt;&gt;c__DisplayClass5.b__2(CompareOperator`1 o)
  
       at fitSharp.Machine.Engine.Operators`2.Do[O](CanDoOperation`1 canDoOperation, 
       DoOperation`1 doOperation)
       at fitSharp.Machine.Engine.ProcessorBase`2.
       &lt;&gt;c__DisplayClass3.b__0(OperationLogging logging)
       at fitSharp.Machine.Engine.ProcessorBase`2.DoLoggedOperation[R](String
       startMessage, Func`2 operation)
       at fitSharp.Machine.Engine.ProcessorBase`2.Compare(TypedValue instance, Tree`1
       parameters)
       at fitSharp.Fit.Operators.CheckDefault.Check(CellOperationValue actualValue, 
       Tree`1 expectedCell)
       --- End of inner exception stack trace ---
       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 fitSharp.Machine.Engine.MethodMember.TryInvoke(Object[] parameters)
       at fitSharp.Machine.Engine.ReflectionMember.Invoke(Object[] parameters)
       at fitSharp.Machine.Engine.ProcessorBase`2.Operate[O](Object[] parameters)
       at fitSharp.Fit.Engine.CellProcessorExtension.Check(CellProcessor processor, 
       Object systemUnderTest, Tree`1 memberName, Tree`1 parameters, Tree`1 expectedCell)
       at fitSharp.Fit.Service.CheckBinding.Do(Tree`1 cell)
       at fitSharp.Fit.Service.Binding.Do(Tree`1 cell)
       at fit.ColumnFixture.DoCell(Parse cell, Int32 column)
  </code></pre>