1.类库代码

1.1暴露的方法必须以接口的方式实现

1.2类需要GUID编号

 1 using System;
 2 using System.Runtime.InteropServices;
 3 
 4 //COM组件
 5 namespace PayCls
 6 {
 7     [Guid("051A5FA3-E34E-4DFF-AF77-BA6D6277A132")]
 8     public interface IPay
 9     {
10         string Init(string strJson);
11     }
12 
13 
14     [ClassInterface(ClassInterfaceType.None)]
15     [Guid("B88176F4-33E9-4C9B-807F-5AB3E25A0CF6")]
16     [ProgId("Pay.Application")]
17     public class Pay: IPay
18     {
19         public string Init(string strJson)
20         {
21             string result = "";
22             Decive dev = new Decive();23             try
24             {
25                 result = dev.Run(strJson);
26             }
27             catch (Exception ex)
28             {
29                 result = ex.Message;
30             }
31             return result;
32         }
33     }
34 }

 

2.在类库项目右键---属性---程序集信息 "使程序集可见" 打勾

3.生成---"为COM互操作注册"打勾

4.签名---”为程序集签名"打勾,选择强名称密钥文件 创建。可不输密码

5.生成dll后需要用gacutil与RegAsm加载并注册程序集,注意该dll所引用的其他dll都必须要加载并注册

E:\Tools\gacutil.exe /i Pay.dll
E:\Tools\gacutil.exe /i Newtonsoft.Json.dll
E:\Tools\gacutil.exe /i RestSharp.dll
E:\Tools\gacutil.exe /i Log4net.dll

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe Pay.dll
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe Newtonsoft.Json.dll
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe RestSharp.dll
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe Log4net.dll

6.log4net读取配置文件:

1                 string configFile = $@"{Environment.CurrentDirectory}\log4net.config";
2                 log4net.Config.XmlConfigurator.Configure(new FileInfo(configFile));

 

相关文章:

  • 2021-07-06
  • 2021-12-16
  • 2021-11-02
  • 2022-01-03
  • 2021-08-27
  • 2022-01-07
猜你喜欢
  • 2021-06-30
  • 2021-08-07
  • 2021-09-03
  • 2022-01-14
  • 2022-12-23
  • 2021-09-24
相关资源
相似解决方案