Search code examples
c#.netbotframeworkopenxmlopenxml-sdk

Unable to integrate OpenXML (documentformat.openxml.*) in C# bot framework, getting the error " Autofac.Core.DependencyResolutionException "


In order to refine a powerpoint(.pptx) file, I have used OpenXML SDK(DocumentFormat.OpenXML) which works fine as a console Application. However, as the requirement was to implement the same in bot framework, I have added the required nuget package, viz., 'DocumentFormat.OpenXml.*'. The call to a new Dialog in the messageController throws an error at this line:

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

Bot works fine in emulator until I add the nuget package 'DocumentFormat.OpenXml.*'. However, it throws the mentioned error. Could not find relevant articles.

complete Method Code:

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

Exception:

An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IPostToBot (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IPostToBot], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: 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 ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IBotToUser (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: 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 ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IConnectorClient (DelegateActivator), Services = [Microsoft.Bot.Connector.IConnectorClient], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = ConnectorClientFactory (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IConnectorClientFactory], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security accessibility of the base type or be less accessible. (See inner exception for details.) (See inner exception for details.) (See inner exception for details.) (See inner exception for details.) (See inner exception for details.) (See inner exception for details.)

Inner Exception:

An error occurred during the activation of a particular registration. See the inner exception for details. Registration: 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 ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IBotToUser (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: 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 ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IConnectorClient (DelegateActivator), Services = [Microsoft.Bot.Connector.IConnectorClient], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = ConnectorClientFactory (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IConnectorClientFactory], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security accessibility of the base type or be less accessible. (See inner exception for details.) (See inner exception for details.) (See inner exception for details.) (See inner exception for details.) (See inner exception for details.)

Stack Trace:

at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable1 parameters) at Autofac.Core.Resolving.InstanceLookup.<Execute>b__5_0() at Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func1 creator) at Autofac.Core.Resolving.InstanceLookup.Execute() at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable1 parameters) at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable1 parameters) at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable1 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 parameters) at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context) at Microsoft.Bot.Builder.Dialogs.Conversation.d__11.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder.Autofac\Dialogs\Conversation.cs:line 0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Conversation.d__6.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder.Autofac\Dialogs\Conversation.cs:line 108 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at 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:line 27


Solution

  • For all those who have been working on a similar problem, the solution would be to proceed with following OpenXml nuget packages:

    DocumentFormat.OpenXml;

    DocumentFormat.OpenXml.Presentation;

    DocumentFormat.OpenXml.Spreadsheet;