Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XmlSerializer使用CSC.EXE反序列化错误_C#_Xml_Serialization_Csc - Fatal编程技术网

C# XmlSerializer使用CSC.EXE反序列化错误

C# XmlSerializer使用CSC.EXE反序列化错误,c#,xml,serialization,csc,C#,Xml,Serialization,Csc,我创建了一个程序,该程序在我的计算机上运行良好,通常也在其他计算机上运行。 但是,有一个人在运行时遇到问题,我真的不明白为什么,Stacktrace是: System.Runtime.InteropServices.ExternalException(0x80004005): 不可能的,不可能的。伊尔·科曼多在埃塞库齐昂时代 “C:\Windows\Microsoft.NET\Framework64\v4.0.30319\C sc.exe”/noconfig /完整路径@“C:\Users\An

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

System.Runtime.InteropServices.ExternalException(0x80004005): 不可能的,不可能的。伊尔·科曼多在埃塞库齐昂时代 “C:\Windows\Microsoft.NET\Framework64\v4.0.30319\C sc.exe”/noconfig /完整路径@“C:\Users\Andry\AppData\Local\Temp\dot0eqxi.cmdli-ne”。 --->System.ComponentModel.Win32异常(0x80004005):未知错误 (0x36b1)在System.CodeDom.Compiler.Executor.ExecWaitWithCaptu中 reUnimpersonated(SafeUserTokenHandle userToken、字符串cmd、字符串 currentDir,TempFileCollection tempFiles,String&outputName,String& 错误名称,字符串(CMDLINE) System.CodeDom.Compiler.Executor.ExecWaitWithCaptu re(安全用户令牌句柄用户令牌、字符串cmd、字符串currentDir、, TempFileCollection tempFiles、String和outputName、String和errorName、, 中的字符串(行) Microsoft.CSharp.CSharpCodeGenerator.Compile(compilerParameters 选项,字符串编译器目录,字符串编译器,字符串 参数、字符串和输出文件、Int32和nativeReturnValue、字符串 Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch中的trueArgs) (CompilerParameters选项,字符串[]文件名)位于 Microsoft.CSharp.CSharpCodeGenerator.FromSourceBat 中的ch(编译器参数选项,字符串[]源) Microsoft.CSharp.CSharpCodeGenerator.System.CodeDo m、 Compiler.ICodeCompiler.compileAsemblyFromSource 批处理(编译器参数选项,字符串[]源) System.Xml.Serialization.Compiler.Compile(程序集父级,字符串ns, XmlSerializerCompilerParameters(xmlParameters,证据) System.Xml.Serialization.TempAssembly.GenerateASE mbly(XmlMapping[] xmlMappings、类型[]类型、字符串defaultNamespace、证据、, XmlSerializerCompilerParameters参数,程序集, 中的哈希表程序集) System.Xml.Serialization.TempAssembly..ctor(XmlMap ping[]xmlMappings, 类型[]类型、字符串defaultNamespace、字符串位置、证据 证据)在System.Xml.Serialization.XmlSerializer..ctor(类型, 中的SpellCaster3.Program.LoadBaseRange()中的字符串defaultNamespace) SpellCaster3.Program.Main()

正如您所看到的,问题与反序列化(该对象仅被反序列化)有关,它发生在XmlSerializer构造函数中

这个问题可能在某种程度上与这个问题有关:以及

我显然不能复制这个错误。 以下是涉及的代码:

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;
        }
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();
        }
    }
}
private static void LoadBaseRange()
{
字符串fileIConimageIndexes=Application.StartupPath+Path.directorySpectorChar+“validiconimageIndexes.xml”;
如果(!File.Exists(fileiconimageindex))抛出新的FileNotFoundException(“Attenzione,il File degli indici delle inmagini nonèstato trovato”);
使用(StreamReader=newstreamreader(fileiconimageindex,Encoding.UTF8))
{
XmlSerializer serializer=新的XmlSerializer(typeof(RangeCollection));
Forms.GumpPicker.BaseRange=序列化程序。将(读取器)反序列化为RangeCollection;
}
}
/// 
///安格尔索应用原理酒店。
/// 
[状态线程]
静态void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ApplicationExit+=新的事件处理程序(Application\u ApplicationExit);
尝试
{
LoadBaseRange();
}
捕获(FileNotFoundException fileException)
{
ErrorForm.Show(fileException.Message+“\nL'applicatione verráterminta”,fileException);
返回;
}
捕获(异常)
{
ErrorForm.Show(“应用程序终止”,例外);
返回;
}
RangeCollection.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;
        }
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();
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Xml;
使用System.Xml.Serialization;
名称空间Expand.Linq
{
公共类RangeCollection:IXmlSerializable
{
公共静态只读版本版本=新版本(1,0,0,0);
内部静态版本FoundVersion{get;private set;}
/// 
///用于xml反序列化
/// 
公共范围集合(){}
公共范围集合(IEnumerable ranges)
{
范围=变矩器阻力(范围);
}
私有列表转换列表(IEnumerable rangest)
{
i可数tmpRange;
tmpRange=Enumerable.Empty();
foreach(范围中的IEnumerable范围)
tmpRange=tmpRange.Union(范围);
tmpRange=tmpRange.OrderBy(number=>number);
返回新列表(tmpRange);
}
公共静态隐式运算符RangeCollection(列表范围)
{
返回新的范围集合(范围);
}
公共列表范围{get;private set;}
公共整数最大值
{
得到
{
返回范围.Max();
}
}
公共整数最小值
{
得到
{
返回范围.Min();
}
}
public System.Xml.Schema.XmlSchema GetSchema()
{
返回null;
}
public void ReadXml(System.Xml.XmlReader)
{
列表范围=新列表(100);
string elementName=“范围”;
版本;
version=version.Parse(reader.GetAttribute(“version”);
FoundVersion=版本;
if(reader.isemptyelment)返回;
reader.ReadStartElement(GetType().Name);
while(true)
{
if(reader.NodeType)