Message 1 of 12
Not applicable
09-18-2012
06:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have the following helper class. It have worked fine for a long time but suddenly it does not work in one solution.
It still works in another solution, I have restarted the computer and is now fresh out of ideas of how to fix this.
Any suggestions to why I see this problem and how to solve it?
Error message: Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))
public static class InventorUtilities
{
public static Inventor.Application GetInventorApplication(bool startNewIfNotFound=false)
{
if (_inventorApplication != null)
return _inventorApplication;
try
{
_inventorApplication = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
}
catch (COMException ex)
{
if (startNewIfNotFound)
{
_inventorApplication = StartInventorApplication();
}
throw new COMException("Inventor application not found", ex);
}
return _inventorApplication;
}
private static Inventor.Application _inventorApplication;
public static Application InventorApplication { get { return GetInventorApplication(); } }
public static Inventor.Application StartInventorApplication()
{
try
{
// Start Inventor.
System.Type oType = System.Type.GetTypeFromProgID("Inventor.Application");
_inventorApplication = (Inventor.Application)System.Activator.CreateInstance(oType);
// Make Inventor visible.
_inventorApplication.Visible = true;
}
catch (COMException ex)
{
throw new COMException("Failed to start Inventor", ex);
}
return _inventorApplication;
}
public static MeasureTools MeasureTools { get { return InventorApplication.MeasureTools; } }
public static TransientGeometry TransientGeometry { get { return InventorApplication.TransientGeometry; } }
public static TransientObjects TransientObjects { get { return InventorApplication.TransientObjects; } }
public static UnitsOfMeasure UnitsOfMeasure { get { return InventorApplication.UnitsOfMeasure; } }
public static T GetActiveDocument<T>()
{
return (T)InventorApplication.ActiveDocument;
}
}
Solved! Go to Solution.
