简体   繁体   中英

ActiveX component can't create object COM interop

I have a requirement where I have to use a base64 encoding on an image in classic ASP

so I created a very simple class project in C# project and trying to make it COM visible, I've read all the guides and various other questions on stackoverflow but I still can't get vbscript to create the Object

The assembly is marked as ComVisible and output is marked to register for COM interop, my source for the class:

namespace Crypto
{
    [ComVisible(true)]
    [Guid("ad491fe9-ade0-46a1-bae0-d407a987a9e9"),ClassInterface(ClassInterfaceType.None)]
    public class Base64
    {
        public Base64() {
            //default com exposable constructor
        }

        public string Base64Encode(string filePath) {

            if (!File.Exists(filePath)) return "";

            using (Image image = Image.FromFile(filePath))
            {
                using (MemoryStream m = new MemoryStream())
                {
                    image.Save(m, image.RawFormat);
                    byte[] imageBytes = m.ToArray();

                    // Convert byte[] to Base64 String
                    string base64String = Convert.ToBase64String(imageBytes);
                    return base64String;
                }
            }
        }
    }
}

After build, I register it as cominterop and put in in GAC anyway, using

regasm *<file path>* /codebase /tlb
gacutil -i *<file path>*

everything registers successfully

when I call from a test classic asp page

set obj = CreateObject("Crypto.Base64")

I get

Microsoft VBScript runtime error '800a01ad'

ActiveX component can't create object: 'Crypto.Base64'

I have worked with ComInterop about 7-8 years ago in .Net 2.0, everything worked smoothly, I can't understand whats wrong in this case

On my dev machine, it's windows 10 pro 64-bit, target compilation is 4.6.2 Framework

Thanks to @Lankymart for pointing me in the right direction

Even though the COM exposable .NET assembly was compiled for both 32-bit / 64-bit 32-bit Applications still need to be enabled in the App Pool advanced settings to get it to work

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM