botframework-sdk: Buffer cannot be null. Parameter name: buffer
Bot Info
- SDK Platform: .NET
- SDK Version: 3.13.1
- Active Channels: Skype, MS Teams, Slack, Skype for Business, WebChat, Emulator
- Deployment Environment: Azure Bot Service, Azure App Service and local development & testing with Emulator and ngrok.
Issue Description
Getting ArgumentNullException
with the following message, Buffer cannot be null. Parameter name: buffer
. ParamName: “buffer”, Source: “mscorlib”
The following is the stack trace,
at System.IO.MemoryStream..ctor(Byte[] buffer, Boolean writable)
at System.IO.MemoryStream..ctor(Byte[] buffer)
at Microsoft.Bot.Builder.Azure.BotDataEntity.Deserialize(Byte[] bytes)
at Microsoft.Bot.Builder.Azure.TableBotDataStore.<Microsoft-Bot-Builder-Dialogs-Internals-IBotDataStore<Microsoft-Bot-Connector-BotData>-LoadAsync>d__8.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 Microsoft.Bot.Builder.Dialogs.Internals.CachingBotDataStore.<LoadFromInnerAndCache>d__8.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 Microsoft.Bot.Builder.Dialogs.Internals.CachingBotDataStore.<Microsoft-Bot-Builder-Dialogs-Internals-IBotDataStore<Microsoft-Bot-Connector-BotData>-LoadAsync>d__6.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.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at AppName.Filters.RefreshTokenFilter.<OnActionExecutingAsync>d__0.MoveNext() in D:\TFS\Source\Workspaces\TP_APPNAME\Development\Source\Dev_AppName_Version1\FolderName\AppName\Filters\RefreshTokenFilter.cs:line 49
Everything was working fine and we didn’t change anything in our code but this issue started showing up from 2/8/2018. We are using Azure Table Storage by following this article here
Code Example
The following statement is throwing the exception
var userData = await botDataStore.LoadAsync(key, BotStoreType.BotUserData, CancellationToken.None);
Registering the Azure Table Storage
Conversation.UpdateContainer(builder =>
{
builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
// Bot Storage: register state storage for your bot
var connectionString = ConfigurationManager.ConnectionStrings[Constants.Database.BotStorageConnectionString].ConnectionString;
var store = new TableBotDataStore(connectionString);
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
});
The code that throws the exception,
public class RefreshTokenFilter : ActionFilterAttribute
{
public async override Task OnActionExecutingAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
{
try
{
object activity;
actionContext.ActionArguments.TryGetValue(Constants.MessagesAndOptions.Activity, out activity);
IMessageActivity message = activity as IMessageActivity;
if (message != null &&
message.Text != null &&
message.Type == ActivityTypes.Message &&
!Constants.MessagesAndOptions.BotResetCommand.Contains(message.Text.ToLower()))
{
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
{
var botDataStore = scope.Resolve<IBotDataStore<BotData>>();
var key = new AddressKey
{
BotId = message.Recipient.Id,
ChannelId = message.ChannelId,
UserId = message.From.Id,
ConversationId = message.Conversation.Id,
ServiceUrl = message.ServiceUrl
};
var userData = await botDataStore.LoadAsync(key, BotStoreType.BotUserData, CancellationToken.None); // problem occurs here
// ... code omitted for brevity
}
}
}
catch (HttpOperationException ex)
{
// error handling due to concurrency issues (another instance of the bot has changed the data)
ErrorSignal.FromCurrentContext().Raise(ex);
}
catch (Exception ex)
{
ErrorSignal.FromCurrentContext().Raise(ex);
}
await base.OnActionExecutingAsync(actionContext, cancellationToken);
}
}
Reproduction Steps
Expected Behavior
Exception shouldn’t occur and the user data should load properly.
Actual Results
Buffer cannot be null. Parameter name: buffer
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 22 (6 by maintainers)
Same problem here. Could not get it to work with latest version, even after deleting the table. I’ve noticed that the first message works but after that it keeps getting the “Buffer cannot be null” error".
Downgrading to version 8.7 and deleting the table seems to solve the problem.
As far as I can see the problem is related to column names casing. WindowsAzure.Storage 9.0 creates camel cased columns (botId, channelId, conversationId, data, userId) whereas previous versions use Pascal Case (BotId, ChannelId, ConversationId, Data, UserId). I could not get version 9 working with Bot Framework, even after deleting botdata table.
Maybe this additional info helps with your trouble shooting. I ran into this issue when I finally migrated my bot from the non-production legacy storage to use Azure Table Storage.
My steps were:
@EricDahlvang
Steps taken
Continuing to test 6. Updated Autofac to v4.6.2 (Successful run). 7. Updated WindowsAzure.Storage to v9.0.0 (FAILED with Bad Request)
Additional note: downgrading WindowsAzure.Storage to 8.7, 8.6 and 8.5 continues to fail upon running.
Additional note 2: Blew away table, started at WindowsAzure.Storage v8.5, stepped thru updates. All worked fine, until updating to v9.0.0, and got Bad Request error again.