Home » C++ ProgrammingRSS

error MSB4018: The "GenerateResource" task failed unexpectedly

I have a Smart Device application that is generating the following errror when I attempt to build.  I would appreciate any feedback in how to debug this error, or what might be a typical cause of this problem. 

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018: The "GenerateResource" task failed unexpectedly.

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018: at Microsoft.Build.Shared.ExceptionHandling.RethrowUnlessFileIO(Exception e)

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018: at Microsoft.Build.Tasks.GenerateResource.NeedSeparateAppDomain()

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018: at Microsoft.Build.Tasks.GenerateResource.Execute()

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018: at Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode howToExecuteTask, Hashtable projectItemsAvailableToTask, BuildPropertyGroup projectPropertiesAvailableToTask, Boolean& taskClassWasFound)

Done building project "PromoScan.vbproj" -- FAILED.

 

53 Answers Found

 

Answer 1

Hi,

I have the same error  message, it is generate after a conversion from a Visual Studio 2003 SmartDevice Project to a VS 2005 SmartDevice Project.

The conversion works fine, the first build  to, but before the second build i want to open a form with the designer and after i attempt  to build and i get this error...

Bye.

 

Answer 2

That is intersting.  I had converted this some of the projects in this solution from VS 2003, but it was quite a while ago.  I had been able to build  a release after the conversion and only now (some months later) have I intermittently encountered this error.

By any chance were you working with an Image Box conrol in your converted solution?

 

Answer 3

I don't use ImageBox Control in my solution. I've retest the conversion and befor open the Designer for my form i look in the InitializeComponent() method. and i find this :

this.BackColor = System.Drawing.Color.White;

this.ClientSize = ((System.Drawing.Size)(resources.GetObject("$this.ClientSize")));

this.ControlBox = false;

this.Controls.Add(this.labelMessage);

this.Controls.Add(this.buttonQuitter);

this.Controls.Add(this.buttonContinuer);

this.Enabled = ((bool)(resources.GetObject("$this.Enabled")));

this.Font = ((System.Drawing.Font)(resources.GetObject("$this.Font")));

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

this.Location = ((System.Drawing.Point)(resources.GetObject("$this.Location")));

this.MaximizeBox = false;

this.MinimizeBox = false;

this.Text = resources.GetString("$this.Text");

this.Visible = ((bool)(resources.GetObject("$this.Visible")));

this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

this.Click += new System.EventHandler(this.FormInitialisation_Click);

this.Load += new System.EventHandler(this.FormInitialisation_Load);

After opening designer i have this :

//

// FormInitialisation

//

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;

resources.ApplyResources(this, "$this");

this.BackColor = System.Drawing.Color.White;

this.ControlBox = false;

this.Controls.Add(this.labelMessage);

this.Controls.Add(this.buttonQuitter);

this.Controls.Add(this.buttonContinuer);

this.MaximizeBox = false;

this.MinimizeBox = false;

this.Name = "FormInitialisation";

this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

this.Click += new System.EventHandler(this.FormInitialisation_Click);

this.Load += new System.EventHandler(this.FormInitialisation_Load);

this.ResumeLayout(false);

Some properties have disapear... and during the opening some popup appears to say that it is impossible to generate the code for Text or Visible Properties....

So strange.

 

Answer 4

I'm working with Windows 2000 sp4 is it this the origin of the matter?
 

Answer 5

The development box I am using is Win Xp Sp 2
 

Answer 6

the problem  don't come from the OS. I asked the question to a MVP and he answer that he have the same problem. He said that we do to redraw all our form.... for the moment we don't find an other solution...
 

Answer 7

I am getting this error  also.  We migrated a VS 2003 vb.net compact framework to VS 2005 and then converted it from cf 1.0 to cf 2.0.  I checked everything in last friday to team foundation server and it was fine.  I tried to rebuild the solution this morning and started getting this error.  I have 23 projects in my solution with over 50 forms.  I am not going to redraw every form.  Is that solution a joke?  Does anyone have a real solution or is microsoft  still working on this problem?

Robert

 

Answer 8

I've send a feedback  to MS and my MVP contact to. I think that the redraw form is not a joke a soon as MS doesn't provide solution....

I'm happy to see that i'm not alone with this problem  :p

 

Answer 9

I find the same error  when I added a resource file in VS8/Mobile 5 project  properties.  The problem  is not associated with either the O/S or the conversion from an earlier VS project.

Create a new project (C# console application/Mobile 5 platform) and build  the empty project--ok, this builds fine.  Then go to the resources tab of the project properties and add a new resource.  The project still builds ok with an empty resource added.

Next add a binary file resource (following the directions in Help for adding a new resource).  Ok, once the resource is added it can be viewed by opening in the binary editor.  Now try to build the project and it fails with the MSB4018 errors.

Go back to the solution view and right click on the resource, and delete it.  Voila, the project builds just fine without the resource.  This is a problem in the VS8 release that needs fixing NOW!

 

Answer 10

i think that the error  will generated by many way. Because i don't add ressource to my project  file with the IDE. My Ressource are comming from RESX file added to project or resx file generated with a form.

With your answer, we know now that the problem  come from the ressource gestion.

Hey MS you Need to read it and fix it!!! we have buy your release and have some project to drive!!!!

I posted the problems on the msdn feedback....

 

Answer 11

Hi Jim,

We've had a few reports of this problem  and we want to fix it. We believe it's probably a bug in the .NET framework, but we can't find it through inspecting their code. We can't progress further without a repro case in-house.

If anyone with this issue can zip up a solution that has this problem, that would be most helpful. I realize in many cases your code is confidential, but very often it's possible to pare down the code to the absolute minimum that still produces the issue, which hopefully doesn't include anything proprietary of yours.

Ideally, you could attach it to the existing feedback  report on the product feedback center, or if that doesn't work, send the zip to msbuild@microsoft.com. Once we have a way to repro ourselves, we should be able to figure this out.

Thanks

Dan

'this posting provided as-is, with no warranties'

 

Answer 12

I get this issue every couple of builds on a clean VS2005 Win Mobile project.

Did you get a zip of a solution, or are you still waiting for one  ?

If I shut down and restart VS then the problem  goes away for a while, until I play with a form, then it comes back ( well most of the time anyway )

I can mail my solution if it will help !

 

Answer 13

I have found that I get this error  every time I remove and add a resource.  I am working on a dll that I use with my project  and every time I remove the old dll and add the new one I have to close the dev environment and open again to get rid of the error.

Full Description is:

The "GenerateResource" task  failed unexpectedly.  System.InvalidOperationException:  Collection was modified;  enumeration  may not execute.  at Microsoft.Build.Shared.ExceptionHandling.RethrowUnlessFileIO(Exception e)  at Microsoft.Build.Tasks.GenerateResource.NeedSeparateAppDomain()  at Microsoft.Build.Taks.GenerateResource.Execute()  at Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode how ToExecute Task, Hashtable projectItemsAvailable To Task, BuildPropertyGroup projectPropertiesAvailableToTask, Boolean&taskClassWasFound)

Hope that helps

 

Answer 14

Hi,

We know this problem  and we are tracking this as an issue that needs fixing. In the mean time can you try this workaround and tell us if it resolves the problem for you?

Edit your project  file and add this to the first PropertyGroup:

<GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>

That should get rid of this error. Tell us what you find.

Faisal Mohamood | Program Manager | Visual Studio - MSBuild

 

Answer 15

Faisal,

u r a champion.It works for me.

Thanks very much.

Cheers

Chandra

 

Answer 16

Faisal,

thanks for the work around, it got rid of the error  when removing and adding a dll.

Matt

 

Answer 17

Faisal,

You  are my hero!!!!

 

Answer 18

I had exactly the same error  message here, but our workaround was a little different. We used a (24 bit) PNG picture for a splash screen for our application, and the error started occurring. After replacing it with a GIF the error seemed to dissapear.
 

Answer 19

I recently ported a project  from .NET CF 1.0 to .NET CF 2.0.  Now, any time I update a resource file I get this error.  I just received a new set of updated graphics to be loaded into existing picture box controls on some forms used in my ported project.  So, as a work-around, I  have been diffing the before and after resource and CS files for the the forms that have been affected, and then manually editing both to minimize changes generated by for form editor.

Here is a diff with the graphics blob removed:

  <?xml version="1.0" encoding="utf-8"?>
   <root>
     <!--
       microsoft  ResX Schema

<      Version 1.0
->     Version 2.0

       The primary goals of this format is to allow a simple XML format
       that is mostly human readable. The generation and parsing of the
       various data types are done through the TypeConverter classes
       associated with the data types.

       Example:

       ... ado.net/XML headers & schema ...
       <resheader name="resmimetype">text/microsoft-resx</resheader>
<      <resheader name="version">1.0</resheader>
->     <resheader name="version">2.0</resheader>
       <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
       <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<      <data name="Name1">this is my long string</data>
->     <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
       <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
       <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<          [base64 mime encoded serialized .NET Framework object]
->         <value>[base64 mime encoded serialized .NET Framework object]</value>
       </data>
       <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<          [base64 mime encoded string representing a byte array form of the .NET Framework object]
->         <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
->         <comment>This is a comment</comment>
       </data>

       There are any number of "resheader" rows that contain simple
       name/value pairs.

       Each data row contains a name, and value. The row also contains a
       type or mimetype. Type corresponds to a .NET class that support
       text/value conversion through the TypeConverter architecture.
       Classes that don't support this are serialized and stored with the
       mimetype set.

<      The mimetype is used forserialized objects, and tells the
->     The mimetype is used for serialized objects, and tells the
       ResXResourceReader how to depersist the object. This is currently not
       extensible. For a given mimetype the value must be set accordingly:

       Note - application/x-microsoft.net.object.binary.base64 is the format
       that the ResXResourceWriter will generate, however the reader can
       read any of the formats listed below.

       mimetype: application/x-microsoft.net.object.binary.base64
       value   : The object must be serialized with
<              : System.Serialization.Formatters.Binary.BinaryFormatter
->             : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
               : and then encoded with base64 encoding.

       mimetype: application/x-microsoft.net.object.soap.base64
       value   : The object must be serialized with
               : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
               : and then encoded with base64 encoding.

       mimetype: application/x-microsoft.net.object.bytearray.base64
       value   : The object must be serialized into a byte array
               : using a System.ComponentModel.TypeConverter
               : and then encoded with base64 encoding.
       -->
     <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
->     <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
       <xsd:element name="root" msdata:IsDataSet="true">
         <xsd:complexType>
           <xsd:choice maxOccurs="unbounded">
->           <xsd:element name="metadata">
->             <xsd:complexType>
->               <xsd:sequence>
->                 <xsd:element name="value" type="xsd:string" minOccurs="0" />
->               </xsd:sequence>
->               <xsd:attribute name="name" use="required" type="xsd:string" />
->               <xsd:attribute name="type" type="xsd:string" />
->               <xsd:attribute name="mimetype" type="xsd:string" />
->               <xsd:attribute ref="xml:space" />
->             </xsd:complexType>
->           </xsd:element>
->           <xsd:element name="assembly">
->             <xsd:complexType>
->               <xsd:attribute name="alias" type="xsd:string" />
->               <xsd:attribute name="name" type="xsd:string" />
->             </xsd:complexType>
->           </xsd:element>
             <xsd:element name="data">
               <xsd:complexType>
                 <xsd:sequence>
                   <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                   <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
                 </xsd:sequence>
<                <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
->               <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
                 <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
                 <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
->               <xsd:attribute ref="xml:space" />
               </xsd:complexType>
             </xsd:element>
             <xsd:element name="resheader">
               <xsd:complexType>
                 <xsd:sequence>
                   <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                 </xsd:sequence>
                 <xsd:attribute name="name" type="xsd:string" use="required" />
               </xsd:complexType>
             </xsd:element>
           </xsd:choice>
         </xsd:complexType>
       </xsd:element>
     </xsd:schema>
     <resheader name="resmimetype">
       <value>text/microsoft-resx</value>
     </resheader>
     <resheader name="version">
<      <value>1.0</value>
->     <value>2.0</value>
     </resheader>
     <resheader name="reader">
<      <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
->     <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
     </resheader>
     <resheader name="writer">
<      <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
->     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
     </resheader>
<    <data name="mainMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
->   <metadata name="mainMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
       <value>17, 17</value>
<    </data>
<    <data name="pictureBox.Image" type="System.Drawing.Bitmap, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" mimetype="application/x-microsoft.net.object.bytearray.base64">
->   </metadata>
->   <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
->   <data name="pictureBox.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
       <value>

   </value>
     </data>
<    <data name="$this.FormFactorShadowProperty">
<      <value xml:space="preserve">SMARTPHONE_2003_QVGA</value>
<    </data>
<    <data name="$this.Skin" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
->   <metadata name="$this.FormFactorShadowProperty" xml:space="preserve">
->     <value>Smartphone QVGA</value>
->   </metadata>
->   <metadata name="$this.Skin" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
       <value>True</value>
<    </data>
->   </metadata>
->   <metadata name="$this.UndoSkinCounterProperty" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
->     <value>1</value>
->   </metadata>
->   <metadata name="$this.FormFactor" xml:space="preserve">
->     <value>Smartphone QVGA</value>
->   </metadata>
   </root>

 

Answer 20

Michael,

Does the workaround from Faisal earlier in this thread fix it?

Dan

 

Answer 21

 Super Solution !!!

We have Win Mobile5/Phone as the target platforms and are writing apps from scratch, and this was really starting to become a pain in the A***.

Since I put this little gem in place, I can hack anywhere in the code, add and remove/update forms etc, with all sorts of controls and third party components in them, and I've not had a lock out for a week now !

Thanks very much !!

 

Answer 22

It doesn't work.

I'm trying to modify my project  file with CTRL+O in visual studio 2005 team edition

I put <GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>

in first property group but text become underlined with waveline and message for error  was => invalid child element "GenerateResourceNeverLockTypeAssemblies"

I'm still trying to fix my project.

Please help me!

 

Answer 23

HI again

I found solution

Just start framework instalation and select "REPAIR"

after this my problems disapear

 

Answer 24

Putting <GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies> in the first group was a god send.  Thanks.  It didn't lower my working set memory usage, but dropped my total app domains from over 50 to 18.  My ide hasn't run this good in weeks.

For those who don't know to modify the project  file, open the vbproj with a text editor.

 

Answer 25

Adding an entry in the project  file didn't work for me but this did...

Control Panel => Add/Remove Programs => Click on Remove Framework button => Repair => Reboot.
 

Answer 26

You can ignore the "invalid child element" wavy line.
 

Answer 27

This worked, would love to know what is really causingthe issue...

 

Answer 28

I'm adding code to fix these problems, but there's several variations and I can't verify for sure that they're all fixed without good reproes in-house. If anyone posting on this issue can reduce their projects down to the minimum that reproduces the problem  (without the GenerateResourceNeverLockTypeAssemblies workaround), please zip it up and send it to MSBUILD@MICROSOFT.COM. I'll use it to verify my fix, and to create an automated test to prevent it ever regressing. This is your and our best assurance that we don't ship this same bug in MSBuild Orcas.
Thank you in advance,
Dan (MSBuild team)
 

Answer 29

Hi Faisal, thank you for the workaround.

I have tried to repair the .Net Framework, as suggested in other msgs but at no avail. I have added the element as you suggested in the first group of a .csproj and it worked (at least VS2005 has survived several rebuilds without producing the annoying MBS4018). I'm working with Motorola SMDK 1.3 for .Net, Visual Studio 2005 Standard Ed (8.0.50727.42 RTM.050727-4200) on WinXp with SP 2a.

Please, could you kindly let me know what has happened in the meantime? (I see that the last post is quite old).

TIA

Best regards

daniel

 

Answer 30

I tried this solution, but it does not work. I will now try to repair the framework installation. I my case it happend after editing a form and adding a new button on the form.
 

Answer 31

Hi all,

Thanks for all your inputs.

By the both ways suggested, i resolved the problem  .

Thank you

aditya

 

Answer 32

I think I am able to reproduce the problem. I will send the code, but here is what I did:

I created a new C# windows form application. Then I opened the Resources.resx file and added, say 20 icons at the same time by selecting icon files. This makes the problem  appear. If you delete the icons, the error  disappears.

I hope this helps at least to find out what's wrong.

regards,

Rudolf Heijink

 

Answer 33

I have properties that have System.Reflection.MemberInfo type and set its value at designtime. Designer stores values in resources as System.Reflection.Runtime[Constructor|Field|Method|Property]Info.

And I have following error  when building  project (IuiToolkitTest2) that has at least one such item in resources:

