Classic ASP using C# .net DLL Object doesn't support this property or method

旧城冷巷雨未停 提交于 2019-12-10 11:09:15

问题


Hey all this is my first time creating a COM object for a classic asp page.

The process I followed when creating this COM DLL is this:

1) Used the Strong Name Tool (sn.exe) and placed the .snk file within the app. (sn -k myKey.snk)

2) Added:

[assembly: AssemblyKeyFile(@"myKey.snk")]
[assembly: ComVisible(true)]

to the AssemblyInfo.cs. I do get a warning on the KeyFile saying:

Use command line option '/keyfile' or appropriate project settings instead of 'AssemblyKeyFile'

3) Ran the following from the Administrator: SDK Command Prompt:

tlbexp c:\\temp\\dll\\classicASPWSEnDecrypt.dll /out:c:\\temp\\dll\\classicASPWSEnDecrypt.tlb

regasm /tlb:c:\\temp\\dll\\classicASPWSEnDecrypt.tlb c:\\temp\\dll\\classicASPWSEnDecrypt.dll

gacutil /i c:\\temp\\dll\\classicASPWSEnDecrypt.dll

regasm c:\\temp\\dll\\classicASPWSEnDecrypt.dll /codebase

All registered just fine without errors.

In my classic ASP page i have:

<%
 Dim classicEnDecrypt
 Set classicEnDecrypt = Server.CreateObject("classicASPWSEnDecrypt.Class1")

 response.write(classicEnDecrypt.Encrypt("testing"))
%>

I found that the ProgID (using OLEView) was Class1 as seen below:

And my C# code (just a snip) is this:

namespace classicASPWSEnDecrypt
{
  public class Class1
  {
      public string Encrypt(string PlainText)
      {
         [code here]
      }

      public string Decrypt(string EncryptedText)
      {
         [code here]
      }
  }
}

Once I run the ASP page on my local machine (IIS7/Windows 7 Enterprise) I get this error:

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'Encrypt'

/contactupdateWS.asp, line 49

Not quite sure why it says I don't have Encrypt function when I know I do?!

What could I be missing?


回答1:


I already provided some information in comment.

I also feel that you should not have static method for this. It seems that com does not support static method.

http://msdn.microsoft.com/en-us/library/ms182198.aspx

Also you are creating object of class by using Server.CreateObject method so it is quite obvious that you should have instance method for this.

public class Class1
  {
     public string Encrypt(string PlainText)
     {
     [code here]
     }

     public string Decrypt(string EncryptedText)
     {
     [code here]
     }
   }

Hope this help.



来源:https://stackoverflow.com/questions/24329935/classic-asp-using-c-sharp-net-dll-object-doesnt-support-this-property-or-metho

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