64

I have developed an application using .net 3.5 and have deployed it as an .exe on a number of machines with the same environment. However, on one particular machine I get the following error. Stack Trace:


See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

System.InvalidOperationException: Unable to generate a temporary class (result=1).
error CS2001: Source file 'C:\WINDOWS\TEMP\wz58eig4.0.cs' could not be found
error CS2008: No inputs specified

   at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
   at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
   at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
   at System.Xml.Serialization.XmlSerializer.GetSerializersFromCache(XmlMapping[] mappings, Type type)
   at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
   at System.Web.Services.Protocols.SoapClientType..ctor(Type type)
   at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()
   at SSOClient..ctor()
   at sc.tradesvc.SSOManager..ctor()
   at sc.tradesvc.SSOManager.get_Inst()
   at sc.cashflowgenerator.Controls.LoginForm.btnLogin_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.PerformClick()
   at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
   at System.Windows.Forms.TextBoxBase.ProcessDialogKey(Keys keyData)
   at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
   at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
   at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)

Loaded Assemblies:

mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll

CashflowGenerator
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/DATA/DEVEL/Output/CashflowGenerator.exe

System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll

System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll

System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll

System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll

System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll

System.Core
    Assembly Version: 3.5.0.0
    Win32 Version: 3.5.21022.8 built by: RTM
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll

System.Web.Services
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Web.Services/2.0.0.0__b03f5f7f11d50a3a/System.Web.Services.dll

************** JIT Debugging ************** To enable just-in-time (JIT) debugging, the .config file for this application or computer (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled.

For example:

When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the computer rather than be handled by this dialog box.


Could someone help me with this?

As I am new to .net could someone also tell me when why a temporary class needs to be created in the first place?

Kit Menke
  • 7,046
  • 1
  • 32
  • 54
keepsmilinyaar
  • 987
  • 1
  • 9
  • 13
  • Could you post some code as well, please? – Andrew Hare Mar 18 '09 at 12:13
  • http://www.hanselman.com/blog/ChangingWhereXmlSerializerOutputsTemporaryAssemblies.aspx has some info on this – Chris S Mar 23 '13 at 13:20
  • It is possible to generate -an-xml-serialization-assembly-as-part-of build and include in deployment http://stackoverflow.com/questions/134224/generating-an-xml-serialization-assembly-as-part-of-my-build?rq=1 – Michael Freidgeim Feb 10 '14 at 10:07

12 Answers12

115

I just spent a lot of time searching for the answer to this so I thought I'd add it here to save some headache for others. If you use the xsd.exe tool to generate your cs it may have added double arrays [][] where an array should be []. Replace all [][] with [] in your generated cs file and retry.

Terra
  • 1,309
  • 2
  • 10
  • 10
  • Just ran into this myself - I'm almost tempted to ask this explicit question with a more discoverable title, just so you can answer it again. Well spotted! – JerKimball Apr 25 '14 at 16:33
  • 8
    This is the "only" correct answer. I aslo was baffled when I saw generated code with double arrays [][]. But glad you pinpointed and figured out the tool. Thanks a lot. – Gerald G. Apr 25 '14 at 22:05
  • 1
    @GeraldG. clearly it is not! It's _another_ reason why people might see the symptoms reported in the OP. That doesn't make it the /only/ answer. Symptoms can be deceiving – sehe Nov 10 '14 at 14:47
  • +1 - saved me a lot of time too! Thank you sire! Can't believe XSD would do something so stupid... oh wait, XSD is stupid. Should not be surprised by this freakish bug. THNX again m8 – George May 29 '15 at 16:33
  • @JerKimball I was thinking the same thing, then I found it had already been asked and answered almost two years before this one - http://stackoverflow.com/q/6678934/892536. It's interesting that this is where we found the answer instead of the older, more specific question. :/ – tehDorf Dec 10 '15 at 15:50
  • Just come across this... Usually, seeing this answer, I would downvote, because changing generated files seem to be bad. But I have to admit... this is the real answer. – Luke Vo Jun 06 '16 at 20:37
  • BOO YA! Way to go Terra! Saved me so much time. Wonderful find. – pim Jul 12 '16 at 14:08
  • Thanks, this was the issue. Saved me lot of time – der_chirurg Jun 16 '17 at 09:17
  • 1
    Thank you so much! I used WSDL.exe tool and it had done exactly that! Once I removed the ()() it fixed the issue! – user1683987 Oct 19 '17 at 19:56
  • I wanted to add that this can be caused by "Paste Special\As XML Classes" also, and this fix works here as well. Brava, Terra. – CodeHxr Apr 12 '18 at 15:39
  • This was the solution to my issue with wsdl.exe as well. I aslo found this that gives some other resolution options: https://support.microsoft.com/en-us/help/2486643/sco-unable-to-generate-a-temporary-class-result-1-error-when-you-execu – Sam Aug 16 '18 at 14:25
30

XML Serialisation works by generating code to perform the serialisation. This is done in a temporary assembly created for that purpose the first time it is needed.

However this relies on being able to write the assembly to disk.1

Your options are either to (1) given the user account which is running the process write permission (for an ASP.NET application this is likely to be a bad idea). (2) Use the SDK tool (sgen.exe) to pre-generate (at development/compile time) the serialisation assembly, and then use (and deplot) that assembly.

1Open question: the APIs exist to create assemblies dynamically in memory: why not do that?

Richard
  • 106,783
  • 21
  • 203
  • 265
  • 3
    in VS08 I think there is even a tick box in project properties to generate it. – Grzenio Mar 18 '09 at 12:34
  • 1
    If created in memory, they need to be recreated on an AppDomain restart. Create them on disk, then they stay on disk? I don't know if that's the reason, as I wonder if they'd have the same names after the restart. – John Saunders Mar 18 '09 at 12:43
24

You only have to give the List Folder Contents and Read permissions on %windir%\Temp.

I found this post when trying to fix my problem, and didn't have to give my user account write access.

From Microsoft

Martin Brown
  • 24,692
  • 14
  • 77
  • 122
BillRob
  • 4,659
  • 4
  • 26
  • 38
  • 1
    Remember to select the correct IUSR/IIS_IUSRS account on a machine that's part of a domain. I started by adding the ISUR account for the domain, but it needed to be the IIS_IUSRS account for the local machine. Didn't need write access as BillRob stated. – Daz Mar 14 '13 at 06:32
5

You need to add *IIS_IUSR* user with read write permission to C:\Windows\Temp folder.

NOTE: Everyone user will not work with full control.

shakaran
  • 10,612
  • 2
  • 29
  • 46
Hemant
  • 51
  • 1
  • 1
5

You Need to give the permission to the temp folder which is in windows folder. And Your Problem is Solved...........

Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126
3

Surfacing @grzenio's comment a bit further for recent users:

If you go to Project Properties -> Build -> Generate serialization assembly -> On, it forces the generation of the XML serializers assembly at compile time, eliminating the need to do so at runtime.

In turn, this means you don't need to change filesystem permissions (useful if you're, for example, hosting on Windows Azure Web Sites, where that isn't an option).

rmc47
  • 1,364
  • 1
  • 13
  • 17
2

It may be also just some simple error in the serialized class (typically a result of some copy/paste). For example the following class will cause this error:

  public class Foo
  {
      private string[] contexts;

      /// <remarks/>
      [System.Xml.Serialization.XmlArrayItemAttribute("Context", 
       typeof(Property), IsNullable = false)]
      public string[] Contexts
      {
          get { return this.contexts; }
          set { this.contexts = value; }
      }
  }

Notice that typeof(Property) parameter in XmlArrayItem attribute is not compatible (most likely) with string causing similar exception:

System.InvalidOperationException: 
Unable to generate a temporary class (result=1).

If typeof(Property) is replaced with typeof(string) serialization will work again.

mp31415
  • 6,531
  • 1
  • 44
  • 34
0

Give Read/Write Privileges to 'C:\WINDOWS\TEMP' folder. It will work.

0

It may be bacause you are switching application pooling identity in IIS to be password instead of predefined so you have one off the following

  1. return to predefined
  2. give prmission full control to user IWAM_WBSRV-01 on the windows temp folder
MKB
  • 7,587
  • 9
  • 45
  • 71
0

In case this helps anyone, my problem was coming from an inherited class used in the serialization. The problem went away when I made a full copy/paste of my class I was serializing and quit using ineritance. Unfortunately, the advantages of inheritance went away, but that is better than having this problem. (Hey, at least I'm pretty sure that's what solved it. Happened to do a reboot in there somehwere too.)

ctn
  • 1
  • 1
0

the APIs exist to create assemblies dynamically in memory: why not do that?

Just a wild guess: I assume this possibility did not exist yet in .NET 1.0, or at least when the XmlSerializer was created and MS doesn't like changing existing behavior...

Wiebe Tijsma
  • 10,173
  • 5
  • 52
  • 68
0

Windows 10 has Virus and threat protection - if you have Ransomware protection (controlled folder access) it will block sgen.exe by default. Add sgen.exe it to exception list.

sgen.exe is located here: C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools Folder name may vary depending on your Framework version

krisu
  • 1
  • 2