Hi,
calling
```
ExcelApi.Application.GetActiveInstances()
```
with an open Excel instance which has no workbooks visibly opened (i.e. start excel and close or hide the default workbook) causes a NullReferenceException.
I tracked it down to the excel hot fix in GetActiveProxiesFromROT and the subsequent proxy lookup by hWnd.
If no workbook is visible there seems to be no EXCEL7 window and the lookup returns a null reference, which then causes the NullReferenceException on COMObject instantiation.
Best regards,
Andreas
Comments: Hi Sebastain, I ran into this same problem today using NetOffice 1.7.3. I was able to find the 'GetActiveProxiesFromROT ' that Andreas mentioned. I created a brand new project, downloaded the NetOffice ExcelApi and put the following code in and it errors as they described. For anyone else that runs into this problem the code shows how I get around the problem using the NetOffice.RunningObjectTable class. Even with this issue NetOffice is a great library that I use a lot! Thanks! -Locke ``` using System.Linq class Program { static void Main(string[] args) { using (var application = new NetOffice.ExcelApi.Application()) using (var application2 = new NetOffice.ExcelApi.Application()) { application.Visible = true; application2.Visible = true; application.Workbooks.Add(); application2.Workbooks.Add(); //OK var applications = NetOffice.ExcelApi.Application.GetActiveInstances(); foreach (var wb in application2.Workbooks) wb.Close(false); //OK, though it will be missing "application2" because no workbooks are open. applications = NetOffice.RunningObjectTable .GetActiveProxiesFromROT("Excel", "Application") .Where(p => p != null) .Select(p => new NetOffice.ExcelApi.Application(null, p)) .ToArray(); //Not OK, this will error var applicationsError = NetOffice.ExcelApi.Application.GetActiveInstances(); application.Quit(); application2.Quit(); } } } ```
calling
```
ExcelApi.Application.GetActiveInstances()
```
with an open Excel instance which has no workbooks visibly opened (i.e. start excel and close or hide the default workbook) causes a NullReferenceException.
I tracked it down to the excel hot fix in GetActiveProxiesFromROT and the subsequent proxy lookup by hWnd.
If no workbook is visible there seems to be no EXCEL7 window and the lookup returns a null reference, which then causes the NullReferenceException on COMObject instantiation.
Best regards,
Andreas
Comments: Hi Sebastain, I ran into this same problem today using NetOffice 1.7.3. I was able to find the 'GetActiveProxiesFromROT ' that Andreas mentioned. I created a brand new project, downloaded the NetOffice ExcelApi and put the following code in and it errors as they described. For anyone else that runs into this problem the code shows how I get around the problem using the NetOffice.RunningObjectTable class. Even with this issue NetOffice is a great library that I use a lot! Thanks! -Locke ``` using System.Linq class Program { static void Main(string[] args) { using (var application = new NetOffice.ExcelApi.Application()) using (var application2 = new NetOffice.ExcelApi.Application()) { application.Visible = true; application2.Visible = true; application.Workbooks.Add(); application2.Workbooks.Add(); //OK var applications = NetOffice.ExcelApi.Application.GetActiveInstances(); foreach (var wb in application2.Workbooks) wb.Close(false); //OK, though it will be missing "application2" because no workbooks are open. applications = NetOffice.RunningObjectTable .GetActiveProxiesFromROT("Excel", "Application") .Where(p => p != null) .Select(p => new NetOffice.ExcelApi.Application(null, p)) .ToArray(); //Not OK, this will error var applicationsError = NetOffice.ExcelApi.Application.GetActiveInstances(); application.Quit(); application2.Quit(); } } } ```