2

I get the error

Error   142 The "GenerateResource" task failed unexpectedly.
System.Runtime.InteropServices.ExternalException (0x80004005): Common error in GDI+.
   bei System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
   bei System.Drawing.Image.Save(MemoryStream stream)
   bei System.Drawing.Image.System.Runtime.Serialization.ISerializable.GetObjectData(SerializationInfo si, StreamingContext context)
   bei System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
   bei System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
   bei System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
   bei System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
   bei System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   bei System.Resources.ResourceWriter.WriteValue(ResourceTypeCode typeCode, Object value, BinaryWriter writer, IFormatter objFormatter)
   bei System.Resources.ResourceWriter.Generate()
   bei System.Resources.ResourceWriter.Dispose(Boolean disposing)
   bei System.Resources.ResourceWriter.Close()
   bei Microsoft.Build.Tasks.ProcessResourceFiles.WriteResources(ReaderInfo reader, IResourceWriter writer)
   bei Microsoft.Build.Tasks.ProcessResourceFiles.WriteResources(ReaderInfo reader, String filename)
   bei Microsoft.Build.Tasks.ProcessResourceFiles.ProcessFile(String inFile, String outFileOrDir)
   bei 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, Boolean extractingResWFiles, String resWOutputDirectory)
   bei 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, Boolean extractingResWFiles, String resWOutputDirectory)
   bei Microsoft.Build.Tasks.GenerateResource.Execute()
   bei Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   bei Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext()    prjMyProject

I have spent 2 days with this error now, removing forms and classes from my project, and even all interop types. Nothing helped.

Does anybody have any idea how I could track this error?

I tried ProcMon, but I did not see anything that would help me (well, I don't know what to look for, that's what makes it even harder).

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
tmighty
  • 10,734
  • 21
  • 104
  • 218
  • 1
    The error is coming from an image in a RESX file. – SLaks Mar 18 '14 at 21:16
  • @SLaks I have open each .resX file in the IDE and had a look if any image looks strange or is not displayed. Do you have any idea how to narrow down my search somehow? – tmighty Mar 18 '14 at 21:28
  • 1
    Do you have an embedded image on a form that might be corrupt? Can you open all of your forms in the designer without getting an error? See: http://stackoverflow.com/q/7017731/880990. – Olivier Jacot-Descombes Mar 18 '14 at 21:32
  • @OlivierJacot-Descombes Oh man, I opened up 200 forms, and finally I found a form that I could not open. I did not change this form for over a year, so I was sure I did not change anything about it, so it could not be the problem. However, I really could not open it. The IDE complained about a missing picturebox or so. Strange. Can you make your reply the answer? – tmighty Mar 18 '14 at 21:42
  • @OlivierJacot-Descombes Hmmm, after having compiled successfully once, I get the same error again. – tmighty Mar 18 '14 at 22:15
  • Now all my forms open up without an error, and I still have the problem. – tmighty Mar 18 '14 at 22:16

2 Answers2

2

Do you have an embedded image on a form that might be corrupt?

Can you open all of your forms and user controls in the designer without getting an error?

See: Compiler Issue in Windows 7: A generic error occurred in GDI+.

Community
  • 1
  • 1
Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
  • Please see my other comments. Unfortunately, after having compiled successfully once, I still have the same problem. All my forms open up fine. – tmighty Mar 18 '14 at 22:17
  • Thank you! I ran MSBUILD from the VSTools start menu, and it listed the files that are being processed. After one form, an error was shown in red. That was the faulty form. It showed a background image, but when I tried to change it in the IDE, the "GDI+ error" messagebox was shown within the VS2012 IDE. – tmighty Mar 18 '14 at 22:25
  • `UserControls` and all other items having a RESX file attached can be the source of the problem. – Olivier Jacot-Descombes Mar 18 '14 at 22:25
  • Hmmm, I have to take my acceptance back unfortunately. At first it built fine, but then the same problem occured. MSBUILD works fine without any errors, but in the IDE, the compiler throws the same error again. :( – tmighty Mar 18 '14 at 22:41
  • LOL, now even my search field disappears in the IDE if no occurance is found. Jeeeeees. – tmighty Mar 18 '14 at 22:51
  • Okay, problem resolved. I remade several form with old images (jpg and bmp, I use only PNG know), and then the problem was gone. I could not really see any error, I just redid the images. However, it is really frightening to know that a project can go that berzerk. – tmighty Mar 19 '14 at 00:16
  • Maybe the the problem is that the Windows image decoder versions changed and that some old images became incompatible. GDI+ relies on the decoders installed in the Windows OS. – Olivier Jacot-Descombes Mar 19 '14 at 13:46
  • 1
    The way I fixed it, was going though all the windows that had some embedded image, one by one. Then I found the "offender", the designer crashed while opening it. I just had to delete the references to this image on the designer.cs and voila! – coloboxp Sep 25 '14 at 07:54
  • Just run MSBUILD from the VSTools start menu (just like tmighty said), and look for red messages, the filename before the red message is the form that you would edit it's resx file. cut the images shown in the resx file and paste them again at the same place then save the file. Run again the MSBUILD until there is no error (red messages). It worked for me. – Noldy Nayoan Oct 05 '19 at 07:39
0

The way I fixed it, was going though all the windows that had some embedded image, one by one. Then I found the "offender", the designer crashed while opening it.

I just had to delete the references to this image on the designer.cs and voila!

coloboxp
  • 494
  • 8
  • 15