Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2005

Tip: Looking for answers? Try searching our database.

Problems using C# class library - Class doesn't support Automation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nadia - 14 Sep 2005 20:14 GMT
Hi All,

I have a C# Class Library I created.  It contains a form and one class.
I can access the one class from JScript OK, but when I try to access
the method that launches the from I get this error message:
"Class doesn't support Automation"

Here is an abbreviated sample of my code:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Expando;
using XMetaL;
namespace LinkManager
{
    /// <summary>
    /// Summary description for CrossReference.
    /// </summary>
    [Guid("1CEC3EE2-C33B-44b4-AD1C-C881F912D8C3"), ComVisible(true),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface ICrossRef
    {
        //void InitializeComponent();
        [DispId(1)]
        void ShowIDDialog();
        [DispId(2)]
        void InsertLink(XMetaL.Selection sel);

    }

    [Guid("4599F628-4741-43ad-BFBC-AEB68BE37E1F"),
ClassInterface(ClassInterfaceType.None), ComVisible(true)]
    public class CrossReference : System.Windows.Forms.Form, ICrossRef
    {
        private System.Windows.Forms.TreeView treeDocument;
        private System.Windows.Forms.ListBox lstParas;
        private System.Windows.Forms.ComboBox cboTags;
        private System.Windows.Forms.Button btnCancel;
        private System.ComponentModel.IContainer components;
        public XMetaL.Application XMApp;
        private System.Windows.Forms.Button btnInsert;
        private System.Windows.Forms.MainMenu mainMenu1;
        private System.Windows.Forms.MenuItem mnuNav;
        private System.Windows.Forms.MenuItem mnuSelElem;
        private System.Windows.Forms.MenuItem mnuActions;
        private System.Windows.Forms.MenuItem mnuSetID;
        private System.Windows.Forms.MenuItem mnuLink;
        private System.Windows.Forms.MenuItem mnuExit;
        private System.Windows.Forms.StatusBar sBarPath;
        private System.Windows.Forms.ToolTip toolTip1;
        public XMetaL.Document currdoc;
        private System.Windows.Forms.MenuItem mnuLastElem;
        public XMetaL.Range startnode;
        Form CrossRef;

        public CrossReference()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //XMApp = CreateObject("XMetaL.Application");
            XMApp = new XMetaL.ApplicationClass();
            currdoc = XMApp.ActiveDocument;
            XMetaL.DOMNode docnode = (XMetaL.DOMNode)currdoc.documentElement;
            startnode = currdoc.Range;
            DisplayDomNode(0,docnode);
            TagsInit();
            selectid = "";

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                currdoc = null;
                XMApp = null;
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
        }
        #endregion

        public void InsertLink(XMetaL.Selection sel)
        {

        }

        public void ShowIDDialog()
        {
            CrossRef = new CrossReference();
            CrossRef.Show();
        }
    }
}

My JScript Code:
var LinkMan = new ActiveXObject("LinkManager.CrossReference");
LinkMan.ShowIDDialog();

TIA
Robert Jordan - 14 Sep 2005 20:38 GMT
Hi Nadia,

> I have a C# Class Library I created.  It contains a form and one class.
>  I can access the one class from JScript OK, but when I try to access
> the method that launches the from I get this error message:
> "Class doesn't support Automation"

If you want to access the class from JScript, you cannot
set ClassInterface(ClassInterfaceType.None). Set it
to AutoDual in this case.

But if you want to expose the class to JScript only and don't
then remove the ClassInterface attribute and the interface,
because it's usesless for JScript.

Rob

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.