2015-08-06 20 views
6
Ben 2015 Visual Studio aşağıdaki kod parçacığını ayıklama ediyorum

"adı geçerli bağlamda yok":Garip hata

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

son satırı bir NullReferenceException atar, bu yüzden hata ayıklama başladı ve tuhaf var durum:

Debugging screenshot

Yani, NullReferenceException atılır hattı, reader beyanı/başlatma altına çizgi, ben reader var olmadığını alıyorum.

Bu nasıl olabilir? Bilgisayarımı bile yeniden başlattım ve temizledim + projeyi bir düzine kez yeniden inşa ettim.

diğer bilgiler:

  • kod ReSharper'ın birim test rayları kullanan bir birim testi (NUnit) çalıştırılır.
  • Hedef çerçeve .NET 4 (test ve kod montaj ikisi)
  • xmlFileStream diş ilgili bir şey var gibi görünüyor çağrı yığını kadar

Ayrıca bu noktada iyi görünüyor (ben olduğum Nasıl kullanılır neden projeye yeterli bilgim yok henüz) belirlemek için:

İşte
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 
     }); 
    } 
} 

() ILSpy kullanılarak IL geçerli:

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

Sürüm oluşturma işleminde hata ayıklama özelliği var mı? –

+1

Son zamanlarda etrafta dolanan bazı garip JIT hataları var. IL ve ngened demontajı gönderir misiniz? –

+0

@Asad Bunlar, .NET 4.0 için geçerli olmaz, değil mi? –

cevap

0

Birisi, yapılandırmayı .sln dosyasında karıştırdı. Tüm projeler "etkin" yapılandırması debug olsa bile release yapılandırmasında oluşturulacak şekilde ayarlanmıştır.

Sürüm modunda .pdb dosyaları üretiyoruz, bu yüzden hata ayıklama işlemi hala bu kadar iyi çalıştı ... bu değişken gizemli bir şekilde kayboluncaya kadar.

İlgili konular