Just trying to do a (I thought) simple callout to read a number from a text file stored on the CRM server, use it as one of the values on the CRM form, and increment the number and then rewrite it to the text file. When I load the form, the callout ostensibly does nothing and Event Viewer on the server gives me this unhelpful invalid cast error message. I've gone over the code and changed various things to no avail, but I'm brand new to both CRM callouts and C#, so I'm probably missing something dumb. Here's the code:
using System;
using System.IO;
using Microsoft.Crm.Callout;
namespace IncrementCompetitorNumber
{
public class Increment
{
public string IncrementNumber()
{
string ProjectAutoNumber = "D:\\CRM_Misc\\incrementers\\new_competitornumber.txt";
string AutoNumber = "0";
string ReturnThis = "0";
int i = 0;
lock(this)
{
TextReader tr = new StreamReader(ProjectAutoNumber);
AutoNumber = tr.ReadLine();
tr.Close();
ReturnThis = AutoNumber;
i = Convert.ToInt32(AutoNumber);
i++;
AutoNumber = i.ToString();
TextWriter tw = new StreamWriter(ProjectAutoNumber);
tw.WriteLine(AutoNumber);
tw.Close();
}
return ReturnThis;
}
}
}
So... anyone know what I'm doing wrong?