2

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

System.Runtime.InteropServices.ExternalException (0x80004005): 不可能 eseguire un programma。Il comando 在 esecuzione 时代 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\c sc.exe" /noconfig /fullpaths @"C:\Users\Andry\AppData\Local\Temp\dot0eqxi.cmdline" . ---> System.ComponentModel.Win32Exception (0x80004005): System.CodeDom.Compiler.Executor.ExecWaitWithCaptu reUnimpersonated 中的未知错误 (0x36b1) (SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine ) 在 Microsoft.CSharp 中的 System.CodeDom.Compiler.Executor.ExecWaitWithCaptu re(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine) 中。

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

这个问题可能在某种程度上与这个问题有关:为什么我的 Windows 服务会启动 csc.exe 的实例?为什么我的 Windows 服务会启动 csc.exe 实例

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

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

4

1 回答 1

6

C# 编译器 (csc.exe) 无法在该计算机上启动。错误代码很糟糕,E_FAIL 仅表示“它不起作用,不知道为什么”。这里需要 C# 编译器来生成 XML 序列化程序集。

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

于 2011-07-20T19:16:06.450 回答