Reputation: 751
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
Upvotes: 1
Views: 1379
Reputation: 751
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
Upvotes: 0