通过经典 ASP 实例化 .NET/COM 互操作类时出错 [英] Error when instantiating .NET/COM interop class via classic ASP

查看:17
本文介绍了通过经典 ASP 实例化 .NET/COM 互操作类时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试实例化在经典 ASP 应用程序中暴露给 COM 的 C# .NET 类时遇到问题.我已经使用 tlbexp 生成了一个 typelib 并在 Component Services 中注册了它;现在尝试这样创建对象时:

I am having a problem when trying to instantiate a C# .NET class that's been exposed to COM in a classic ASP application. I've used tlbexp to generate a typelib and registered it in Component Services; now when trying to create the object as such:

Server.CreateObject("The.Class.Name")

我收到错误:

服务器对象错误 'ASP 0177 : 80131534'

Server.CreateObject 失败

我在网上搜索了有关此错误的信息,发现了很多讨论但没有解决方案.错误代码 0x80131534 显然意味着COR_E_TYPEINITIALIZATION,类型无法初始化",这表明问题出在构造函数中.相关类的构造函数将私有字段设置为来自同一程序集的另一个类的实例,然后从 XML 文件中读取一些配置设置.此行为经过单元测试,我已检查该文件是否存在;我看不到任何其他可能闯入其中的东西.

I've searched around online for information on this error, and found numerous discussions but no solution. The error code 0x80131534 apparently means "COR_E_TYPEINITIALIZATION, a type failed to initialize", which would suggest the problem would be in the constructor. The constructor of the class in question sets a private field to an instance of another class from the same assembly, and then reads some configuration settings from an XML file. This behaviour is unit tested and I've checked that the file exists; I can't see anything else that could be breaking in there.

其他几点可能有用也可能没用:

A few other points which may or may not be of use:

  • 引用 DLL 的测试 .NET 项目可以很好地实例化该类;然而,一个引用 TLB 的测试 VB6 项目因同样的错误而崩溃.DLL 和 TLB 都在同一个位置.
  • 此应用程序在 Windows XP Professional SP3 和 IIS 5.1 上本地运行.
  • .NET 程序集是使用 .NET Framework 2.0 构建的,尽管机器上安装了 3.5.

我知道其他人在他们的构建中没有遇到这个错误,所以我相信这可能是环境问题.欢迎任何建议,因为我一直在努力解决这个问题.

I know other people who don't get this error on their builds, so I believe it may be something environmental. Any suggestions are welcome as I've been struggling to fix this for some time.

提前致谢.

推荐答案

我们遇到了与具有构造函数的类完全相同的问题.有趣的是,只有在较旧的服务器上,较新的服务器才能正常工作.

We had exactly the same problem with a class that had a constructor. Funnily enough only on older servers, newer ones would work fine.

我们通过添加一个空白的公共默认构造函数来修复它...

We fixed it by adding in a blank public default constructor...

public class MyClass
{
    public string MyGString
    {
        get; set;
    }

    //Com Fix
    public MyClass(){}

    //Normal Class
    public MyClass(string myString)
    {
        HashAlgorithm = hashType;
    }

有人跟我有同样的问题...

Someone with the same problem to me...

http://social.msdn.microsoft.com/Forums/vstudio/en-US/4b021da2-3fc7-4f20-b3d0-0f90491a232e/regasm-not-registering-all-classes

较新的服务器具有此版本的 RegAsm 2.0.50727.5420 旧的服务器具有此版本 2.0.50727.3053 这可能与它在没有空白公共默认构造函数的情况下工作的原因有关.

Newer servers had this version of RegAsm 2.0.50727.5420 old ones had this version 2.0.50727.3053 This could be something to do with why it worked without a blank public default constructor.

这篇关于通过经典 ASP 实例化 .NET/COM 互操作类时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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