Asked by:
c# create activex issue

Question
-
Hi:
I used c # vs2017 to create an activex 64-bit dll project (not any cpu), which compiles and runs normally on the IE browser html webpage, but when I debug the html code in IE browser F12, it prompts that activex is not loaded. The operating system is Win10 64-bit, IE11. Thank you.
code show as below:.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace ClassLibrary1 { [ProgId("DemoClassLibrary1.HelloWorld")] [ClassInterface(ClassInterfaceType.AutoDual)] [Guid("731632A9-05F4-4B8E-A34E-BCA8168843B9")] [ComVisible(true)] public class Class1 { [ComVisible(true)] public String SayHello() { return "helloworld"; } } }
.csproj
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="15.0" xmlns="/////////////////////"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProjectGuid>{0D958562-8481-4A7F-8482-09EAED3B86C0}</ProjectGuid> <OutputType>Library</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> <RootNamespace>ClassLibrary1</RootNamespace> <AssemblyName>ClassLibrary1</AssemblyName> <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> <Deterministic>true</Deterministic> <TargetFrameworkProfile> </TargetFrameworkProfile> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <RegisterForComInterop>true</RegisterForComInterop> <AllowUnsafeBlocks>false</AllowUnsafeBlocks> <Prefer32Bit>false</Prefer32Bit> <PlatformTarget>x64</PlatformTarget> <FileAlignment>4096</FileAlignment> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <Prefer32Bit>false</Prefer32Bit> </PropertyGroup> <PropertyGroup> <SignAssembly>false</SignAssembly> </PropertyGroup> <PropertyGroup> <AssemblyOriginatorKeyFile>miyao.pfx</AssemblyOriginatorKeyFile> </PropertyGroup> <ItemGroup> <Reference Include="System" /> <Reference Include="System.Core" /> <Reference Include="System.Xml.Linq" /> <Reference Include="System.Data.DataSetExtensions" /> <Reference Include="Microsoft.CSharp" /> <Reference Include="System.Data" /> <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> <Compile Include="Class1.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <ItemGroup> <None Include="miyao.pfx" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
.html
<!DOCTYPE> <html> <head> <title>DemoCSharpActiveX webpage</title> </head> <body> <button>1231123</button> <OBJECT id="DemoActiveX" classid="clsid:731632A9-05F4-4B8E-A34E-BCA8168843B9"></OBJECT> <script type="text/javascript"> try { var obj = document.DemoActiveX if (obj) { alert(obj.SayHello()); } else { alert("Object is not created!"); } } catch (ex) { alert("Some error happens, error message is: " + ex.Description); } </script> </body> </html>
register dll:
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /register /codebase "C:\Users\Dell\Desktop\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll"
regedit:
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main] "TabProcGrowth"=dword:00000000
#########################################
The operation results are divided into two cases:
1. Direct operation, normal:
*. Use IE to open html webpage, it is normal.
2. Using IE F12 to debug html, exception:
*. Open IE
*. Press F12
* .Enter the local html file address
*. Prompt "Object doesn't support property or method 'SayHello'", the html object control (activex control) did not load successfully.
Question:
Why didn't it load successfully? I need to debug html code using IE F12.- Moved by CoolDadTx Monday, December 30, 2019 2:56 PM ASP.NET related
Monday, December 30, 2019 1:27 AM
All replies
-
Please post questions related to web development in the ASP.NET forums.
Michael Taylor http://www.michaeltaylorp3.net
Monday, December 30, 2019 2:56 PM -
Dear CoolDadTx:
How can I move it to ASP.NET forums.?
Tuesday, December 31, 2019 1:21 AM -
Dear CoolDadTx:
How can I move it to ASP.NET forums.?Tuesday, December 31, 2019 1:22 AM