diff --git a/Mono.Cecil/AssemblyReader.cs b/Mono.Cecil/AssemblyReader.cs index 5cd3d1784..b66c1622e 100644 --- a/Mono.Cecil/AssemblyReader.cs +++ b/Mono.Cecil/AssemblyReader.cs @@ -3005,7 +3005,9 @@ ConstantDebugInformation ReadLocalConstant (uint rid) object value; if (type.etype == ElementType.String) { - if (signature.CanReadMore () && signature.buffer [signature.position] != 0xff) { + if (!signature.CanReadMore ()) + value = ""; + else if (signature.buffer [signature.position] != 0xff) { var bytes = signature.ReadBytes ((int) (signature.sig_length - (signature.position - signature.start))); value = Encoding.Unicode.GetString (bytes, 0, bytes.Length); } else diff --git a/Test/Mono.Cecil.Tests/PortablePdbTests.cs b/Test/Mono.Cecil.Tests/PortablePdbTests.cs index 43b8cfed2..d9786cb37 100644 --- a/Test/Mono.Cecil.Tests/PortablePdbTests.cs +++ b/Test/Mono.Cecil.Tests/PortablePdbTests.cs @@ -474,6 +474,23 @@ public void GenericInstConstantRecord () } } + [Test] + public void EmptyStringLocalConstant () + { + TestModule ("empty-str-const.exe", module => { + var type = module.GetType ("$"); + var method = type.GetMethod ("
$"); + var symbol = method.DebugInformation; + + Assert.IsNotNull (symbol); + Assert.AreEqual (1, symbol.Scope.Constants.Count); + + var a = symbol.Scope.Constants [0]; + Assert.AreEqual ("value", a.Name); + Assert.AreEqual ("", a.Value); + }, symbolReaderProvider: typeof (PortablePdbReaderProvider), symbolWriterProvider: typeof (PortablePdbWriterProvider)); + } + [Test] public void SourceLink () { diff --git a/Test/Resources/assemblies/empty-str-const.exe b/Test/Resources/assemblies/empty-str-const.exe new file mode 100644 index 000000000..6cc51287f Binary files /dev/null and b/Test/Resources/assemblies/empty-str-const.exe differ diff --git a/Test/Resources/assemblies/empty-str-const.pdb b/Test/Resources/assemblies/empty-str-const.pdb new file mode 100644 index 000000000..723ec4e12 Binary files /dev/null and b/Test/Resources/assemblies/empty-str-const.pdb differ