Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Commented Unassigned: AddHostObject works very slowly [68]

$
0
0
Hi!
AddHostObject works very slowly for an object of type Microsoft.Office.Interop.Excel.Workbook.
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Excel;

namespace ClearScriptTest
{
class Program
{
static void Main(string[] args)
{
Application ExcelApplication = null;
try
{
ExcelApplication = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
}
catch (COMException)
{
Type type = Type.GetTypeFromProgID("Excel.Application");
ExcelApplication = (Application)System.Activator.CreateInstance(type);
}
Workbook ExcelDocument = (Workbook)ExcelApplication.Workbooks.Add();
Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
engine.AddHostObject("ExcelObject", ExcelApplication);
engine.AddHostObject("DocumentObject", ExcelDocument); // Too long
engine.Execute(@"ExcelObject.ScreenUpdating = True
ExcelObject.Visible = True");
}
}
}
```
Can you please have a look?
Thanks!
Comments: This looks like a COM interop bug - an interesting one. When you call `AddHostObject()`, ClearScript asks for the object's imported type. At this point the CLR fails to detect that the relevant interop assembly is already loaded. Then it fails to look it up and load it manually. Finally, as a last resort, the CLR generates the interop assembly _on the fly_. For Excel's gigantic type library, this is the step that can take minutes. We'll have a workaround in the next ClearScript release. Thanks for reporting this issue!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images