2015-08-06 10 views
6

jestem debugowanie następujący fragment kodu w Visual Studio 2015:Weird „nazwa nie istnieje w bieżącym kontekście” bug

Stream xmlFileStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceFilePath); 
if (xmlFileStream != null) 
{ 
    var reader = XmlReader.Create(xmlFileStream); 
    XDocument schemaDefinition = XDocument.Load(reader); // NullReference 
    ... 

Ostatnia linia rzuca się NullReferenceException, więc zacząłem debugowanie i mam najdziwniejsza sytuacja:

Debugging screenshot

Tak, linia, gdzie NullReferenceException jest wyrzucane, linia poniżej deklaracji/inicjalizacji reader, dostaję że reader nie istnieje.

Jak to jest możliwe? Nawet zrestartowałem komputer i oczyściłem + przebudowałem projekt kilkanaście razy.

Więcej informacji:

  • Kod jest uruchamiany z testów jednostkowych (NUnit) za pomocą testów jednostkowych biegaczy ReSharper jest.
  • ramy docelowa jest .NET 4 (oba testy i montaż kod)
  • xmlFileStream wygląda dobrze w tym momencie

dalej w górę stosu wywołań nie wydaje się być coś związanego z wątków (jestem nie tyle z projektem zna jeszcze do ustalenia, dlaczego jest używany):

lock (Threadlock) 
{ 
    if (!SchemaConfigurations.Keys.Contains(dialect)) 
    { 
     SchemaConfigurations.Add(dialect, new SchemaConfiguration 
     { 
      /*DOING THIS*/ MessageStructureConfigurations = ReadMessageStructureConfiguration(dialect), 
      SegmentConfigurations = ReadSegmentConfiguration(dialect), 
      DataTypeConfigurations = ReadDataTypeConfiguration(dialect), 
      MessageTypeLocation = _messageTypeLocation, 
      TriggerEventLocation = _triggerEventLocation 
     }); 
    } 
} 

Oto IL (używając ILSpy):

IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1<class Ihc.Integration.ParserBuilder.Hl7.Core.SchemaConfigurations.Domain.SegmentConfiguration>::.ctor() 
IL_0005: stloc.0 
IL_0006: newobj instance void class [mscorlib]System.Collections.Generic.List`1<class Ihc.Integration.ParserBuilder.Hl7.Core.SchemaConfigurations.Domain.SegmentConfiguration>::.ctor() 
IL_000b: stloc.1 
IL_000c: ldstr "{0}.Hl7.Core.SchemaConfigurations.Schemas.{1}_Segments.xml" 
IL_0011: call class [mscorlib]System.Reflection.Assembly [mscorlib]System.Reflection.Assembly::GetExecutingAssembly() 
IL_0016: callvirt instance class [mscorlib]System.Reflection.AssemblyName [mscorlib]System.Reflection.Assembly::GetName() 
IL_001b: callvirt instance string [mscorlib]System.Reflection.AssemblyName::get_Name() 
IL_0020: ldarg.0 
IL_0021: box Ihc.Integration.ParserBuilder.Hl7.Interfaces.SupplierType 
IL_0026: call string [mscorlib]System.String::Format(string, object, object) 
IL_002b: stloc.2 
IL_002c: call class [mscorlib]System.Reflection.Assembly [mscorlib]System.Reflection.Assembly::GetExecutingAssembly() 
IL_0031: ldloc.2 
IL_0032: callvirt instance class [mscorlib]System.IO.Stream [mscorlib]System.Reflection.Assembly::GetManifestResourceStream(string) 
IL_0037: stloc.3 
IL_0038: ldloc.3 
IL_0039: brfalse IL_0339 

IL_003e: ldloc.3 
IL_003f: call class [System.Xml]System.Xml.XmlReader [System.Xml]System.Xml.XmlReader::Create(class [mscorlib]System.IO.Stream) 
IL_0044: call class [System.Xml.Linq]System.Xml.Linq.XDocument [System.Xml.Linq]System.Xml.Linq.XDocument::Load(class [System.Xml]System.Xml.XmlReader) 
IL_0049: stloc.s 4 
IL_004b: ldloc.s 4 
+4

Czy debugujesz kompilację wydania przez przypadek? –

+1

Ostatnio pojawiły się dziwne błędy JIT. Czy możesz opublikować IL i nierozpoznany demontaż? –

+0

@Asad Te nie miałyby zastosowania do .NET 4.0, prawda? –

Odpowiedz

0

Ktoś zepsuł konfigurację w pliku .sln. Wszystkie projekty miały być skonfigurowane w konfiguracji release, nawet jeśli "aktywna" konfiguracja była debug.

Generujemy pliki .pdb w trybie zwolnienia, dlatego debugowanie nadal działało dobrze ... dopóki ta jedna zmienna nie zniknie w tajemniczy sposób.

Powiązane problemy