【发布时间】:2019-05-20 06:55:27
【问题描述】:
为了优化 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;
}
例外:
在激活特定注册期间发生错误。有关详细信息,请参阅内部异常。注册: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'。派生类型必须要么与基类型的安全可访问性相匹配,要么难以访问。 (详见内部异常。)(详见内部异常。)(详见内部异常。)(详见内部异常。)(详见内部异常。)
堆栈跟踪:
在 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 注册,IEnumerable1 parameters) at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable1 参数) 在 Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration 注册, IEnumerable1 parameters) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 参数, Object& instance) 在 Autofac.ResolutionExtensions.ResolveService(IComponentContext 上下文,服务服务,IEnumerable1 parameters) at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable1 参数) 在 Autofac.ResolutionExtensions.Resolve[TService](IComponentContext 上下文) 在 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(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 Microsoft.Bot.Builder.Dialogs.Conversation.d__6.MoveNext() 在 D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder.Autofac\Dialogs\Conversation.cs:line 108 --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 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:line 27 中的 CredentialsAutomation.MessagesController.d__0.MoveNext() 处
【问题讨论】:
-
“在我添加 nuget 包 'DocumentFormat.OpenXml 之前,Bot 在模拟器中工作正常。” - 即使不使用,添加包后你是否也会收到错误它在机器人代码中?
-
是的,只是在我添加了这个包之后我才开始收到这个错误。
-
当你的内部异常说“查看内部异常以了解详细信息”时,看起来你可能必须沿着内部异常链一路走下去才能找到真正告诉你什么的那个问题是。
-
我检查了最里面的异常 ((System.TypeLoadException)ex.InnerException.InnerException.InnerException.InnerException.InnerException.InnerException).Message " 类型违反了继承安全规则:'System.Net. Http.WebRequestHandler'。派生类型必须与基类型的安全可访问性相匹配或难以访问。"
-
Interop 需要安装 PowerPoint,这在默认部署到 Azure 时是不可能的。但是,如果您自己托管机器人,比如说在虚拟机上,那么它可能会起作用。这可能取决于您实际在做什么。
标签: c# .net botframework openxml openxml-sdk