I'm trying to connect to a running Solid Edge instance, but I am getting the following error:
System.MissingMethodException: 'Method not found: 'System.Object System.Runtime.InteropServices.Marshal.GetActiveObject(System.String)'
I've been searching about this error and I found that:
"API was originally removed from .NET Core since COM support was not included.", but it is on .NET framework.
And "that API is a simple wrapper over the Running Object Table (ROT)" so there is a solution pulling function directly from source code and modifying the Marshal class.
I want to make another solution, more accurate for my project. The idea is to make a DLL with .NET Framework 4.8.1 and then use it in another projects that are programmed with .NET Core 7.
I wrote this code snippet for the DLL:
using System;
using System.Runtime.InteropServices;
namespace SolidEgde.OpenSDK
{
public static class Communication
{
/// <summary>
/// Connects to or starts a new instance of Solid Edge.
/// </summary>
/// <param name="startIfNotRunning"></param>
/// <returns>
/// An object of type SolidEdgeFramework.Application.
/// </returns>
public static SolidEdgeFramework.Application Connect(bool startIfNotRunning)
{
SolidEdgeFramework.Application application = null;
try
{
// Attempt to connect to a running instance of Solid Edge.
application = (SolidEdgeFramework.Application)Marshal.GetActiveObject(PROGID.SolidEdge_Application);
}
catch { throw; }
if (application != null)
application.Visible = true;
return application;
}
}
public static class PROGID
{
public const string SolidEdge_Application = "SolidEdge.Application"; // HKEY_CLASSES_ROOT\SolidEdge.Application
}
}
And then I call It from a test project, like this:
namespace Testeo
{
class Program
{
static void Main(string[] args)
{
SolidEdgeFramework.Application application = null;
application = SolidEgde.OpenSDK.Communication.Connect(true);
}
}
}
But I get the error mentioned at the beginning.
PS: in my project I am trying to connect to an instance of the Solid Edge CAD program.
Based on the comment of @Hans Passant, I search more info about legacy dll .NET Framework components and .NET Core integration and the answer is:
No, It is not possible to have both on a project in a safe way.
Why?
References to this problem: