gpt4 book ai didi

c# - 错误 :Could not load file or assembly 'DocumentFormat. OpenXml,

转载 作者:行者123 更新时间:2023-11-29 02:16:24 27 4
gpt4 key购买 nike

我得到这个错误是 VS2015

Additional information: Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

我正在尝试用 C# 发送带有数据库表附件的邮件

这里是我的代码id

using ClosedXML.Excel;
using MySql.Data.MySqlClient;
using System;
using System.Data;
using System.IO;
using System.Net.Mail;
using System.Windows.Forms;

namespace Email
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
String MyConString = "SERVER=10.0.30.125;" + "DATABASE=test;" + "UID=root;" + "PASSWORD=asterisk;" + "Convert Zero Datetime = True";
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = GetData();
dt.TableName = "data";
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(dt);
using (MemoryStream memoryStream = new MemoryStream())
{
wb.SaveAs(memoryStream);
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
using (MailMessage Msg = new MailMessage())
{
Msg.From = new MailAddress("my@mail.com");
Msg.To.Add("to@mail.com");
Msg.Subject = "DATA";
Msg.Body = "Excel Attachment";
Msg.Attachments.Add(new Attachment(new MemoryStream(bytes), "DATA.xlsx"));
Msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential();
credentials.UserName = "my@mail.com";
credentials.Password = "password";
smtp.UseDefaultCredentials = true;
smtp.Credentials = credentials;
smtp.Port = 587;
smtp.Send(Msg);
MessageBox.Show("MAIL SENT SUCCESSFULLY TO " + txtTo.Text);
txtTo.Text = "";
}
}
}
}
private DataTable GetData()
{
using (MySqlConnection conn = new MySqlConnection(MyConString))
{
using (MySqlCommand cmd = new MySqlCommand("SELECT * from table;", conn))
using (MySqlDataAdapter sda = new MySqlDataAdapter())
{
cmd.Connection = conn;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
}
}

我将它添加到我的 AddReference 中

ClosedXml.dll
DocumentFormat.OpenXml.dll
MySql.Data.dll

帮助解决我的问题。为什么我会收到此错误消息?

最佳答案

下载并安装 DocumentFormat.OpenXml 版本 2.5 https://www.microsoft.com/en-us/download/details.aspx?id=30425

关于c# - 错误 :Could not load file or assembly 'DocumentFormat. OpenXml,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38991488/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com