1

I created a dll in VS2008 using C#. It was compiled using .Net Framework 2.0. The project was created using the Class Library template under Visual C# / Windows. I don't know if that matters but I am trying to use the resulting dll in both classic asp and asp.net applications not on a desktop app.

This was created by taking existing classic asp vbscript code and rewriting it in C#. I am not very experienced with creating dlls so there is a lot of still need to learn. I have been searching the web for all kind of help in creating this dll.

Here is what I have done so far.

The top level class is set up like this:

using System.Runtime.InteropServices;
using System.EnterpriseServices;
using System;
using System.Text;
using System.Web;

[assembly: ApplicationName("WebFramework")]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationAccessControl(false,
           AccessChecksLevel = AccessChecksLevelOption.ApplicationComponent)]

namespace WebFramework
{
    [GuidAttribute("AACB678E-2C54-450A-873D-77A5A15BA0E5")]
    public class Framework : ServicedComponent
    {
        //Blah
    }
}

The other classes in the project are public and they all inherit from class Framework. I did not include the GuidAttribute directive for those classes because I don't know if that is necessary or not. I do need them exposed because I will reference them from my classic asp / asp.net applications.

After I compiled my code I copied the three files; Inter.Scripting.dll, WebFramework.dll and WebFramework.pdb to the web server.

The web server is a Windows 2008 R2 box with IIS 7.5 installed.

In a command prompt on the server I ran the regsvcs program and it installed this assembly and registered the dll with out any problems. The command window looked like this:

E:\inetpub\wwwroot\web\WebFramework>"C:\Windows\Microsoft.NET\Framework\v4.0.30319/regsvcs.exe" /appname:WebFramework /tlb:WebFramework.tlb WebFramework.dll

Microsoft (R) .NET Framework Services Installation Utility Version 4.0.30319.17929 Copyright (C) Microsoft Corporation.  All rights reserved.

Installed Assembly:
        Assembly: E:\inetpub\wwwroot\web\WebFramework\WebFramework.dll
        Application: WebFramework
        TypeLib: E:\inetpub\wwwroot\web\WebFramework\WebFramework.tlb

I checked the the Component Services app and there was a WebFramework object under COM+ Applications. I also ran regedit and searched for "WebFramework" and it found my application under Computer\HKEY_CLASSES_ROOT\WebFramework..

So far I think everything is correct....or is it?

When I run a test classic asp page with the following code I get Error 424 - Object required.

<html>
<head>
    <title></title>
</head>

<body>
    <script type="text/vbscript">
        On Error Resume Next

        Dim WebFrame
        Set WebFrame = Server.CreateObject("WebFramework.Framework")

        Document.Write("<hr>")
        Document.Write(Err.Number)
        Document.Write(" - ")
        Document.Write(Err.Description)
        Document.Write("<br><hr>")

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

What am I missing? Why can't the asp page find the dll?

[Edit] One other thing that I forgot to mention. In the Project Properties page on the Build tab there is a check box for Register for COM interop. I have tried compiling with this option checked and unchecked and it made no difference.

Robert Lawson
  • 151
  • 1
  • 3
  • 16
  • Your dll will appear in HKEY_CLASSES_ROOT and HKEY_LOCAL_MACHINE/Software/Classes. IT should be with the following format "Namespace.ClassName". Tell us if it is not the case – Dalorzo May 21 '14 at 23:50
  • Have you tried adding your dll to GAC (gacutil) and use the regasm tool to register for COM+ calls? http://msdn.microsoft.com/en-us/library/tzat5yw6(v=vs.110).aspx – Dinesh Rajan May 22 '14 at 03:18
  • Your ASP code makes no sense?? `Document.Write` is not a valid ASP object I'm guessing you mean `Response.Write`. Your ASP code is inside a client side `VBScript` ` – user692942 May 22 '14 at 10:22
  • Lankymart - Yes you are correct. Sometimes I get a little confused when jumping back and forth between client and server, vbscript, javascript, C#, VB, etc. Using the DOM Document.Write was putting text on the screen so I wasn't worrying about that as much as trying to get all my ducks in a row on the dll side. – Robert Lawson May 22 '14 at 14:31
  • @RobertLawson That clears things up I've updated my answer, think it will be the `Server.CreateObject` that's causing the error as it's not client side `VBScript`. – user692942 May 22 '14 at 14:47
  • @Dalorzo - The dll appears in both HKEY_CLASSES_ROOT and HKEY_LOCAL_MACHING/Software/Classes. And it follows the "Namespace.ClassName" convention. I have about 28 classes in the dll and they all show up. – Robert Lawson May 22 '14 at 16:22

