Hangfire.MySqlStorage
Hangfire.MySqlStorage copied to clipboard
Index was outside the bounds of the array.
I'm getting Index was outside the bounds of the array error
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Hangfire.MySql.MySqlStorage.<>c.<ToString>b__14_1(String[] x)
at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable
1 source, Func2 keySelector, Func
2 elementSelector, IEqualityComparer`1 comparer)
at Hangfire.MySql.MySqlStorage.ToString()
I'm using ASP.NET MVC .NET Framework, below is my code in Global.asax.cs
public class MvcApplication : System.Web.HttpApplication
{
private IEnumerable<IDisposable> GetHangfireServers ()
{
GlobalConfiguration.Configuration.UseStorage(
new MySqlStorage(
ConfigurationManager.ConnectionStrings["hangfireDBConnString"].ToString(),
new MySqlStorageOptions
{
TransactionIsolationLevel = IsolationLevel.ReadCommitted,
QueuePollInterval = TimeSpan.FromSeconds(15),
JobExpirationCheckInterval = TimeSpan.FromHours(1),
CountersAggregateInterval = TimeSpan.FromMinutes(5),
PrepareSchemaIfNecessary = true,
DashboardJobListLimit = 50000,
TransactionTimeout = TimeSpan.FromMinutes(1),
TablesPrefix = "hangfire"
}));
yield return new BackgroundJobServer();
}
protected void Application_Start ()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
HangfireAspNet.Use(GetHangfireServers);
UnityConfig.RegisterComponents();
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
// Let's also create a sample background job
//BackgroundJob.Enqueue(() => Debug.WriteLine("Hello world from Hangfire!"));
}
}
public class HangFireBackgroundService
{
private BackgroundJobServer server;
public bool Start ()
{
this.server = new BackgroundJobServer();
return true;
}
public bool Stop ()
{
this.server.Dispose();
return true;
}
}
Did you solved this problem? @micro9000
Did you solved this problem? @micro9000
No, I decided not to use Hangfire on my ASP.NET MVC project, I have no idea why I'm getting this error, but even I have this error, it works for simple task But I'm using Unity for DI, I can't use Hangfire properly.
I got this error
fail: Hangfire.MySql.MySqlStorage[0]
Index was outside the bounds of the array.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Hangfire.MySql.MySqlStorage.<>c.<ToString>b__14_1(String[] x)
at System.Linq.Utilities.<>c__DisplayClass2_0'3.<CombineSelectors>b__0(TSource x)
at System.Linq.Enumerable.SelectArrayIterator'2.MoveNext()
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable'1 source, Func'2 keySelector, Func'2 elementSelector, IEqualityComparer'1 comparer)
at Hangfire.MySql.MySqlStorage.ToString()
It because you have semicolon (;) in your password or your password is empty but you include it in Connection String
I get the same error, and my password is NOT empty and doesn't have a semicolon in it.
I do further get the error: "Connection string can not be parsed".
Oddly, it works as expected, but these errors bother me.
@samcov I had this problem as well, everything works but throws these errors.
I got it fixed simply by editing the connection string's password from password=
to password=''
, notice two single quotation marks. So similarly people should probably use password='hunter2'
instead of password=hunter2
. Doesn't matter if the password is at the end of the string or in the middle somewhere. So the whole string that works for me is:
"HangfireConnection": "Server=localhost;Database=hangdb;Allow User Variables=true;user=root;password='';port=3306"
I believe that connection string gets parsed somewhere without all variations.
Hope this helps for anyone else searching for the answer too!
I get the same error,Later on, I found out that there was a space at the end of my connection statement "Database=hncore;Data Source=localhost;Port=3306;User Id=root;Password=123456;Charset=utf8;TreatTinyAsBoolean=false;AllowLoadLocalInfile=true;Allow User Variables=True; " yes, I Modify to "Database=hncore;Data Source=localhost;Port=3306;User Id=root;Password=123456;Charset=utf8;TreatTinyAsBoolean=false;AllowLoadLocalInfile=true;Allow User Variables=True;"
Pay attention to the last blank space, you can't see it
all fine