none
How to install C# Interop Control ActiveX in Client Side RRS feed

  • Question

  • I made a Component COM
    IClassTest.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    
    namespace MyCOM
    {
        [ComVisible(true)]
        [Guid("8F388924-7743-4166-993F-CBF897D08A8B")]
        public interface IClassTest
        {
            string getString(string b);
        }
    }
    

    ClassTest.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    
    namespace MyCOM
    {
        [ComVisible(true)]
        [Guid("1AE4AD64-A951-4E6C-8600-AA1F08810DDD")]
        public class ClassTest : IClassTest
        {
            public string getString(string str)
            {
                return str + "1";
            }
        }
    }
    


    In AssemblyInf.cs has [assembly: ComVisible(true)]
    I made another asp application:
    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeBehind="Default.aspx.cs" Inherits="asp_test._Default" %>
    
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <object id="Obj" codebase="MyCOM.dll#version=1,0,0,0" classid="clsid:1AE4AD64-A951-4E6C-8600-AA1F08810DDD" VIEWASTEXT></object> 
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    
    <script type="text/javascript" >
        function test() {
            var test = Obj.getString('2');
            alert(test);
        }
        </script>
        <input name="btnTest" value="Call COM" onclick="test()" style=" width: 400px;" type="button">
    </asp:Content>
    


    I change IE settings to display ActiveX not trust and run the program. In windows XP works, In Windows Server works. 
    If I register the component manually "Client Windows XP can call Server Windows 2008 page". But if I "regasm /u MyCOM.dll" the page prompt to install, but not work, appears: "Object doesn't support this property or method". The dll is stored in the C:\WINDOWS\Downloaded Program Files, if I try to install more than once, creates a folder called CONFLICT.1.. C:\WINDOWS\Downloaded Program Files\CONFLICT.1 very strange. I think this is related to "safe inicialization" and I found this link: http://msdn.microsoft.com/en-us/library/aa751977.aspx#iobjsafe but this is for C++. How to make IE install C# Interop COM on client Side?
    I am using Visual Studio 2010 and C:\Windows\Microsoft.NET\Framework\v4.0.30319
    Thanks in Advance





    • Edited by James, Bond Saturday, August 6, 2011 2:27 PM
    Friday, August 5, 2011 6:17 PM

Answers

All replies

  • I found this article: http://www.codeproject.com/KB/vbscript/vbActiveXControl.aspx that say to make cab for .dll. but does not work for C# interop COM in my case.

    Have I to use WPF projects to make it work?
    Friday, August 5, 2011 6:35 PM
  • First, we should clarify terminology. You cannot create a COM or an ActiveX control in .Net. You can create Interop controls which look like ActiveX controls and can interact with COM clients.

    You can host COM objects in IE, and it may even be possible to host .Net interop objects, but the more important point is that you don't have to. IE can host any .Net control without having to create a COM wrapper for it. Just set the classid to the fully-qualified .Net class id (not the Guid). For example, if your control is in the MyCom namespace and the dll is also called MyCom, you could use:

    <object id="Obj" classid="MyCom.dll#MyCom.ClassTest" VIEWASTEXT>
    <%-- Add something in case the object can't be loaded --%>
    </object>
    



    Check out My Blog for tech news, development tips, and other information for geeks like me.
    Friday, August 5, 2011 8:30 PM
  • Hi Tim Copenhaver, thanks for reply. I wrapper in COM because C++ and Delphi also needs to use it.
    I would like to install the Interop control on client's machine, because it uses Windows's Store.
    I'll try to explain the situation:
    I have a server with MyCOM.dll registered with "regasm MyCOM.dll /codebase". The serve has a asp page on IIS that I can run IE e run the page to view Store of server. That page can also be accessed by Clients. 
    The client does not have MyCOM.dll registered and want to use the page. When it uses the dll installed on the server side, the client will access the server Store, but the ideal behavior is the client access their own store.  
    If I register the MyCOM.dll manually on the client side this works. But I would like to install automatic from IE. Is this possible? The IE prompt to install but the install has no effect.
    You posted:
    <object id="Obj" classid="MyCom.dll#MyCom.ClassTest" VIEWASTEXT>
    <%-- Add something in case the object can't be loaded --%>
    </object>
    

    How can I use object tag without codebase and control the Interop version on client side?
    How client can download and install MyCOM.dll without codebase?

    Thanks






    Friday, August 5, 2011 11:33 PM
    • Marked as answer by James, Bond Monday, August 8, 2011 1:51 PM
    Monday, August 8, 2011 1:51 PM
  •  

    I'm glad to hear that you got it working.

    Thank you for sharing your solutions & experience here. It will be very beneficial for other community members who have similar questions.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 9, 2011 1:22 AM