0

I want to use in an ASP page, dll built in C#.

For this, I created a test DLL, the code is as follows:

using System;
using System.Runtime.InteropServices;

namespace MyDLL {

    [ComVisible(true)]
    public class Operations {

        [ComVisible(true)]
        public string getValue1( string sParameter ) {
            switch (sParameter) {
                case "a":
                    return "A was chosen";

                case "b":
                    return "B was chosen";

                case "c":
                    return "C was chosen";

                default:
                    return "Other";
            }
        }

        public string getValue2() {
            return "From VBS String Function";
        }
    }
}

With Assembly.cs :

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Les informations générales relatives à un assembly dépendent de 
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("MyDLL")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Hewlett-Packard Company")]
[assembly: AssemblyProduct("MyDLL")]
[assembly: AssemblyCopyright("Copyright © Hewlett-Packard Company 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly 
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de 
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[assembly: ComVisible(true)]

// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[assembly: Guid("a9a02baa-1de9-43be-8df0-147f0c371c67")]

// Les informations de version pour un assembly se composent des quatre valeurs suivantes*:
//
//      Version principale
//      Version secondaire 
//      Numéro de build
//      Révision
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut 
// en utilisant '*', comme indiqué ci-dessous*:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

After the build of the dll, I've registered with regasm.exe, using the following command: regasm MyDLL.dll /codebase

The Dll is successfully registered in registry :

HKEY_CLASSES_ROOT\MyDLL.Operations]
@="MyDLL.Operations"
[HKEY_CLASSES_ROOT\MyDLL.Operations\CLSID]
@="{0A42BA99-B4E1-356B-947E-EAC337F3B243}"

But when I launch my asp page :

<%@ language="javascript" %>

<!DOCTYPE html>
<html>
<body>
<%
try{
    var myDll = Server.CreateObject("MyDLL.Operations");  
    Response.Write("2 : " + myDll.getValue1("a")) ;
    Response.Write("2 : " + myDll.getValue2());
}catch(err){
    Response.write(err.message);
}
%>
</body>
</html>

My browser displays this message :

**ActiveX component can not create object**

I must have missed a step in the creation and/or registration of the dll ! Do you have any idea?

Maybe a track, I can't find the key {0A42BA99-B4E1-356B-947th-EAC337F3B243} in the registry [HKEY_CLASSES_ROOT \ CLSID].

user692942
  • 16,398
  • 7
  • 76
  • 175
Jo_
  • 13
  • 4
  • 2
    Could you be building a 64 bit COM object, and trying to load it from a 32 bit web server? – Baldrick Apr 17 '14 at 08:13
  • If I try this, I've the following message Error : RegAsm : error RA0000 : Failed to load '.\MyDLL.dll' because it is not a valide .NET assembly – Jo_ Apr 17 '14 at 10:02
  • First of all on top page it should be <%@ Language=VBScript %> secondary did you try dim myDLL
    set myDll = Server.CreateObject("MyDLL.Operations"); before you use it? And lastly Classic ASP does not have try-catch at all. For me it looks like you using syntax of C# in classic asp page. Choose one and work with it.
    – All Blond Apr 17 '14 at 13:45
  • One more thing, your DLL should be registered with IIS not just in registry of OS.You are trying to use third party component after all on IIS. – All Blond Apr 17 '14 at 13:54

0 Answers0