I have a Class Library project in .NET Core named “LIBTOOBA” with the following setup:
Project File (LIBTOOBA.csproj):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="Interop.TSMSLIB_TLB">
<HintPath>DLLSInterop.TSMSLIB_TLB.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
</ItemGroup>
</Project>
Details about the DLL:
- Name: Interop.TSMSLIB_TLB
- Works on Platform target: x86
Class Definitions:
namespace LIBTOOBA
{
class Authentication
{
//...
}
class Proxy
{
//...
}
using TSMSLIB_TLB;
class TSMS
{
private Authentication a = new Authentication();
public Authentication A
{
set { this.a = value; }
get { return this.a; }
}
private TSMS_Tooba t = new TSMS_Tooba();
public TSMS_Tooba T
{
set { this.t = value; }
get { return this.t; }
}
public void init()
{
t.UserName = this.a.UserName;
t.Password = this.a.PassWord;
t.LibKey = this.a.LibKey;
t.ProxyServer = this.p.Server;
t.ProxyPort = this.p.Port;
t.ProxyUserName = this.p.UserName;
t.ProxyPassword = this.p.PassWord;
}
}
}
Main Class:
namespace LIBTOOBA
{
public class CL_TOOBASMS
{
private readonly TSMS CL_SMS;
public CL_TOOBASMS(string userName, string password, string libKey)
{
// Validate inputs
if (string.IsNullOrWhiteSpace(userName))
throw new ArgumentException("Username cannot be null or empty", nameof(userName));
if (string.IsNullOrWhiteSpace(password))
throw new ArgumentException("Password cannot be null or empty", nameof(password));
if (string.IsNullOrWhiteSpace(libKey))
throw new ArgumentException("LibKey cannot be null or empty", nameof(libKey));
CL_SMS = new TSMS();
try
{
CL_SMS.A.UserName = userName;
CL_SMS.A.PassWord = password;
CL_SMS.A.LibKey = libKey;
}
catch (Exception ex)
{
throw new InvalidOperationException("Failed to set SMS library credentials.", ex);
}
}
public (string Number, int Credit, int UsedCredit, string LastDate) GetMyAccountInfo()
{
//...
return (number, credit, usedCredit, lastDate);
}
public string GetDeliveryInfo(string sendToNumber, string sendEvent)
{
//...
return delivery;
}
public string SendSMS(string sendToNumber, string sendMsg)
{
//...
return sendEventTxt;
}
}
}
My Issue:
I have a WPF .NET Core 6 Application with Platform target set to AnyCPU (x64). When I add the “LIBTOOBA” library and try to run the application, I get the following error:
System.Runtime.InteropServices.COMException: 'Retrieving the COM class factory for component with CLSID {83A108DD-D51F-43AF-9290-00541698F0F9} failed due to the following error: 80040154 Class not registered (0x80040154 (REGDB_E_CLASSNOTREG)).'
There is no x64 version of the Interop.TSMSLIB_TLB.dll.
If I change my WPF Platform target to x86, it runs successfully. However, I want to keep my WPF .NET Core 6 Application on Platform target AnyCPU (x64). How can I bypass this issue?
Potential Solutions I am Considering:
- “Side-by-side” COM activation: Load the 32-bit COM component in a 64-bit process
- PInvoke (Platform Invoke) to call functions directly from unmanaged DLLs
- Separate 32-bit process for COM Interop
- Use CorFlags to force x86 execution
- Create a C++/CLI wrapper
Any suggestions or guidance on how to implement one of these solutions or another approach would be greatly appreciated.
I want to keep my WPF .NET Core 6 Application on Platform target AnyCPU (x64) , How can I bypass that ?