[英]Error referencing dll in .net standard 2.0 library from .net core console application
嘗試在.net標准2.0庫中使用SendGrid nuget包時,出現以下錯誤消息。 此錯誤消息顯示在我的控制台應用程序捕獲中
Could not load file or assembly 'SendGrid, Version=9.8.0.0, Culture=neutral, PublicKeyToken=4f047e93159395ca'. The system cannot find the file specified.
控制台應用程序目標框架為:.NET Core 2.0
庫構建后,在控制台應用程序中通過轉至依賴關系->添加引用->從庫項目文件夾中的bin目錄中選擇dll來引用該庫dll(最終,該dll將移至私有nuget提要中) 。
.net核心控制台應用程序代碼如下所示:
static void Main(string[] args)
{
try
{
MailSender.SendEmail(new EmailRequest { Email = "toEmail@gmail.com" });
}
catch (Exception e)
{
}
}
這是庫目標框架:.NET Standard 2.0
這是我從以下錯誤中獲取的MailSender方法:
using EmailUtility.Models;
using SendGrid;
using SendGrid.Helpers.Mail;
using System;
using System.Collections.Generic;
namespace EmailUtility
{
public static class MailSender
{
public static void SendEmail(EmailRequest request)
{
var message = new SendGridMessage();
message.SetFrom(new EmailAddress("fromEmail@gmail.com"));
var recipients = new List<EmailAddress>
{
new EmailAddress(request.Email)
};
message.AddTos(recipients);
message.SetSubject("Test Email");
message.AddContent(MimeType.Html, "<h1>Test Email</h1>");
var client = new SendGridClient("APIKEY");
try
{
var response = client.SendEmailAsync(message);
}
catch (Exception e)
{
throw;
}
}
}
}
我下載的Sendgrid Nuget軟件包是version.9.9
我注意到在錯誤消息中它引用的是9.8版,因此我下載了Nuget軟件包資源管理器,並在引用的dll路徑中看到了該軟件包。
核心2.0應用程序和標准2.0庫之間是否存在一些兼容性問題? 我對出於兼容性目的使用標准感興趣。 非常感謝您提供有關如何解決此問題的幫助!
編輯:還注意到,如果我將控制台應用程序移到相同的解決方案中,並引用項目而不是dll,則代碼可以正常工作。 可悲的是,我不想將這些項目放在一起。
嘗試將dll放入控制台解決方案或另一個隨機文件夾中,這似乎是Visual Studio無法識別dll的原因,兼容性似乎是正確的。 奇怪的問題。 也可以嘗試暫時將它們重新定位,以查看是否確實是版本兼容性問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.