未找到字段:升级到机器人框架 3.8.1 时 'Microsoft.Bot.Builder.Dialogs.Conversation.Container'
Field not found: 'Microsoft.Bot.Builder.Dialogs.Conversation.Container' when upgrading to bot framewotk 3.8.1
我们正在使用 Auth bot,在将 bot 框架升级到 3.8.1 后,我们在尝试登录我们的 bot 时遇到以下异常:
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Field not found: 'Microsoft.Bot.Builder.Dialogs.Conversation.Container'.
</ExceptionMessage>
<ExceptionType>System.MissingFieldException</ExceptionType>
<StackTrace>
at AuthBot.Controllers.OAuthCallbackController.<OAuthCallback>d__3.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine) at AuthBot.Controllers.OAuthCallbackController.OAuthCallback(String code, String state, CancellationToken cancellationToken) at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass12.<GetExecutor>b__8(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) --- 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.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext() --- 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.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() --- 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.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
</StackTrace>
</Error>
我猜应该有某个地方我们应该添加 Conversation.Container 但不确定在哪里。
这是我们的一些相关代码:
public class CustomModule : Module
{
/// <summary>
/// Allows adding custom registrations to the container builder.
/// In this case we are adding the CustomPostToUser registration.
/// </summary>
protected override void Load(ContainerBuilder builder)
{
Ensure.ArgIsNotNull(builder, nameof(builder));
builder.RegisterType<CustomPostToUser>().Keyed<IPostToBot>(typeof(CustomPostToUser)).InstancePerLifetimeScope();
builder.RegisterAdapterChain<IPostToBot>
(
typeof(EventLoopDialogTask),
typeof(SetAmbientThreadCulture),
typeof(PersistentDialogTask),
typeof(ExceptionTranslationDialogTask),
typeof(SerializeByConversation),
typeof(CustomPostToUser),
typeof(LogPostToBot)
)
.InstancePerLifetimeScope();
}
/// <summary>
/// Registers the given adapter chain to the container builder.
/// </summary>
public static IRegistrationBuilder<TLimit, SimpleActivatorData, SingleRegistrationStyle> RegisterAdapterChain<TLimit>(ContainerBuilder builder, params Type[] types)
{
Ensure.ArgIsNotNull(builder, nameof(builder));
return
builder
.Register(c =>
{
var service = default(TLimit);
return types.Aggregate(service, (current, t) => c.ResolveKeyed<TLimit>(t, TypedParameter.From(current)));
})
.As<TLimit>();
}
}
static MessagesController()
{
Conversation.UpdateContainer(builder =>
{
builder.RegisterType<MessageActivityLogger>().AsImplementedInterfaces().InstancePerDependency();
builder.RegisterModule(new ReflectionSurrogateModule());
builder.RegisterModule(new CustomModule());
});
}
找到解决方案,似乎是因为 authbot 库也需要更新才能使身份验证与新的 bot 框架版本一起工作。
我们正在使用 Auth bot,在将 bot 框架升级到 3.8.1 后,我们在尝试登录我们的 bot 时遇到以下异常:
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Field not found: 'Microsoft.Bot.Builder.Dialogs.Conversation.Container'.
</ExceptionMessage>
<ExceptionType>System.MissingFieldException</ExceptionType>
<StackTrace>
at AuthBot.Controllers.OAuthCallbackController.<OAuthCallback>d__3.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine) at AuthBot.Controllers.OAuthCallbackController.OAuthCallback(String code, String state, CancellationToken cancellationToken) at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass12.<GetExecutor>b__8(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) --- 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.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext() --- 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.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() --- 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.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
</StackTrace>
</Error>
我猜应该有某个地方我们应该添加 Conversation.Container 但不确定在哪里。
这是我们的一些相关代码:
public class CustomModule : Module
{
/// <summary>
/// Allows adding custom registrations to the container builder.
/// In this case we are adding the CustomPostToUser registration.
/// </summary>
protected override void Load(ContainerBuilder builder)
{
Ensure.ArgIsNotNull(builder, nameof(builder));
builder.RegisterType<CustomPostToUser>().Keyed<IPostToBot>(typeof(CustomPostToUser)).InstancePerLifetimeScope();
builder.RegisterAdapterChain<IPostToBot>
(
typeof(EventLoopDialogTask),
typeof(SetAmbientThreadCulture),
typeof(PersistentDialogTask),
typeof(ExceptionTranslationDialogTask),
typeof(SerializeByConversation),
typeof(CustomPostToUser),
typeof(LogPostToBot)
)
.InstancePerLifetimeScope();
}
/// <summary>
/// Registers the given adapter chain to the container builder.
/// </summary>
public static IRegistrationBuilder<TLimit, SimpleActivatorData, SingleRegistrationStyle> RegisterAdapterChain<TLimit>(ContainerBuilder builder, params Type[] types)
{
Ensure.ArgIsNotNull(builder, nameof(builder));
return
builder
.Register(c =>
{
var service = default(TLimit);
return types.Aggregate(service, (current, t) => c.ResolveKeyed<TLimit>(t, TypedParameter.From(current)));
})
.As<TLimit>();
}
}
static MessagesController()
{
Conversation.UpdateContainer(builder =>
{
builder.RegisterType<MessageActivityLogger>().AsImplementedInterfaces().InstancePerDependency();
builder.RegisterModule(new ReflectionSurrogateModule());
builder.RegisterModule(new CustomModule());
});
}
找到解决方案,似乎是因为 authbot 库也需要更新才能使身份验证与新的 bot 框架版本一起工作。