无法将OpenXML(documentformat.openxml。*)集成到C#Bot框架中,并显示错误“ Autofac.Core.DependencyResolutionException”

时间:2018-12-19 18:15:28

标签: c# .net botframework openxml openxml-sdk

为了优化powerpoint(.pptx)文件,我使用了OpenXML SDK(DocumentFormat.OpenXML),它可以很好地用作控制台应用程序。 但是,由于要在bot框架中实现相同的要求,因此我添加了必需的nuget包,即'DocumentFormat.OpenXml。*'。呼吁新 messageController中的对话框在此行引发错误:

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

在我添加nuget包'DocumentFormat.OpenXml。*'之前,Bot在模拟器中可以正常工作。但是,它引发了提到的错误。找不到相关文章。

完整的方法代码:

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

例外:

  

在激活特定注册期间发生错误。有关详细信息,请参见内部异常。注册:激活程序= IPostToBot(DelegateActivator),服务= [Microsoft.Bot.Builder.Dialogs.Internals.IPostToBot],生命周期= Autofac.Core.Lifetime.CurrentScopeLifetime,共享=共享,所有权= OwnedByLifetimeScope --->在运行期间发生错误激活特定注册。有关详细信息,请参见内部异常。注册:激活程序= QueueDrainingDialogTask(ReflectionActivator),服务= [Microsoft.Bot.Builder.Dialogs.Internals.QueueDrainingDialogTask(Microsoft.Bot.Builder.Dialogs.Internals.IPostToBot)],生命周期= Autofac.Core.Lifetime.CurrentScopeLifetime,共享=共享,所有权= OwnedByLifetimeScope --->在激活特定注册期间发生错误。有关详细信息,请参见内部异常。注册:激活程序= IBotToUser(DelegateActivator),服务= [Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser],生命周期= Autofac.Core.Lifetime.CurrentScopeLifetime,共享=共享,所有权= OwnedByLifetimeScope --->在运行期间发生错误激活特定注册。有关详细信息,请参见内部异常。注册:激活程序= AlwaysSendDirect_BotToUser(ReflectionActivator),服务= [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,共享=共享,所有权= OwnedByLifetimeScope --->在激活特定注册期间发生错误。有关详细信息,请参见内部异常。注册:激活程序= IConnectorClient(DelegateActivator),服务= [Microsoft.Bot.Connector.IConnectorClient],生命周期= Autofac.Core.Lifetime.CurrentScopeLifetime,共享=无,所有权=外部拥有--->激活a期间发生错误特殊注册。有关详细信息,请参见内部异常。注册:Activator = ConnectorClientFactory(DelegateActivator),服务= [Microsoft.Bot.Builder.Dialogs.Internals.IConnectorClientFactory],Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime,共享=无,所有权= ExternallyOwned --->违反了继承安全规则按类型:“ System.Net.Http.WebRequestHandler”。派生类型必须与基本类型的安全可访问性匹配,或者不可访问。 (有关详细信息,请参阅内部异常。)(有关详细信息,请参阅内部异常。)(有关详细信息,请参阅内部异常。)(有关详细信息,请参阅内部异常。)(有关详细信息,请参阅内部异常。)(有关详细信息,请参阅内部异常。)

内部异常:

  

在激活特定注册期间发生错误。有关详细信息,请参见内部异常。注册:激活程序= QueueDrainingDialogTask(ReflectionActivator),服务= [Microsoft.Bot.Builder.Dialogs.Internals.QueueDrainingDialogTask(Microsoft.Bot.Builder.Dialogs.Internals.IPostToBot)],生命周期= Autofac.Core.Lifetime.CurrentScopeLifetime,共享=共享,所有权= OwnedByLifetimeScope --->在激活特定注册期间发生错误。有关详细信息,请参见内部异常。注册:激活程序= IBotToUser(DelegateActivator),服务= [Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser],生命周期= Autofac.Core.Lifetime.CurrentScopeLifetime,共享=共享,所有权= OwnedByLifetimeScope --->在运行期间发生错误激活特定注册。有关详细信息,请参见内部异常。注册:激活程序= AlwaysSendDirect_BotToUser(ReflectionActivator),服务= [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,共享=共享,所有权= OwnedByLifetimeScope --->在激活特定注册期间发生错误。有关详细信息,请参见内部异常。注册:激活程序= IConnectorClient(DelegateActivator),服务= [Microsoft.Bot.Connector.IConnectorClient],生命周期= Autofac.Core.Lifetime.CurrentScopeLifetime,共享=无,所有权=外部拥有--->激活a期间发生错误特殊注册。有关详细信息,请参见内部异常。注册:Activator = ConnectorClientFactory(DelegateActivator),服务= [Microsoft.Bot.Builder.Dialogs.Internals.IConnectorClientFactory],Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime,共享=无,所有权= 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, Func 1个创建者)处      在Autofac.Core.Resolving.InstanceLookup.Execute()      在Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope,IComponentRegistration注册,IEnumerable 1 parameters) at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable 1个参数)处      在Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration注册,IEnumerable 1 parameters) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable 1个参数,对象和实例)处      在Autofac.ResolutionExtensions.ResolveService(IComponentContext上下文,服务服务,IEnumerable 1 parameters) at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable 1参数)处      在Autofac.ResolutionExtensions.Resolve [TService](IComponentContext上下文)      在D. \ a \ 1 \ s \ CSharp \ Library \ Microsoft.Bot.Builder.Autofac \ Dialogs \ Conversation.cs:line中Microsoft.Bot.Builder.Dialogs.Conversation.d__11.MoveNext()   ---从之前引发异常的位置开始的堆栈结束跟踪---      在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)      在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)      在D. \ a \ 1 \ s \ CSharp \ Library \ Microsoft.Bot.Builder.Autofac \ Dialogs \ Conversation.cs:line 108中的Microsoft.Bot.Builder.Dialogs.Conversation.d__6.MoveNext()   ---从之前引发异常的位置开始的堆栈结束跟踪---      在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)      在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)      在System.Runtime.CompilerServices.TaskAwaiter.GetResult()      在C:\ Users \ Tanu \ source \ repos \ CredentialsAutomation \ CredentialsAutomation \ Controllers \ MessagesController.cs:第27行中的CredentialsAutomation.MessagesController.d__0.MoveNext()

1 个答案:

答案 0 :(得分:0)

对于所有正在研究类似问题的人,解决方案是继续使用以下OpenXml nuget软件包:

DocumentFormat.OpenXml;

DocumentFormat.OpenXml.Presentation;

DocumentFormat.OpenXml.Spreadsheet;