C# 无法隐式转换类型';字符串';至';System.Collections.Generic.IEnumerable<;Xrm.ActivityParty>';
我收到两个指向下面脚本的错误: 接收错误: 无法将类型“string”隐式转换为 To的C# 无法隐式转换类型';字符串';至';System.Collections.Generic.IEnumerable<;Xrm.ActivityParty>';,c#,.net,string,type-conversion,C#,.net,String,Type Conversion,我收到两个指向下面脚本的错误: 接收错误: 无法将类型“string”隐式转换为 To的System.Collections.Generic.IEnumerable= emailData.To 以及接收错误: 无法使用集合初始化类型“Xrm.ActivityParty” 初始化器,因为它不实现 From的“System.Collections.IEnumerable”=新ActivityParty{ 代码如下: foreach (var file in unReadFiles) { Mi
System.Collections.Generic.IEnumerable
=
emailData.To
以及接收错误:
无法使用集合初始化类型“Xrm.ActivityParty”
初始化器,因为它不实现
From的“System.Collections.IEnumerable”=新ActivityParty{
代码如下:
foreach (var file in unReadFiles)
{
Microsoft.Office.Interop.Outlook._MailItem emailData = oApp.Session.OpenSharedItem(file);
try
{
Email scrapedMessage = new Email
{
Subject = emailData.Subject,
Subcategory = EmailHelper.ScrapeMethod.Manual.ToString(),
Description = emailData.HTMLBody,
To = emailData.To,
From = new ActivityParty{
emailData.Sender.Address
}
};
}
}
似乎
To
是一个IEnumerab
,您正试图为其分配一个简单的字符串。您可以使用如下数组:
To = new [] {new ActivityParty { To= emailData.To }}
此外,对于您的From
属性,您需要声明属性名称:
From = new ActivityParty
{
Address = emailData.Sender.Address
}
根据文档,您需要创建Activity party类变量以分配“to”和“From”属性
private Guid _contactId;
private Guid _userId;
// Create the 'From:' activity party for the email
ActivityParty fromParty = new ActivityParty
{
PartyId = new EntityReference(SystemUser.EntityLogicalName, _userId)
};
// Create the 'To:' activity party for the email
ActivityParty toParty = new ActivityParty
{
PartyId = new EntityReference(Contact.EntityLogicalName, _contactId)
};
To = new ActivityParty[] { toParty },
From = new ActivityParty[] { fromParty },
如果您认为答案解决了问题,请单击答案旁边的灰色复选标记将其标记为“已接受”。查看此链接了解接受答案的工作原理: