C# 构建DLL类库
我试图用发送电子邮件的方法构建一个dll,用于另一个编程平台(OpenEdge-progress),但它不起作用,因为它显示错误0x80040154(类未注册)。要构建我的dll项目,我使用了: 贝娄,我班的全部代码:C# 构建DLL类库,c#,dll,com,C#,Dll,Com,我试图用发送电子邮件的方法构建一个dll,用于另一个编程平台(OpenEdge-progress),但它不起作用,因为它显示错误0x80040154(类未注册)。要构建我的dll项目,我使用了: 贝娄,我班的全部代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Mail; using System.IO; using System.R
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.IO;
using System.Runtime.InteropServices;
namespace EnviaEmail
{
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("61495415-e035-4bc5-bc00-70e46c9766b8")]
public interface IMailFunctions
{
void EnviaMail(string fromMail, string toMail, string bodyMail, string subjectMail, string attachmentsMail, string smtpMail);
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None), Guid("0262794c-1858-40d8-90ca-cfe765913d3c")]
public class clsEnviaEmail : IMailFunctions
{
public clsEnviaEmail(){}
[ComVisible(true)]
public void EnviaMail(string fromMail, string toMail, string bodyMail, string subjectMail, string attachmentsMail, string smtpMail)
{
string[] attachmentsSplit = attachmentsMail.Split(new Char[] { ',' });
// Create the mail message
MailMessage mail = new MailMessage();
// Set the addresses
mail.From = new MailAddress(fromMail);
mail.CC.Add(toMail);
// Set the content
mail.Subject = subjectMail;
mail.IsBodyHtml = true;
mail.To.Add(toMail);
foreach (string s in attachmentsSplit)
{
if (s.Trim() != "")
mail.Attachments.Add(new Attachment(s));
}
using (StreamReader reader = File.OpenText(bodyMail))
{
mail.Body = reader.ReadToEnd();
}
// Send the message
SmtpClient smtp = new SmtpClient(smtpMail);
smtp.Send(mail);
}
}
}
有什么想法吗?我可以问一下,当您可以创建一个类并使用内置的.NET Mail类
System.NET.Mail时,为什么要构建一个.dll来发送电子邮件代码>以执行此操作。。还有你为什么要发明轮子。。。关于如何使用System.Net.Mail使用,网上有太多的工作示例代码>DJ KRAZE,我不是在重新发明轮子。我将在另一个ERP、另一个基础结构中使用此DLL。在我的ERP中,我没有这么多有用的方法,比如这个(发送电子邮件)。我很抱歉,但是,我做了很多研究,但没有解决我的问题…这是不确定的,请给我一个负面的问题…我已经编辑了你的标题。请看“”,其中的共识是“不,他们不应该”,您需要使用
块将MailMessage
和SmtpClient
对象放入中。确定您是否实际检查了assmenbly,以确保ComVisible属性已实际设置为true,或者您是否假设该属性将处理该。。?