Frage

Wir sehen einen Absturz, wenn sie in einer C # Bibliothek eine Instanz der Klasse System.Xml.Serialization.XmlSerializer instanziieren. Der Absturz tritt im Konstruktor, wenn er versucht, einen doppelten Schlüssel zu einem Wörterbuch hinzuzufügen. Ich habe einen Stack-Trace enthalten.

Dieser Absturz auftritt nur auf einer Maschine, und unsere Installation der Reparatur .NET 3.5 hat nicht geholfen. Hat jemand irgendwelche ähnliche Probleme gesehen?

System.ArgumentException was unhandled
  Message="Item has already been added. Key in dictionary: 'mainbuild'  Key being added: 'mainbuild'"
  Source="mscorlib"
  StackTrace:
       at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
       at System.Collections.Hashtable.Add(Object key, Object value)
       at System.Collections.Specialized.StringDictionary.Add(String key, String value)
       at System.CodeDom.Compiler.Executor.ExecWaitWithCaptureUnimpersonated(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine)
       at System.CodeDom.Compiler.Executor.ExecWaitWithCapture(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine)
       at Microsoft.CSharp.CSharpCodeGenerator.Compile(CompilerParameters options, String compilerDirectory, String compilerExe, String arguments, String& outputFile, Int32& nativeReturnValue, String trueArgs)
       at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)
       at Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources)
       at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters options, String[] sources)
       at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource(CompilerParameters options, String[] sources)
       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.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace)
       at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
       at System.Xml.Serialization.XmlSerializer..ctor(Type type)
       at OurTools.Tools.Common.XML.DataAccess`1.DeserializeFromXml(String strFilePath) in c:\AutomatedBuild\projects\1.0\OurTools.Tools.Common\OurTools.Tools.Common\XML\DataAcess.cs:line 100
       at OurTools.Tools.Common.ProjectFileManager.GetProjectInfoModel() in c:\AutomatedBuild\projects\1.0\OurTools.Tools.Common\OurTools.Tools.Common\ProjectFileManager.cs:line 252
       at OurTools.Tools.Common.ProjectFileManager.GetAvailableCultures() in c:\AutomatedBuild\projects\1.0\OurTools.Tools.Common\OurTools.Tools.Common\ProjectFileManager.cs:line 299
       at OurAppLib.GeneratorOptions.DefaultCultures() in c:\AutomatedBuild\projects\1.0\OurApp\OurAppLib\GeneratorOptions.cs:line 192
       at OurAppLib.GeneratorOptions.ReadCulturesFromArgs(List`1 arglist, String& errormsg) in c:\AutomatedBuild\projects\1.0\OurApp\OurAppLib\GeneratorOptions.cs:line 358
       at OurAppLib.GeneratorOptions.ReadFromArgs(String[] args, String& errormsg) in c:\AutomatedBuild\projects\1.0\OurApp\OurAppLib\GeneratorOptions.cs:line 261
       at OurApp.Program.Main(String[] args) in c:\AutomatedBuild\projects\1.0\OurApp\OurApp\Program.cs:line 76`print("code sample");`
War es hilfreich?

Lösung

Gefunden auf diesen Link, der die Frage erklärt: http: //social.msdn .microsoft.com / Foren / en-US / asmxandxml / thread / 4476f044-bab9-492d-bb94-4e0960bd2d26

Eine kurze Zusammenfassung: Wenn die Serialisierung, macht die Aufgabe, ein Wörterbuch aus allen Umgebungsvariablen, scheint aber eine ToLower () auf alle Einträge zu laufen. Also, wenn Sie zwei Umgebungsvariablen, die die gleichen, außer für Gehäuse sind, werden Sie zu einem Absturz kommen.

Das wird nur ein Problem, wenn von innen ein System wie Cygwin laufen, die für Variablen Groß- und Kleinschreibung erzwingt. In unserem Fall verwenden wir machen.

Es gibt ein paar Lösungen, aber sie alle drehen sich um dafür zu sorgen, dass Ihre Umgebung hat keine duplizierten Variablen, wenn Ihre c # app läuft.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top