什么会导致简单的 .NET 控制台应用程序在 Windows XP 下失败?
我编写了一个简单的.NET 控制台应用程序。有多简单?很简单:
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);
}
}
}
我针对 .NET 2.0 框架制作了一个发行版,并将可执行文件提供给我的一位客户。当他在 XP 计算机(或 Windows 2008 服务器)上的命令窗口中运行它时,他收到 (DOS) 内存不足错误。
我绞尽脑汁想弄清楚我可能做错了什么。我当然没有自己的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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种想法:也许您的客户尚未安装 .NET Framework。
One idea: Maybe your customer haven't got .NET Framework installed.
您可以尝试使用虚拟机来创建 XP 吗? (虚拟盒等)
我在几台机器上看到一些 Windows 更新导致 Machine.config 损坏,但我认为这只会在机器上产生 .NET 错误,而不是内存不足错误。
您可以尝试使用仅显示一个基本窗口、一个文本框、一个按钮的 .NET Windows 窗体应用程序,然后在单击按钮时将当前日期/时间放入文本框中以消除环境错误。
我知道这没有那么有用,但如果您只是在日期中添加天数,则可以使用 DateTime.Now.AddDays(days)
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)
您是否为他提供了在 32 位操作系统上运行的 64 位可执行文件?那不行...
Are you giving him a 64-bit executable to run on a 32-bit operating system? That won't work...