C# NET2中的资源有一个奇怪的问题

C# NET2中的资源有一个奇怪的问题,c#,resources,.net-2.0,C#,Resources,.net 2.0,在VS 2010 SP 1中,我为.Net Framework 2创建了WinForms应用程序。我尝试从资源中获取图标并将其分配给表单图标: this.Icon = global::tester.Properties.Resources.icon_gray; Icon resource Icon_gray.ico已从VS designer添加到我的开发人员PC Windows 7 x86中的Resources.resx中,其中包含.NET Framework 3.5 SP1和.NET 4 但

在VS 2010 SP 1中,我为.Net Framework 2创建了WinForms应用程序。我尝试从资源中获取图标并将其分配给表单图标:

this.Icon = global::tester.Properties.Resources.icon_gray;
Icon resource Icon_gray.ico已从VS designer添加到我的开发人员PC Windows 7 x86中的Resources.resx中,其中包含.NET Framework 3.5 SP1和.NET 4

但在仅使用.NET Framework 2 SP 2的Windows XP SP 3中出现以下错误

错误

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ComponentModel.Win32Exception: Параметр задан неверно
   at System.Drawing.Icon.Initialize(Int32 width, Int32 height)
   at System.Drawing.Icon..ctor(SerializationInfo info, StreamingContext context)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)
   at System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object target, SerializationInfo info, StreamingContext context)
   at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)
   at System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder)
   at System.Runtime.Serialization.ObjectManager.DoFixups()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Resources.ResourceReader.DeserializeObject(Int32 typeIndex)
   at System.Resources.ResourceReader.LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode)
   at System.Resources.ResourceReader.LoadObject(Int32 pos, ResourceTypeCode& typeCode)
   at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase, Boolean isString)
   at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase)
   at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)
   at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture)
   at tester.Properties.Resources.get_icon_gray()
   at tester.Form1.button1_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
如何解决这个问题? 编辑: 使用png:

pictureBox1.Image = global::tester.Properties.Resources.icon_gray1;

一切正常

对于遇到此问题的用户,请确保检查“项目属性”窗口中的图标以及所有表单中的图标属性。它们都必须是32x32才能在Windows XP中工作。

请翻译俄文信息您的图标分辨率是多少?“参数不正确”错误是指错误的参数被传递到
系统.Drawing.Icon.Initialize中,并且图标无法加载/解决。我不知道真正的答案,但问题很可能是不同的*.ico文件处理XP和后XP Windows系统。尝试用*.png文件复制相同的问题。如果它起作用,那么问题确实是ICO处理。查看详细信息。@Migol:图标的分辨率为32x32。在我的开发者PC上,一切都很好,正如你在问题中提到的,这个问题只发生在Windows XP上。我只能猜测,因为我没有XP机器来检查这种行为。但是,如果能用PNG文件重现这个问题,那将是一件有趣的事情。