0

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:

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.

8
  • Create a different namespace for your code so you can specify your version of Runtime.InteropServices instead of the standard Core version Commented Sep 29, 2023 at 12:40
  • Thank for the answer @jdweng. If I understand you correctly, the projects already have different namespaces, and each one is using a different Target framework. .Net Framework 4.8 for the DLL (namespace = SolidEgde.OpenSDK) and .Net Core 7 for the executable (namespace = Testeo). Commented Sep 29, 2023 at 14:26
  • The you simply change the using statement : using System.Runtime.InteropServices; System and Runtime are the namespace and InterpService is the Class. Commented Sep 29, 2023 at 14:28
  • I'm sorry for the ignorance @jdweng , but I don't understand what you're asking me to change. Are you saying that I have to add using System.Runtime.InteropServices; in the executable part? Commented Sep 29, 2023 at 14:48
  • You have the source code. Change at top namespace System.Runtime.InteropServices to namespace MySystem.Runtime.InteropServices. Then top of your module : using MySystem.Runtime.InteropServices; Commented Sep 29, 2023 at 14:56

1 Answer 1

0

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?

  • They target a different set of assemblies (mscorlib vs. System.Runtime) which causes incompatibilities since all usages of types are prefixed with the assembly the type is from.
  • .NET Core can reference .NET Framework assemblies. This allows to reference the assembly and compile successfully. BUT this doesn't guarantee a successful execution on runtime, since .NET Core doesn't provide all the APIs from .NET Framework.

References to this problem:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.