-------------------------------------------------------------------------------
The "GenerateResource" task  failed unexpectedly.
System.Reflection.TargetInvocationException: Type  in the data at line 129, position 5, cannot be loaded because it threw the following exception during construction: Could not load file or assembly 'IuiToolkitTest2, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system  cannot find the file specified. ---> System.Xml.XmlException: Type  in the data at line 129, position 5, cannot be loaded because it threw the following exception during construction: Could not load file or assembly 'IuiToolkitTest2, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. Line 129, position 5. ---> System.IO.FileNotFoundException: Could not load file or assembly 'IuiToolkitTest2, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'IuiToolkitTest2, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null'
   at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at System.Reflection.MemberInfoSerializationHolder..ctor(SerializationInfo info, StreamingContext context)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

   --- End of inner exception stack trace ---

   --- End of inner exception stack trace ---
   at Microsoft.Build.Shared.ExceptionHandling.RethrowUnlessFileIO(Exception e)
   at Microsoft.Build.Tasks.ProcessResourceFiles.ProcessFile(String inFile, String outFile)
   at Microsoft.Build.Tasks.ProcessResourceFiles.Run(TaskLoggingHelper log, ITaskItem[] assemblyFilesList, ArrayList inputs, ArrayList outputs, Boolean sourcePath, String language, String namespacename, String filename, String classname, Boolean publicClass)
   at Microsoft.Build.Tasks.ProcessResourceFiles.Run(TaskLoggingHelper log, ITaskItem[] assemblyFilesList, ArrayList inputs, ArrayList outputs, Boolean sourcePath, String language, String namespacename, String filename, String classname, Boolean publicClass)
   at Microsoft.Build.Tasks.GenerateResource.Execute()
   at Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode howToExecuteTask, Hashtable projectItemsAvailableToTask, BuildPropertyGroup projectPropertiesAvailableToTask, Boolean& taskClassWasFound) IuiToolkitTest2

-------------------------------------------------------------------------------

I reinstalled Framework, set GenerateResourceNeverLockTypeAssemblies key - nothing works.

 

Answer 34

I removed GenerateResourceNeverLockTypeAssemblies and project  was built. It's magic)))
 

Answer 35

I received the following error: error MSB4018: The "Vbc" task  failed unexpectedly.

I thought it was something complicated. After removing all of my files from my project  and still not being able to compile the project it turned out that the problem  was I had manually typed &H98512474 for my base address setting (project properties | Compile tab | Advanced Compile Options button). Although this number conforms with the requirements for a hex number apparently it was too large for compiler to handle. Changing this value to a smaller number resolved the problem.

Here is a recommendation that I received from the helpful folks at Microsoft:

In general, you want to keep base addresses lower than 2gig; although each process that you create runs in a virtual process space that on 32 bits is 4gig, you may be causing a fair amount of memory page swapping with such a large address space.  What you are trying to avoid by setting the base address is loading into a space someone else is loading into.  Collisions occur, and it just slows down the load time of your program.  A small amount, but some.  By default, VS builds programs at 0x10000000.  Now since Microsoft knows that, we move all our dll’s to higher ranges.  For example, most MSFT components load in the 0x60000000 to 0x80000000 range (Use the tool below and open System.dll from the .Net Framework to see an example).

A good tool to use to help you set an appropriate address is dependency walker.  This used to ship as part of Visual Studio but is now open source. http://www.dependencywalker.com/

Build your executable, and open it with dependency walker.  This will show every dll you are dependent on.  Look at the column ‘Preferred Base’ and ‘Virtual Size’.  Set your dll to a base that is not taken, and add your virtual size to ensure that you are not tramping over someone else’s preferred base.

A good rule of thumb is to use the space between 0x10000000 and 0x40000000.  The only time you really need to worry about this is when you’re are building  a program with several libraries.  Since your libraries will all want to load into the same space, they will clash and collide.  

 

Answer 36

I pasted the code you gave in the .csproj file.  but the same error  persists.  Do you know any other work around?
 

Answer 37

What about ? :

Error 223 The "GeneratePolicyManifest" task  failed unexpectedly.
System.UnauthorizedAccessException: Access to the path 'C:\Work\tf_dev\WorkflowComponents\_Main\AE.Indexing.BusinessComponent\bin\x86\Debug\policy.1.0.AE.Indexing.BusinessComponent.config' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.Xml.XmlWriter.Create(String outputFileName, XmlWriterSettings settings)
   at AE.Utility.TeamFoundation.MSBuild.GeneratePolicyManifest.GenerateManifestFile(VersionInfo info, Version curVersion, AssemblyName assemblyShortName, String destPublicKeyToken, String destDir)
   at AE.Utility.TeamFoundation.MSBuild.GeneratePolicyManifest.Execute()
   at Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode howToExecuteTask, Hashtable projectItemsAvailableToTask, BuildPropertyGroup projectPropertiesAvailableToTask, Boolean& taskClassWasFound) AE.Indexing.BusinessComponent

Using Team Foundation

 

Answer 38

I haven't seen that. Please open a new bug using the instructions at the top of the forum front page.

Dan

 

Answer 39

Rudolf heijink wrote:

I think I am able to reproduce the problem. I will send the code, but here is what I did:

I created a new C# windows form application. Then I opened the Resources.resx file and added, say 20 icons at the same time by selecting icon files. This makes the problem  appear. If you delete the icons, the error  disappears.

I hope this helps at least to find out what's wrong.

regards,

Rudolf Heijink



This is definitely the problem... Neither one of those workarounds worked for me... I added the <Generate...>true</Generate...> line on the project  file and the error kept appearing... I repaired the .net framework twice and didn't work either... Since I knew that the only change I made, before the error appeared, was adding more than 2 images (like 6 or 7) to the resources then I deleted all of them and then started adding one by one (without restarting VS2005) and the error disappeared like magic.

Hope this works for you
 

Answer 40

There are several unrelated problems in this thread, many of which you should find are fixed in .NET 3.5 -- certainly the problems that were previously fixed with <GenerateResourceNeverLockTypeAssemblies>. But as far as Christian Sanchez's posting on Sept 25th goes -- I'm not sure I understand this one yet.

Do you see an ImageList type in the .resx when it has this problem? That type is known to me to have a bug. Or are the icons persisted in it with some other type (such as Icon)?

Do you get a callstack you could post?

Thanks, Dan

 

Answer 41

After converting from vs2003 to vs2005, I have tried all the threads suggestions, Repair Framework and reboot and the <GenerateResourceNeverLockTypeAssemblies> tag in project  file and still get the below error. Where is the line reference coming from? the .resx file?

Error    10    The "GenerateResource" task  failed unexpectedly.
System.Reflection.TargetInvocationException: Type  in the data at line 135, position 5, cannot be loaded because it threw the following exception during construction: Loading of the ImageList did not succeed. ---> System.Xml.XmlException: Type  in the data at line 135, position 5, cannot be loaded because it threw the following exception during construction: Loading of the ImageList did not succeed. Line 135, position 5. ---> System.InvalidOperationException: Loading of the ImageList did not succeed.
   at System.Windows.Forms.ImageListStreamer..ctor(SerializationInfo info, StreamingContext context)
   --- End of inner exception stack trace ---

   --- End of inner exception stack trace ---
   at Microsoft.Build.Shared.ExceptionHandling.RethrowUnlessFileIO(Exception e)
   at Microsoft.Build.Tasks.ProcessResourceFiles.ProcessFile(String inFile, String outFile)
   at Microsoft.Build.Tasks.ProcessResourceFiles.Run(TaskLoggingHelper log, ITaskItem[] assemblyFilesList, ArrayList inputs, ArrayList outputs, Boolean sourcePath, String language, String namespacename, String filename, String classname, Boolean publicClass)
   at Microsoft.Build.Tasks.ProcessResourceFiles.Run(TaskLoggingHelper log, ITaskItem[] assemblyFilesList, ArrayList inputs, ArrayList outputs, Boolean sourcePath, String language, String namespacename, String filename, String classname, Boolean publicClass)
   at Microsoft.Build.Tasks.GenerateResource.Execute()
   at Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode howToExecuteTask, Hashtable projectItemsAvailableToTask, BuildPropertyGroup projectPropertiesAvailableToTask, Boolean& taskClassWasFound)    MyDLLfile

 

Answer 42

Hi, this is a known, sporadic bug in the implementation of the serializer or deserializer code in this ImageList type.

