Error when instantiating .NET/COM interop class via classic ASP

◇◆丶佛笑我妖孽 提交于 2019-11-29 16:55:28

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

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.

If you can, try using your library from another dynamic, COM enabled language. If you don't know of one, here's a quick snippet that you can use, if you have perl handy. (If you don't, grab ActivePerl to get started really quick)

use strict;
use warnings;
use Win32::OLE;

my $object = Win32::OLE->new('my.object.1')
    or die "Unable to create my.object.1!";
if (my $error = Win32::OLE->LastError()) {
    die "Still got an error starting up: $error\n";
}
print "Good!\n";

Alternatively, if Python is your gig, grab and install PyWin32 and try this:

try:
    import win32com.client as w32c
    from win32com.client import util
except ImportError:
    print "\npywin32 package must be installed.  Available https://sourceforge.net/projects/pywin32/\n"
    sys.exit()
lib = w32c.dynamic.Dispatch("my.object.1")
# error checking and more, yatta

If this works, then it's likely a configuration issue with your ASP app. If this doesn't, then it means the object that you're trying to create either a) isn't registered, or b) has a problem with the library. .NET dll's must be set up properly to export to COM. Was this .NET library one you created yourself?

I'm pretty sure Regasm.exe needs to be used to register a .Net dll to expose it to COM

Interesting post on the subject http://www.simple-talk.com/dotnet/visual-studio/build-and-deploy-a-.net-com-assembly/

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