C# System.InvalidOperationException:无法生成临时类(结果 = 1)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/657993/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 12:09:48  来源:igfitidea点击:

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

c#input

提问by keepsmilinyaar

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:

我使用 .net 3.5 开发了一个应用程序,并将其作为 .exe 部署在具有相同环境的多台机器上。但是,在一台特定的机器上,我收到以下错误。堆栈跟踪:



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

有关调用即时 (JIT) 调试而不是此对话框的详细信息,请参阅此消息的末尾。

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.

************** JIT 调试 ************** 要启用即时 (JIT) 调试,此应用程序的 .config 文件或计算机 (machine.config) 必须在 system.windows.forms 部分设置 jitDebugging 值。还必须在启用调试的情况下编译应用程序。

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.

启用 JIT 调试后,任何未处理的异常都将发送到计算机上注册的 JIT 调试器,而不是由此对话框处理。



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?

由于我是 .net 的新手,有人可以告诉我为什么首先需要创建临时类吗?

采纳答案by Richard

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.

XML 序列化通过生成代码来执行序列化。这是在第一次需要时在为此目的创建的临时程序集中完成的。

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

然而,这依赖于能够将程序集写入磁盘。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.

您可以选择 (1) 给运行进程写入权限的用户帐户(对于 ASP.NET 应用程序,这可能是一个坏主意)。(2) 使用 SDK 工具 ( sgen.exe) 预先生成(在开发/编译时)序列化程序集,然后使用(和 deplot)该程序集。

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

1开放性问题:存在用于在内存中动态创建程序集的 API:为什么不这样做?

回答by Wiebe Tijsma

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

API 的存在是为了在内存中动态创建程序集:为什么不这样做呢?

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...

只是一个疯狂的猜测:我认为这种可能性在 .NET 1.0 中还不存在,或者至少在创建 XmlSerializer 并且 MS 不喜欢改变现有行为时......

回答by BillRob

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

您只需在 %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

来自微软

回答by Ayush Chaudhary

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

您需要授予 Windows 文件夹中临时文件夹的权限。你的问题解决了.......

回答by Hemant

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

您需要将具有读写权限的 *IIS_IUSR* 用户添加到C:\Windows\Temp 文件夹

NOTE: Everyone user will not work with full control.

注意:每个用户都不会完全控制工作。

回答by Brijesh Kansagara

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

为“C:\WINDOWS\TEMP”文件夹提供读/写权限。它会起作用。

回答by abdullah

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

这可能是因为您将应用程序池身份切换IIS为密码而不是预定义的,因此您有以下一项

  1. return to predefined
  2. give prmission full control to user IWAM_WBSRV-01 on the windows temp folder
  1. 返回预定义
  2. 将 prmission 完全控制权授予 Windows 临时文件夹上的用户 IWAM_WBSRV-01

回答by Terra

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.

我只是花了很多时间来寻找这个问题的答案,所以我想我会在这里添加它以减轻其他人的头痛。如果您使用 xsd.exe 工具生成您的 cs,它可能会添加双数组 [][],其中数组应为 []。将生成的 cs 文件中的所有 [][] 替换为 [] 并重试。

回答by rmc47

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

为最近的用户进一步展示@grzenio 的评论:

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.

如果转到 Project Properties -> Build -> Generate serialization assembly -> On,它会在编译时强制生成 XML 序列化程序集,而无需在运行时这样做。

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).

反过来,这意味着您不需要更改文件系统权限(例如,如果您在 Windows Azure 网站上托管,这不是一个选项,则很有用)。

回答by ctn

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.)

如果这对任何人都有帮助,我的问题来自序列化中使用的继承类。当我对正在序列化的类进行完整复制/粘贴并退出使用继承时,问题就消失了。不幸的是,继承的优势消失了,但这总比有这个问题要好。(嘿,至少我很确定这就是解决问题的方法。碰巧在那里也进行了重新启动。)