However I've never managed to reproduce it internally so that I can bring the problem  to the attention of the owners of ImageList. (If you can help me with this, please open a bug using the instructions at the top of the forum.)

Meantime I suggest that you try adding/removing images to the image list, or removing it and re-adding it to your form, that kind of thing, which seems to have helped others in this situation.

Dan

 

Answer 43

Hi,

I have a co-worker getting this "GenerateResource" error  (see below).  He is useing VS 2005 with SP1.  The project  is a Visual Basic one.  I am able to build  the same project without problems, he used to be but can not any longer.  We tried adding the

<GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>

to the .vbproj file, repairing the .net install (2.0), and reinstalling the VS Service Pack.  Nothing worked.

Any ideas?

------ Build started: Project: TSMain, Configuration: Debug Any CPU ------
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018: The "GenerateResource" task  failed unexpectedly.
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018: System.Reflection.TargetInvocationException: Type  in the data at line 1030, position 5, cannot be loaded because it threw the following exception during construction: Member 'mcaloktext' was not found. ---> System.Xml.XmlException: Type  in the data at line 1030, position 5, cannot be loaded because it threw the following exception during construction: Member 'mcaloktext' was not found. Line 1030, position 5. ---> System.Runtime.Serialization.SerializationException: Member 'mcaloktext' was not found.
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018:    at System.Runtime.Serialization.SerializationInfo.GetElement(String name, Type& foundType)
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018:    at System.Runtime.Serialization.SerializationInfo.GetString(String name)
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018:    at FarPoint.Win.Spread.CellType.NumberCellType..ctor(SerializationInfo info, StreamingContext context)
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018:    --- End of inner exception stack trace ---
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018:    --- End of inner exception stack trace ---
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018:    at Microsoft.Build.Shared.ExceptionHandling.RethrowUnlessFileIO(Exception e)
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018:    at Microsoft.Build.Tasks.ProcessResourceFiles.ProcessFile(String inFile, String outFile)
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018:    at Microsoft.Build.Tasks.ProcessResourceFiles.Run(TaskLoggingHelper log, ITaskItem[] assemblyFilesList, ArrayList inputs, ArrayList outputs, Boolean sourcePath, String language, String namespacename, String filename, String classname, Boolean publicClass)
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018:    at Microsoft.Build.Tasks.ProcessResourceFiles.Run(TaskLoggingHelper log, ITaskItem[] assemblyFilesList, ArrayList inputs, ArrayList outputs, Boolean sourcePath, String language, String namespacename, String filename, String classname, Boolean publicClass)
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018:    at Microsoft.Build.Tasks.GenerateResource.Execute()
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1616,9): error MSB4018:    at Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode howToExecuteTask, Hashtable projectItemsAvailableToTask, BuildPropertyGroup projectPropertiesAvailableToTask, Boolean& taskClassWasFound)
Done building  project "TSMain.vbproj" -- FAILED.
 

Answer 44

Hello,

I have a potential fix for this problem. I just hit that same problem  and this is the solution I found.

I had installed an evaluation version of some third party software and created projects using it.

I then uninstalled the evaluation software and installed the retail software.

I could suddenly no longer build  anything. Error MSB4018.

I knew it had to be Visual Studio 2005 caching something out of sync so I searched my hard drive and found a cache at C:\Documents and Settings\Mikec\Local Settings\Application Data\Microsoft\VisualStudio\8.0\ProjectAssemblies. Subdirectories with temporary names still containing the old assemblies.

I deleted (moved them temporarily to be safe) these subdirectories and everything started working again.

This is probably supposed to be a temporary cache that's not getting cleaned out properly.

Hope this works for you.

 

Answer 45

I think there is another potential workaround for some version of this bug (it at least worked for me):

Close all instances of VS
Open a VS Command Prompt
run: devenv /clean
run: devenv /setup
Re-open everything and try to compile again

I think this performs what Michael Carney suggested, plus some other things although I'll let microsoft  or an MVP clarify more about it as I'm pretty ignorant to it. Smile

My issue was not the images issue as we haven't changed any image stuff in at least a week and the problem  just began happening this afternoon.

Good luck and I hope this helps somebody!

-Shane

 

Answer 46

Thank you very much for your fix Jaxidian.  I have had this error  occur on three separate occasions and the only fix that was routinely successful was un-installing and re-installing Visual Studio.  Cleaning the devenv caused my application  to work immediately, thus saving me several hours. 
 

