none
Make .NET COM object accessable over the LAN? RRS feed

  • Question

  • Hello, I've created COM-object using C#:

    using System.Runtime.InteropServices;
    using System.Diagnostics;
    using System;
    
    [ComVisible(true)]
    [Guid("<interface_guid>")]
    public interface IMyTest {
        string Test();
    }
    
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [Guid("<class_guid>")]
    public class MyTest : IMyTest {
        public string Test() {
            var pro = Process.GetCurrentProcess();
            var mac = Environment.MachineName;
    
            return $"{mac} - {pro.Id} - {pro.ProcessName}";
        }
    }

    I'm registering COM-object programatically like this:

    var asm = Assembly.LoadFrom("<path_to_the_dll>");
    var reg = new RegistrationServices();
    
    reg.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase);
    
    var nam = "AppID\\<class_guid>";
    using(var key = Registry.ClassesRoot.CreateSubkey(nam)) {
        key.SetValue("DllSurrogate", "", RegistryValueKind.String);
        key.SetValue("", "MyTest", RegistryValueKind.String);
    }
    
    nam = "CLSID\\<class_guid>";
    using(var key = Registry.ClassesRoot.CreateSubkey(nam)) {
        key.SetValue("AppID", "<class_guid>", RegistryValueKind.String);
    }

    When I try to access the object on local machine with VBScript, everything works

    set obj = CreateObject("MyTest", "localhost")    ' Works
    set obj = CreateObject("MyTest", "127.0.0.1")    ' Works
    set obj = CreateObject("MyTest", "<ip_address>") ' Works
    
    WScript.Echo(obj.Test)

    However, when I try accessing it from remote machine, I get error with HRESULT of 0x800A01AD.

    Can you please tell me what I'm doing wrong here?

    Wednesday, February 14, 2018 9:11 AM

All replies