-1

I write a simple Activex (just show alert Hello World) but I can't acces to my method HelloWorld of my C# program when I call ActiveX in a my JavaScript function

This is my C# program

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace DemoCSharpActiveX
{
    [ProgId("DemoCSharpActiveX.HelloWorld")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [Guid("1c61c720-ce70-40e5-9e88-714469911fb3")]
    [ComVisible(true)]
    public class HelloWorld
    {
        [ComVisible(true)]
        public String SayHello()
        {
            return "Hello World!";
        }
    }
}

My html file

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 

<html>
  <head>
    <title>WebForm1</title>
  </head>
   <body>
       <OBJECT id="DemoCSharpActiveX" classid="clsid:1c61c720-ce70-40e5-9e88-714469911fb3" VIEWASTEXT></OBJECT>  

        <script type="text/javascript">
            try {
                var obj = document.DemoCSharpActiveX;
                if (obj) {
                    alert(obj.SayHello());
                } else {
                    alert("Object is not created!");
                }
            } catch (Err) {
                alert(Err.description);
            }

        </script>
   </body>
</html>

If I execute my html file I get this error :

  Object does not support this property or method
user1814879
  • 984
  • 6
  • 23
  • 49
  • Hard to guess what could be wrong, code is okay, html is okay. Works fine when I try it. The error message hints at DLL Hell, trying to use an old version of the assembly that didn't have the SayHello() method yet. Re-run regasm.exe, perhaps. Be sure to use the correct version of it. – Hans Passant Apr 16 '14 at 12:55

1 Answers1

0

Are you sure that your ActiveX is properly registered in system and that it is properly initialized?

Your activeX does not implement IObjectSafety interface so IE will not run it normaly. Check what security zone does your demo page land in and set this setting Prompt when initializing unsafe activex

Also, you might want to look at this example and if you want install ActiveX from CAB then also this SO question

Community
  • 1
  • 1
pepo
  • 8,644
  • 2
  • 27
  • 42