Registered COM+ object cannot be found in classic asp

强颜欢笑 提交于 2019-12-11 09:59:17

问题


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.


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/23794453/registered-com-object-cannot-be-found-in-classic-asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!