How fix "No parameterless constructor defined for this object" for TcSysManager class (a 3rd party COM object that supposedly has one)?

-1

I have a trivial exploratory unit test to use a 3rd party class that is a COM object. The class is TcSysManager. TcSysManager is in a "type library" named "Beckhoff TwinCAT XAE Base 3.2 Type Library" (Beckhoff is a PLC vendor that provides TwinCAT software API)."

This is generating a run-time failure that there is no parameterless constructor even though all their sample code suggests calling one (i.e., "new TcSysManager()"). I also believe that Add Reference of a type library containing COM objects results in Visual Studio creating the parameterless constructor (per Microsoft - COM Interop Part 1).

How do I fix this?

(None of the many "no parameterless constructor" SO posts I reviewed applied.)

Environment: Beckhoff TwinCAT 3.1.4022.16, VS2017 Enterprise 15.7.5, C# 4.7.2, ReSharper 2018.1.3, Windows 7 (and Windows 10)

Sample Exception (from a 2nd unit test against a 2nd class):

    Test method Thermo.TcSystemManager.Test.TcSysManagerTest.Test_TcConfigManager threw exception: 
System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {8CEC71B0-9B27-4238-B4D5-04849B1E688B} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
    at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Thermo.TcSystemManager.Test.TcSysManagerTest.Test_TcConfigManager() in C:\Code\HMI\HMI Source Code\TcSystemManagerTest\TcSysManagerTest.cs:line 48

Unit Test Failure

Console App Failure

c#
com
plc
twincat
asked on Stack Overflow Aug 7, 2018 by dthal • edited Aug 8, 2018 by dthal

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0