无法将类型'string'隐式转换为'System.Collections.Generic.IEnumerable <xrm.activityparty>'

时间:2018-05-30 19:33:43

标签: c# .net string type-conversion

我收到了两个指向下面脚本的错误:

收到错误:

  

无法隐式转换类型'string'   System.Collections.Generic.IEnumerable<Xrm.ActivityParty> FOR To =   emailData.To,

还收到错误:

  

无法使用集合初始化类型'Xrm.ActivityParty'   初始化程序因为它没有实现   'System.Collections.IEnumerable'FOR From = new 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
            }
        };
    }
}

2 个答案:

答案 0 :(得分:1)

似乎ToIEnumerab<ActivityParty>,您正试图为其分配一个简单的字符串。你可以使用这样的数组:

To = new [] {new ActivityParty { To= emailData.To }}

同样对于From属性,您需要声明属性名称:

From = new ActivityParty
{ 
    Address = emailData.Sender.Address
}

答案 1 :(得分:0)

根据MSDN文档,您需要创建活动方类变量以指定“收件人”和“发件人”属性。

 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 },