0
votes

Attempting to load multiple .xlsx files. After updating Office versions to 2013 to make sure the .dll was compatible, I'm still getting this error.

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module. Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified.

When attempting to execute the following code.

using System;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;

namespace SolnName
{
    class Program
    {
        static void Main(string[] args)
        {
            //File paths
            string path1 = @"path\file1.xlsx";
            string path2 = @"path\file2.xlsx";

            try
            {
                Excel.Application xlApp = new Excel.Application();

                Excel.Workbook book1 = xlApp.Workbooks.Open(path1);
                Excel.Worksheet sheet1 = (Excel.Worksheet)book1.Worksheets.get_Item(1);

                Excel.Workbook book2 = xlApp.Workbooks.Open(path2);
                Excel.Worksheet sheet2 = (Excel.Worksheet)book2.Worksheets.get_Item(1);

                book1.Close(true, null, null);
                book2.Close(true, null, null);

                xlApp.Quit();

                Marshal.ReleaseComObject(sheet1);
                Marshal.ReleaseComObject(sheet2);
                Marshal.ReleaseComObject(book1);
                Marshal.ReleaseComObject(book2);
                Marshal.ReleaseComObject(xlApp);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.Data);
                Console.WriteLine(e.Message);
            }
        }
    }
}

The plan ultimately is to create pivot tables in a new file based off the data, but I can't even execute opening and closing the files. The files DO exist at the actual file paths. All help is greatly appreciated!

1
Consider whether your error relates to a run-time failure to load your application's dependent assemblies or one of their dependent assemblies. Check out the the Fusion Log: hanselman.com/blog/…ScottWelker

1 Answers

2
votes

Target Framework was off for the VS Project.