首页 > 解决方案 > 无法在 C# bot 框架中集成 OpenXML (documentformat.openxml.*),出现错误“Autofac.Core.DependencyResolutionException”

问题描述

为了优化 powerpoint(.pptx) 文件,我使用了 OpenXML SDK(DocumentFormat.OpenXML),它可以作为控制台应用程序正常工作。但是,由于要求在 bot 框架中实现相同的功能,我添加了所需的 nuget 包,即“DocumentFormat.OpenXml.*”。在 messageController 中调用新 Dialog 会在此行引发错误:

await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());

Bot 在模拟器中工作正常,直到我添加 nuget 包'DocumentFormat.OpenXml.*'。但是,它会引发上述错误。找不到相关文章。

完整的方法代码:

public class MessagesController : ApiController
{

    public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
    {

        try
        {
            if (activity.GetActivityType() == ActivityTypes.Message)
            {
                await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
            }
            else
            {
                HandleSystemMessage(activity);
            }
        }
        catch (Exception ex)
        {
            activity.CreateReply(ex.Message);
        }
        var response = Request.CreateResponse(HttpStatusCode.OK);
        return response;
    }

例外:

激活特定注册期间发生错误。有关详细信息,请参阅内部异常。注册:Activator = IPostToBot (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IPostToBot], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> 期间发生错误特定注册的激活。有关详细信息,请参阅内部异常。注册:Activator = QueueDrainingDialogTask (ReflectionActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.QueueDrainingDialogTask (Microsoft.Bot.Builder.Dialogs.Internals.IPostToBot)], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> 激活特定注册时出错。有关详细信息,请参阅内部异常。注册:Activator = IBotToUser (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> 期间发生错误特定注册的激活。有关详细信息,请参阅内部异常。注册:Activator = AlwaysSendDirect_BotToUser (ReflectionActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser (Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser), Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> 激活特定注册时出错。有关详细信息,请参阅内部异常。注册:Activator = IConnectorClient (DelegateActivator), Services = [Microsoft.Bot.Connector.IConnectorClient], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> 激活一个错误具体注册。有关详细信息,请参阅内部异常。注册:Activator = ConnectorClientFactory (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IConnectorClientFactory], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> 违反继承安全规则按类型:'System.Net.Http.WebRequestHandler'。派生类型必须要么与基类型的安全可访问性相匹配,要么难以访问。(有关详细信息,请参阅内部异常。

内部异常:

激活特定注册期间发生错误。有关详细信息,请参阅内部异常。注册:Activator = QueueDrainingDialogTask (ReflectionActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.QueueDrainingDialogTask (Microsoft.Bot.Builder.Dialogs.Internals.IPostToBot)], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> 激活特定注册时出错。有关详细信息,请参阅内部异常。注册:Activator = IBotToUser (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> 期间发生错误特定注册的激活。有关详细信息,请参阅内部异常。注册:Activator = AlwaysSendDirect_BotToUser (ReflectionActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser (Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser), Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> 激活特定注册时出错。有关详细信息,请参阅内部异常。注册:Activator = IConnectorClient (DelegateActivator), Services = [Microsoft.Bot.Connector.IConnectorClient], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> 激活一个错误具体注册。有关详细信息,请参阅内部异常。注册:Activator = ConnectorClientFactory (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IConnectorClientFactory], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> 违反继承安全规则按类型:'System.Net.Http.WebRequestHandler'。派生类型必须要么与基类型的安全可访问性相匹配,要么难以访问。(详情请参阅内部异常。)(详情请参阅内部异常。)(详情请参阅内部异常。)(详情请参阅内部异常。)(详情请参阅内部异常。)CurrentScopeLifetime,Sharing = None,Ownership = ExternallyOwned ---> 类型违反了继承安全规则:'System.Net.Http.WebRequestHandler'。派生类型必须要么与基类型的安全可访问性相匹配,要么难以访问。(详情请参阅内部异常。)(详情请参阅内部异常。)(详情请参阅内部异常。)(详情请参阅内部异常。)(详情请参阅内部异常。)CurrentScopeLifetime,Sharing = None,Ownership = ExternallyOwned ---> 类型违反了继承安全规则:'System.Net.Http.WebRequestHandler'。派生类型必须要么与基类型的安全可访问性相匹配,要么难以访问。(详情请参阅内部异常。)(详情请参阅内部异常。)(详情请参阅内部异常。)(详情请参阅内部异常。)(详情请参阅内部异常。)

堆栈跟踪:

在 Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable 1 parameters) at Autofac.Core.Resolving.InstanceLookup.<Execute>b__5_0() at Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func1 创建者) 在 Autofac.Core.Resolving.InstanceLookup.Execute() 在 Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration 注册, IEnumerable 1 parameters) at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable1 参数) 在 Autofac .Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable 1 parameters) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable1 个参数)在 Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context) 在 Microsoft.Bot.Builder.Dialogs.Conversation.d__11.MoveNext() 在 D:\a\1\s\CSharp\Library\Microsoft.Bot。 Builder.Autofac\Dialogs\Conversation.cs:line 0 --- 从先前引发异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 在 System.Runtime.CompilerServices。 D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder.Autofac\Dialogs\Conversation.cs 中 Microsoft.Bot.Builder.Dialogs.Conversation.d__6.MoveNext() 的 TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) :第 108 行 --- 从先前引发异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 在 System.Runtime。CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at CredentialsAutomation.MessagesController.d__0.MoveNext() in C:\Users\Tanu\source\repos\CredentialsAutomation\CredentialsAutomation\Controllers\MessagesController .cs:第 27 行

标签: c#.netbotframeworkopenxmlopenxml-sdk

解决方案


对于所有一直在解决类似问题的人,解决方案是继续使用以下 OpenXml nuget 包:

文档格式.OpenXml;

DocumentFormat.OpenXml.Presentation;

DocumentFormat.OpenXml.Spreadsheet;


推荐阅读