When I debug my Windows Form Application I get this error:
Retrieving the COM class factory for component with CLSID {27526253-6119-4B38-A1F9-2DC877E72334} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
and because of it, my WFA can't interface with the software Solidworks installed on my computer; the only library that WFA needs to interface with Solidworks is
SolidWorks.Interop.sldworks.dll
(native position in the Solidworks directory C:\Program Files\SOLIDWORKS Corp 2017\SOLIDWORKS\SolidWorks.Interop.sldworks.dll).
Other informations below.
64 bit
(updated)x86
(32 bit)x86
(32 bit)When I added the library SolidWorks.Interop.sldworks.dll
into my project references, through Visual Studio, there wasn't the CLSID
{27526253-6119-4B38-A1F9-2DC877E72334}
into the Windows registry, so I tried to register that library in these ways:
SolidWorks.Interop.sldworks.dll
into directory
C:\Windows\SysWOW64The module C:\Windows\SysWOW64\SolidWorks.Interop.sldworks.dll was loaded but the call to DllRegisterServer failed...
So, the library was not registered.
SolidWorks.Interop.sldworks.dll
into the directory
C:\Windows\Microsoft.NET\Framework\v4.0.30319The types were registered.
So, I think, now the library is registered, in fact I see the CLSID
{27526253-6119-4B38-A1F9-2DC877E72334}
into the Windows registry.
The problem, however, persists.
In my C#
code I created a new Guid
; this is the code:
using System;
using System.Diagnostics;
using System.Windows.Forms;
using SolidWorks.Interop.sldworks;
namespace CreateModelSW
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Create interface
SldWorks swApp;
private void buttonCreateModel_Click(object sender, EventArgs e)
{
//Kill Solidworks processes
Process[] processes = Process.GetProcessesByName("SLDWORKS");
foreach (Process process in processes)
{
process.CloseMainWindow();
process.Kill();
}
//Create new GUID
Guid myGuid1 = new Guid("27526253-6119-4B38-A1F9-2DC877E72334");
object processSW = System.Activator.CreateInstance(System.Type.GetTypeFromCLSID(myGuid1));
//Create new SOLIDWORKS Part
swApp = (SldWorks)processSW;
swApp.Visible = true;
swApp.NewPart();
}
}
}
The problem persists.
Can you please help me? Thanks.
You should be using version agnostic progId, try this :
SldWorks swApp = (SldWorks)Activator.CreateInstance(System.Type.GetTypeFromProgID("SldWorks.Application"));