Wednesday, March 30, 2011

Index (zero based) must be greater than or equal to zero and less than the size of the argument list

Problem:
System.FormatException was unhandled by user code
  Message=Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
  Source=mscorlib
  StackTrace:
       at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
       at System.String.Format(IFormatProvider provider, String format, Object[] args)
       at System.String.Format(String format, Object arg0)
       at MultiThreadedDbSeeder.Program.<Main>b__0(Int32 i) in C:\xxxx\Program.cs:line 22
       at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.b__c()
  InnerException:

Offending Line:
SqlCommand cmd = new SqlCommand(string.Format(@"insert into table_1 (vch_value) values('{1}')", "the value of i is " + i));

Solution:
Don’t forget that string.Format uses a zero based index.
Fixed Code:
SqlCommand cmd = new SqlCommand(string.Format(@"insert into table_1 (vch_value) values('{0}')", "the value of i is " + i));

Tuesday, March 29, 2011

The project file has been moved, renamed or is not on your computer

Solution:
1) Close the solution you have open.
2) In the project folder which is giving you problems, find the .suo file and delete it.
3) Reopen your solution and add the project back.

Saturday, March 26, 2011

Quartz.ObjectAlreadyExistsException: Unable to store Job with name: '' and group: 'DEFAULT', because one already exists with this identification.

Problem:
Exception Caught: Quartz.ObjectAlreadyExistsException: Unable to store Job with name: 'updateMyStuff' and group: 'DEFAULT', because one already exists with this identification.


Code:
                 // construct job info for every 10 seconds
                JobDetail = jobDetail = new JobDetail("updateMyStuff", null, typeof(UpdateMyOneMethod));
                trig = new CronTrigger();
                trig.CronExpression = new CronExpression("0/10 * * * * ?");
                trig.Name = " updateStuff ";
                sched.ScheduleJob(jobDetail, trig);

                // job for every day 12:00 am
                jobDetail = new JobDetail("updateMyStuff", null, typeof(UpdateMyOtherMethod));
                trig = new CronTrigger();
                trig.CronExpression = new CronExpression("0 0 0 * * ?");
                trig.Name = "updateStuff";
                sched.ScheduleJob(jobDetail, trig);



Solution:
I was clearly very tired and not paying attention and made a miserable copy/paste error.  Make sure the JobDetail has a unique name and same with the trigger!  Fixed Code, changes bolded:

                 // construct job info for every 10 seconds
                JobDetail = jobDetail = new JobDetail("updateMyStuff", null, typeof(UpdateMyOneMethod));
                trig = new CronTrigger();
                trig.CronExpression = new CronExpression("0/10 * * * * ?");
                trig.Name = " updateStuff ";
                sched.ScheduleJob(jobDetail, trig);

                // job for every day 12:00 am
                jobDetail = new JobDetail("updateMyOtherStuff", null, typeof(UpdateMyOtherMethod));
                trig = new CronTrigger();
                trig.CronExpression = new CronExpression("0 0 0 * * ?");
                trig.Name = "updateOtherStuff";
                sched.ScheduleJob(jobDetail, trig);