2 Answers2

1

Instead of concentrating on your COM component being the issue try changing your ASP code to valid syntax.

<html>
<head>
    <title></title>
</head>

<body>
    <%
    'This code will be processed server-side
    On Error Resume Next

    Dim WebFrame
    Set WebFrame = Server.CreateObject("WebFramework.Framework")
    'Do we have an error? Display it.
    If Err.Number <> 0 Then 
      Response.Write("<hr>")
      Response.Write(Err.Number)
      Response.Write(" - ")
      Response.Write(Err.Description)
      Response.Write("<br><hr>")
    End If
    %>
</body>
</html>

Why the Object Not Found Error?

As stated above your code wasn't valid, why?

  1. Use of <script type="text/vbscript"> tag (usually runat="server" is required to use <script> tags server side, but as you get an error that suggests it is being processed by ASP. In future though I would recommend you use <% and %> to distinguish server side processing.

  2. Unless you instantiate it somewhere else, there is no such ASP object called Document. If I was to guess I would say you are trying to output to screen. To do this use the inbuilt Response object (server side request are made up of Request and Response).

I would say your Object Not Found is caused by ASP not understanding what Document is and hence raises the Object Not Found error.


Update

After reading your comment I realised that your code was being interpreted client side and so the Document.Write would not cause an Object Not Found error I think now the problem is the Server.CreateObject because this is server side syntax with client side VBScript will not understand.

Community
  • 1
  • 1
user692942
  • 16,398
  • 7
  • 76
  • 175
  • I think I might have bigger fish to fry. I think something is messed up in IIS. I cannot even get this to work: ' <% Response.Write("Hello World
    ") %> '. It displays an blank page.
    – Robert Lawson May 22 '14 at 14:46
  • @RobertLawson If it's not processing ASP at all then you need to make sure that you have a [HTTPHandler setup for Classic ASP](http://stackoverflow.com/a/9072482/692942) in IIS. You might also find [this guide](http://stackoverflow.com/a/22993413/692942) useful. – user692942 May 22 '14 at 14:50
  • Everything had been set up correctly by the Sys Admin who built this box. The only thing that I changed was in IIS. As suggested by the page that you directed me to I changed the Handler Mapping that I had created a few months ago for Classic ASP to use the 32 bit version if the asp.dll. I also changed the Applications Pool that I created from .Net Framework version 2.0 to No Managed Code. I can display straight HTML code without a problem. But after all of the changes I still to not see any vbscript Response.Write text. – Robert Lawson May 22 '14 at 16:09
  • @RobertLawson Is your app pool set to 32 bit mode? – user692942 May 22 '14 at 16:10
  • The default in IIS in the ASP icon for Script Language is VBScript. – Robert Lawson May 22 '14 at 16:10
  • Yes. Enable 32 bit Applications is set to true – Robert Lawson May 22 '14 at 16:11
  • @RobertLawson It sounds like a similar issue to what [this OP](http://stackoverflow.com/q/22186052/692942) has but I don't think he ever got an answer. – user692942 May 22 '14 at 16:16
  • 1
    I tried it without any HTML code. All that was in the file was '<%= Response.Write("Hello World") %>'. I even copied off of your comment and pasted it into the blank page. Nothing. It displays a polar bear in a snow storm. All white and no text. – Robert Lawson May 22 '14 at 16:35
  • Sorry should of said `<%= "Hello World" %>` or `<% Response.Write("Hello World") %>` the equals is a short-cut for `Response.Write`. – user692942 May 23 '14 at 14:53
  • No problem. It didn't work any way I tried it using vbscript or javascript on the server side. It will work client side but that is not going to help me because I have a ton of code that uses both client and server side scripting that was written long before I started working here. – Robert Lawson May 23 '14 at 18:29
0

I'm going out on a huge limb and answering this question before I have a resolution. I think my problem has nothing to do with the dll but rather with how IIS and this new web server has been set up.

I asked another question here: Getting IIS 7.5 to work with classic ASP that is about properly setting up the server and IIS.

So far no luck there but if I cannot even get a simple client side Hello World script to display Hello World on the web page then how was I ever going to think that I could create a dll object there.

If I solve the first problem and I still have problems with using the dll then I will come back to this and try again.

Community
  • 1
  • 1
Robert Lawson
  • 151
  • 1
  • 3
  • 16