在经典的asp中找不到注册的COM +对象 [英] Registered COM+ object cannot be found in classic asp

查看:166
本文介绍了在经典的asp中找不到注册的COM +对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS2008中使用C#创建了一个dll。它是使用.Net Framework 2.0编译的。该项目是使用Visual C#/ Windows下的类库模板创建的。我不知道这是否重要,但我试图在经典的asp和asp.net应用程序中使用结果DLL,而不是桌面应用程序。



这是创建的通过采用现有的经典asp vbscript代码,并在C#中重写。我不是很有经验的创建dll,所以有很多仍然需要学习。我一直在网上搜索创建此dll的各种帮助。



这是我迄今为止所做的。



顶级类设置如下:

 使用System.Runtime.InteropServices; 
使用System.EnterpriseServices;
使用系统;
使用System.Text;
使用System.Web;

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

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

项目中的其他类是公共的,它们都从类Framework继承。我没有包括GuidAttribute指令的这些类,因为我不知道是否有必要。我确实需要它们暴露,因为我将从我的经典asp / asp.net应用程序中引用它们。



在我编译代码之后,我复制了三个文件; Inter.Scripting.dll,WebFramework.dll和WebFramework.pdb到Web服务器。



Web服务器是安装了IIS 7.5的Windows 2008 R2框。 >

在服务器上的命令提示符下,我运行了regsvcs程序,并安装了这个程序集并注册了dll,出了任何问题。命令窗口如下所示:

  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安装实用版本4.0.30319.17929版权所有(C)微软公司。版权所有。

安装程序集:
程序集:E:\inetpub\wwwroot\web\WebFramework\WebFramework.dll
应用程序:WebFramework
TypeLib:E :\inetpub\wwwroot\web\WebFramework\WebFramework.tlb

我查了组件服务应用程序,并在COM +应用程序下面有一个WebFramework对象。我还运行regedit并搜索WebFramework,它找到我的应用程序在Computer\HKEY_CLASSES_ROOT\WebFramework ..



到目前为止,我认为一切都是正确的... 。/是吗?



当我使用以下代码运行测试经典asp页面时,我得到错误424 - 需要对象

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

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

Dim WebFrame
设置WebFrame = Server.CreateObject(WebFramework.Framework)

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

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

我缺少什么?为什么asp页面不能找到dll?



另一件我忘记提到的事情。在构建选项卡的项目属性页面中,有一个用于COM互操作注册的复选框。我已经尝试使用此选项进行编译,并且没有选中它,并没有任何区别。

解决方案

而不是专注于您的COM组件问题是尝试将ASP代码更改为有效的语法。


  HTML> 
< head>
< title>< / title>
< / head>

< body>



 <%
'此代码将被处理服务器端
错误恢复下一步

Dim WebFrame
设置WebFrame = Server.CreateObject(WebFramework.Framework)
我们有错误吗?显示它。
如果Err.Number<> 0然后
Response.Write(< hr>)
Response.Write(Err.Number)
Response.Write( - )
Response.Write(Err 。描述)
Response.Write(< br>< hr>)
End If
%>



 < / body> 
< / html>







为什么对象未找到错误?



如上所述,您的代码无效,为什么?


  1. 使用< script type =text / vbscript> 标签(通常 runat =server需要使用< script> 标签服务器端,但是当你收到一个错误,表明它正在被ASP处理。在将来,我建议你使用<%%> / code>来区分服务器端的处理。


  2. 除非您在其他地方实例化,否则没有这样的ASP对象名为文件如果我想我会说你正在尝试输出到屏幕上,要使用内置的响应对象(服务器端请求由请求响应组成。


我会说你的对象未找到通过ASP不了解什么文档是因此引发 Object Not Found 错误。







更新



阅读后您的评论我意识到您的代码是被解释为客户端,因此 Document.Write 不会导致对象未找到错误我认为现在的问题是 Server.CreateObject 因为这是客户端 VBScript 不能理解的服务器端语法。



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.

解决方案

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.

这篇关于在经典的asp中找不到注册的COM +对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