草庐IT

c# - XmlSerializer 反序列化 CSC.EXE 的错误

coder 2024-07-04 原文

我创建了一个在我的计算机上运行良好并且通常在其他计算机上也运行良好的程序。 但是有人在运行它时遇到问题,我真的不明白为什么,Stacktrace 是:

System.Runtime.InteropServices.ExternalException (0x80004005): Impossibile eseguire un programma. Il comando in esecuzione era "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\c sc.exe" /noconfig /fullpaths @"C:\Users\Andry\AppData\Local\Temp\dot0eqxi.cmdli ne". ---> System.ComponentModel.Win32Exception (0x80004005): Unknown error (0x36b1) in System.CodeDom.Compiler.Executor.ExecWaitWithCaptu reUnimpersonated(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine) in System.CodeDom.Compiler.Executor.ExecWaitWithCaptu re(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine) in Microsoft.CSharp.CSharpCodeGenerator.Compile(Compi lerParameters options, String compilerDirectory, String compilerExe, String arguments, String& outputFile, Int32& nativeReturnValue, String trueArgs) in Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch (CompilerParameters options, String[] fileNames) in Microsoft.CSharp.CSharpCodeGenerator.FromSourceBat ch(CompilerParameters options, String[] sources) in Microsoft.CSharp.CSharpCodeGenerator.System.CodeDo m.Compiler.ICodeCompiler.CompileAssemblyFromSource Batch(CompilerParameters options, String[] sources) in System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence) in System.Xml.Serialization.TempAssembly.GenerateAsse mbly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies) in System.Xml.Serialization.TempAssembly..ctor(XmlMap ping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence) in System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace) in SpellCaster3.Program.LoadBaseRange() in SpellCaster3.Program.Main()

如您所见,问题与反序列化有关(该对象仅被反序列化)并且它发生在 XmlSerializer 构造函数中。

这个问题可能以某种方式与这个问题有关:Why is my windows service launching instances of csc.exe?Why is my windows service launching instances of csc.exe?

我显然无法复制该错误。 这是涉及的代码:

Program.cs

    private static void LoadBaseRange()
    {
        string fileIconImageIndices = Application.StartupPath + Path.DirectorySeparatorChar + "ValidIconImageIndices.xml";
        if (!File.Exists(fileIconImageIndices)) throw new FileNotFoundException("Attenzione, il file degli indici delle immagini non è stato trovato");

        using (StreamReader reader = new StreamReader(fileIconImageIndices, Encoding.UTF8))
        {
            XmlSerializer serializer = new XmlSerializer(typeof(RangeCollection));
            Forms.GumpPicker.BaseRange = serializer.Deserialize(reader) as RangeCollection;
        }
    }

    /// <summary>
    /// Punto di ingresso principale dell'applicazione.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
        try
        {
            LoadBaseRange();
        }
        catch (FileNotFoundException fileException)
        {
            ErrorForm.Show(fileException.Message + "\nL'applicazione verrà terminata", fileException);
            return;
        }
        catch (Exception exception)
        {
            ErrorForm.Show("L'applicazione verrà terminata", exception);
            return;
        }

RangeCollection.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace Expand.Linq
{
    public class RangeCollection : IXmlSerializable
    {
        public static readonly Version Version = new Version(1, 0, 0, 0);

        internal static Version FoundVersion { get; private set; }

        /// <summary>
        /// Used for xml deserialization
        /// </summary>
        public RangeCollection() { }

        public RangeCollection(IEnumerable<IEnumerable<int>> ranges)
        {
            Range = ConvertToListInt(ranges);
        }

        private List<int> ConvertToListInt(IEnumerable<IEnumerable<int>> ranges)
        {
            IEnumerable<int> tmpRange;
            tmpRange = Enumerable.Empty<int>();

            foreach (IEnumerable<int> range in ranges)
                tmpRange = tmpRange.Union(range);

            tmpRange = tmpRange.OrderBy(number => number);
            return new List<int>(tmpRange);
        }


        public static implicit operator RangeCollection(List<IEnumerable<int>> ranges)
        {
            return new RangeCollection(ranges);
        }

        public List<int> Range { get; private set; }

        public int Maximum
        {
            get
            {
                return Range.Max();
            }
        }

        public int Minimum
        {
            get
            {
                return Range.Min();
            }
        }

        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            List<IEnumerable<int>> ranges = new List<IEnumerable<int>>(100);
            string elementName = "Range";
            Version version;

            version = Version.Parse(reader.GetAttribute("Version"));
            FoundVersion = version;

            if (reader.IsEmptyElement) return;

            reader.ReadStartElement(GetType().Name);
            while (true)
            {
                if (reader.NodeType == XmlNodeType.Element && reader.LocalName == elementName)
                {
                    reader.ReadStartElement(elementName);
                    int start = reader.ReadElementContentAsInt();
                    int end = reader.ReadElementContentAsInt();
                    reader.ReadEndElement();
                    if (start == end)
                        ranges.Add(ExEnumerable.Range(start));
                    else
                        ranges.Add(ExEnumerable.RangeBetween(start, end));
                }
                else
                    break;
            }
            reader.ReadEndElement();
            Range = ConvertToListInt(ranges);
        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            throw new NotSupportedException();
        }
    }
}

