设置图像时参数无效

pro*_*ach 5 c# exception-handling image .net-2.0 winforms

我在许多计算机上运行.NET 2.0程序.在一个我有重复发生此错误,直到我重置应用程序.

 //line below was throwing the exception
 this.myButton.BackgroundImage = global::myNamespace.Properties.Resources.myImage;
Run Code Online (Sandbox Code Playgroud)

例外:

 ExceptionType: ArgumentException
 Message: Parameter is not valid.
 Source: System.Drawing
 StackTrace:    at System.Drawing.Image.get_Flags()
     at System.Windows.Forms.ControlPaint.IsImageTransparent(Image backgroundImage)
      at System.Windows.Forms.Control.set_BackgroundImageLayout(ImageLayout value)
Run Code Online (Sandbox Code Playgroud)

资源存在,重置后工作正常.任何人都可以提供任何有关可能发生的见解吗?

Pol*_*fun 1

我建议您使用进程监视器来检查文件的实时活动,以及哪些进程可能正在锁定它。添加一个过滤器,其中路径是图像/资源文件的名称;这应该很快就能显示出是否有任何东西在背后对文件进行胡闹。