What would cause a simple .NET console application to fail under Windows XP?
I've written a simple .NET console application. How simple? This simple:
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.Error.WriteLine("Returns a date some number of days in the future or past.");
Console.Error.WriteLine();
Console.Error.WriteLine("GETDATE days [format]");
Console.Error.WriteLine("");
Console.Error.WriteLine(" days Specifies the number of days (defaults to 0, may be negative).");
Console.Error.WriteLine(" format .NET format 开发者_运维知识库string for output, (defaults to \"MM-dd-yyyy\").");
return;
}
string number = (args[0]);
string format = (args.Length > 1)
? args[2]
: "MM-dd-yyyy";
int days;
if (!int.TryParse(number, out days))
{
Console.Error.WriteLine("Can't parse {0} into an integer.", days);
return;
}
DateTime d = DateTime.Now + new TimeSpan(days, 0, 0, 0);
try
{
string result = d.ToString(format);
Console.Out.Write(result);
}
catch (FormatException)
{
Console.Error.Write("{0} is not a valid format.", format);
}
}
}
I've made a release build of this against the .NET 2.0 framework and given the executable to one of my customers. When he runs it in a command window on his XP machine (or his Windows 2008 server), he gets a (DOS) out of memory error.
I'm racking my brains to figure out how what I could possibly be doing wrong. I of course don't have an XP environment of my own to test, so I can't replicate this problem. Any ideas?
One idea: Maybe your customer haven't got .NET Framework installed.
Can you try a Virtual Machine to create the XP? (Virtual Box etc)
I have seen on a couple of machines a corrupted Machine.config from some Windows Updates, but I think that just makes .NET error on the machine, not an Outofmemory error.
Can you try using a .NET Windows forms app that just presents a Basic window, chuck a Textbox, a Button and when you click the button, put the current Date/Time into the textbox just to eliminate environment errors.
I know it's not that helpful, but if you are just adding Days to the Date, you can just use DateTime.Now.AddDays(days)
Are you giving him a 64-bit executable to run on a 32-bit operating system? That won't work...
精彩评论