Answer 47

DevelOnYourShoulder wrote:
Thank you very much for your fix Jaxidian.  I have had this error  occur on three separate occasions and the only fix that was routinely successful was un-installing and re-installing Visual Studio.  Cleaning the devenv caused my application  to work immediately, thus saving me several hours. 

Am happy to be of service!! Smile

 

Answer 48

Faisal Mohamood MSFT

Oh my gosh!!!

Faisal... You r a Hero, a champion and who knows something even more!!! hehehe

Thx a lot!!!

Cheers
cya
mr.xalala

Everybody can save! Just use Ctrl+S! =o]-
 

Answer 49

Hi, does anyone have this issue when trying to build  a solution file.
Im running Win7RC and VS2008, think this is a build problem, but im not sure.

Error 1 The "GenerateResource" task  failed unexpectedly.
System.Runtime.InteropServices.ExternalException: 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)
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
   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, ArrayList inputs, ArrayList 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, ArrayList inputs, ArrayList outputs, Boolean sourcePath, String language, String namespacename, String resourcesNamespace, String filename, String classname, Boolean publicClass)
   at Microsoft.Build.Tasks.GenerateResource.Execute()
   at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult) W_GM

 

Answer 50

I had a similar issue and it turned out to be caused by multiple revisions of a particular framework in the "C:\WINDOWS\Microsoft.NET\Framework\" path.  For me, I had v4.0.30128  and v4.0.21006 due to my own chicanery.  I simply renamed the unwanted revision and restarted my build  successfully.

dgp
 

Answer 51

I've add this to the first PropertyGroup, but it doesn't solve my problem.

Here is error  text

Error	6	The "GenerateResource" task  failed unexpectedly.
System.InvalidOperationException: The security state of an AppDomain was modified  by an AppDomainManager configured with the NoSecurityChanges flag.
  at System.AppDomain.SetupDomainSecurity(AppDomainHandle appDomain, ObjectHandleOnStack appDomainEvidence, IntPtr creatorsSecurityDescriptor, Boolean publishAppDomain)
  at System.AppDomain.InitializeDomainSecurity(Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, Boolean generateDefaultEvidence, IntPtr parentSecurityDescriptor, Boolean publishAppDomain)
  at System.AppDomain.Setup(Object arg)
  at System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor)
  at System.AppDomainManager.CreateDomainHelper(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
  at System.AppDomainManager.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
  at System.AppDomain.InternalCreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
  at System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
  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)	Components
I'm using VS 2010. Error appears while migrating project  to 4.0 framework when I add <NetFx40_LegacySecurityPolicy enabled="true"/> this to devenv.exe.config.


 

Answer 52

Hi Faisal,

I have VS2010 with the same problem.  I tried your workaround and it didnt work.   Any other suggestion?

J

 

Answer 53

I am having the exactly same problem  after upgrading my solutions/projects to VS 2010.

Error 80 The "GenerateResource" task  failed unexpectedly.
System.InvalidOperationException: The security state of an AppDomain was modified  by an AppDomainManager configured with the NoSecurityChanges flag.
   at System.AppDomain.SetupDomainSecurity(AppDomainHandle appDomain, ObjectHandleOnStack appDomainEvidence, IntPtr creatorsSecurityDescriptor, Boolean publishAppDomain)
   at System.AppDomain.InitializeDomainSecurity(Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, Boolean generateDefaultEvidence, IntPtr parentSecurityDescriptor, Boolean publishAppDomain)
   at System.AppDomain.Setup(Object arg)
   at System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor)
   at System.AppDomainManager.CreateDomainHelper(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
   at System.AppDomainManager.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
   at System.AppDomain.InternalCreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   at System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   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) Juris.SnapIn.Base


I have added the <NetFx40_LegacySecurityPolicyenabled="true"/> line to the <runtime> group in the devenv.exe.config file. I also tried the <GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies> work around as well as attempting Shane M's suggestion of running devenv /clean and devenv setup.

I still get the compilation error. I've been butting my head against this for 2 days now. It looks, based on my web searches, that this problem has been around since VS 2005. I would have hoped that MSFT would have provided a solid solution by now.


 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Tech Videos   |   Follow us on Twitter