Windows 7中的编译器问题:GDI +中发生了一般错误

我们有一个应用程序需要在Windows 7环境中开始测试和开发。 它可以在VS2008的WinXP下正常编译,没问题。 然而,当我今天使用VS2008在Windows 7机器上编译它时,我收到以下错误:

Error 12 The "GenerateResource" task failed unexpectedly. System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+. at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(MemoryStream stream) at System.Drawing.Image.System.Runtime.Serialization.ISerializable.GetObjectData(SerializationInfo si, StreamingContext context) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph) at System.Resources.ResourceWriter.WriteValue(ResourceTypeCode typeCode, Object value, BinaryWriter writer, IFormatter objFormatter) at System.Resources.ResourceWriter.Generate() at System.Resources.ResourceWriter.Dispose(Boolean disposing) at System.Resources.ResourceWriter.Close() at Microsoft.Build.Tasks.ProcessResourceFiles.WriteResources(IResourceWriter writer) at Microsoft.Build.Tasks.ProcessResourceFiles.WriteResources(String filename) at Microsoft.Build.Tasks.ProcessResourceFiles.ProcessFile(String inFile, String outFile) at Microsoft.Build.Tasks.ProcessResourceFiles.Run(TaskLoggingHelper log, ITaskItem[] assemblyFilesList, List`1 inputs, List`1 outputs, Boolean sourcePath, String language, String namespacename, String resourcesNamespace, String filename, String classname, Boolean publicClass) at Microsoft.Build.Tasks.ProcessResourceFiles.Run(TaskLoggingHelper log, ITaskItem[] assemblyFilesList, List`1 inputs, List`1 outputs, Boolean sourcePath, String language, String namespacename, String resourcesNamespace, String filename, String classname, Boolean publicClass) at Microsoft.Build.Tasks.GenerateResource.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult) 

我不能为我的生活跑下去。 我访问过msdn论坛,发现这对许多人来说都是一个问题,但MS或其他任何人都没有提供一致的解决方案。

有人见过这个并修好过吗? 请指教是必要的!

谢谢

我使用命令行msbuild编译并确定了问题位置。

它是一个类中的resx文件,其中包含一个未使用的图像。 我删除了,一切都很好。 现在可以建立好。

经过数小时的故障排除后,我使用MSBUILD“我的解决方案文件路径”在VS 2010命令行提示符下打开并构建了项目。 这提供了一个更明显的构建事件序列,我发现我的项目在编译表单16之后就失败了。表单编译似乎按解决方案资源管理器中的对象顺序进行。 所以我检查了下一个表格,发现它包含一个图片框。 我也在那之后检查了表单,发现我无法打开设计器而没有错误(对象引用没有设置为对象的实例)。 显然,问题现在是双重的。

要解决我必须从我认为有问题的第一个表单中删除图片框对象(它没有被任何方式使用),因为它似乎已损坏。 我发现第二个带有null引用exception的表单是使用用户控件。 在调用InitializeComponent()之前,用户控件的构造函数的代码试图将对象传递给容器。 这创建了空引用,因为在调用有问题的代码时,容器没有在InitializeComponent中创建事件。

解决了上一段中的问题后,我的解决方案在Windows 7下编译。

我认为,如果我没有弄错的话,Windows 7有一个GDI更新。 也许这将解决问题。 您的解决方案是否在commsnd线上使用Msbuild构建?

您是否在应用中使用TIFF图像?

前段时间,我也遇到了TIFF图像的问题,这些报告不能在Win7 x64下编译,尽管它在Vista x86下编译成了一个魅力。 错误消息也涉及GDI +。 我以不同的格式(PNG)保存了图像,问题就消失了。

当时(2011年3月左右),我首先确保我的Windows是最新的,但它没有解决问题。 所以也许E​​rik会提到这样的更新,但当时并没有通过Windows Update来实现(也许它更新)。

从资源管理器中删除资源(右键单击每个资源并删除)然后重新添加它们。 对我来说它解决了这个问题。