ValidIconImageIndices.xml(涉及XML文件)

<?xml version="1.0" encoding="utf-8" ?>
<RangeCollection Version="1.0.0.0">
  <Range>
    <Start>1236</Start>
    <End>1246</End>
  </Range>
  <Range>
    <Start>1260</Start>
    <End>1260</End>
  </Range>
  <Range>
    <Start>1263</Start>
    <End>1287</End>
  </Range>
  <Range>
    <Start>1300</Start>
    <End>1309</End>
  </Range>
  <Range>
    <Start>1311</Start>
    <End>1312</End>
  </Range>
  <Range>
    <Start>1401</Start>
    <End>1415</End>
  </Range>
  <Range>
    <Start>1782</Start>
    <End>1782</End>
  </Range>
  <Range>
    <Start>1789</Start>
    <End>1795</End>
  </Range>
  <Range>
    <Start>2240</Start>
    <End>2303</End>
  </Range>
  <Range>
    <Start>2406</Start>
    <End>2408</End>
  </Range>
  <Range>
    <Start>2410</Start>
    <End>2419</End>
  </Range>
  <Range>
    <Start>20480</Start>
    <End>20496</End>
  </Range>
  <Range>
    <Start>20736</Start>
    <End>20745</End>
  </Range>
  <Range>
    <Start>20992</Start>
    <End>21020</End>
  </Range>
  <Range>
    <Start>21248</Start>
    <End>21248</End>
  </Range>
  <Range>
    <Start>21251</Start>
    <End>21257</End>
  </Range>
  <Range>
    <Start>21280</Start>
    <End>21287</End>
  </Range>
  <Range>
    <Start>21504</Start>
    <End>21507</End>
  </Range>
  <Range>
    <Start>21536</Start>
    <End>21542</End>
  </Range>
  <Range>
    <Start>21632</Start>
    <End>21632</End>
  </Range>
  <Range>
    <Start>23000</Start>
    <End>23015</End>
  </Range>
</RangeCollection>

我不知道操作系统的用户,但我认为它是 Windows 7 家庭版 64 位。 他有 .NET 4.0,应用程序是 .net 4.0 的 Winforms 应用程序

如果你想测试它,链接到应用程序: http://dl.dropbox.com/u/762638/Files/Documents/My%20Programs/SpellCaster3/SpellCaster3.zip

与安装程序的链接: http://dl.dropbox.com/u/762638/Files/Documents/My%20Programs/SpellCaster3/setup.zip

最佳答案

C# 编译器 (csc.exe) 无法在那台机器上启动。错误代码是悲惨的,E_FAIL,除了“它没有工作,不知道为什么”之外没有任何意义。这里需要 C# 编译器来生成 XML 序列化程序集。

这是环境问题,与你的代码无关。鉴于糟糕的错误代码,它可能是任何东西。恶意软件扫描器通常会导致此类问题的发生。这是用户的 IT 团队需要解决的问题,您对此无能为力。尽管您可以使用 sgen.exe 预先生成序列化程序集,这样它就不必在用户的机器上完成。

关于c# - XmlSerializer 反序列化 CSC.EXE 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6766834/

有关c# - XmlSerializer 反序列化 CSC.EXE 的错误的更多相关文章

  1. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  2. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  3. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  4. ruby-on-rails - 如何在 Rails View 上显示错误消息? - 2

    我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c

  5. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  6. ruby-on-rails - 错误 : Error installing pg: ERROR: Failed to build gem native extension - 2

    我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby​​'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe

  7. ruby - #之间? Cooper 的 *Beginning Ruby* 中的错误或异常 - 2

    在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee

  8. ruby-on-rails - 每次我尝试部署时,我都会得到 - (gcloud.preview.app.deploy) 错误响应 : [4] DEADLINE_EXCEEDED - 2

    我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie

  9. ruby-on-rails - Rails 5 Active Record 记录无效错误 - 2

    我有两个Rails模型,即Invoice和Invoice_details。一个Invoice_details属于Invoice,一个Invoice有多个Invoice_details。我无法使用accepts_nested_attributes_forinInvoice通过Invoice模型保存Invoice_details。我收到以下错误:(0.2ms)BEGIN(0.2ms)ROLLBACKCompleted422UnprocessableEntityin25ms(ActiveRecord:4.0ms)ActiveRecord::RecordInvalid(Validationfa

  10. c# - 如何在 ruby​​ 中调用 C# dll? - 2

    如何在ruby​​中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL

随机推荐