2
Vote

Assembly DeepCopy Infinite Recursion for Portable Libraries

description

I'm seeing StackOverflowException when using MetadataCopier.DeepCopy on a Portable Class Library. The overflow occurs when the namespace name and mangled name passed to Microsoft.Cci.MetadataReader.PEFileToObjectModel.ResolveNamespaceTypeDefinition are System.Runtime and DebuggableAttribute.

The Recursive Calls
Microsoft.Cci.PeReader.dll!Microsoft.Cci.MetadataReader.ObjectModelImplementation.NamespaceTypeNameTypeReference.Resolve() Line 580 + 0x32 bytes
Microsoft.Cci.PeReader.dll!Microsoft.Cci.MetadataReader.ObjectModelImplementation.NamespaceTypeNameTypeReference.ResolvedType.get() Line 656 + 0x8 bytes
Microsoft.Cci.PeReader.dll!Microsoft.Cci.MetadataReader.ObjectModelImplementation.NamespaceTypeNameTypeReference.Microsoft.Cci.INamedTypeReference.ResolvedType.get() Line 703 + 0x9 bytes
Microsoft.Cci.PeReader.dll!Microsoft.Cci.MetadataReader.PEFileToObjectModel.ResolveNamespaceTypeDefinition(Microsoft.Cci.IName namespaceName, Microsoft.Cci.IName mangledTypeName) Line 1367 + 0x29 bytes
Reproduction

You can reproduce the bug by running the following program on the attached project (which is a a portable class library with a single class that contains a single autogenerated property).
static void Main(string[] args)
{
     IMetadataHost host = (IMetadataHost) new PeReader.DefaultHost();
     IModule module = host.LoadUnitFrom(args.Last()) as IModule;
     var copy = MetadataCopier.DeepCopy(host, module);
}
Thanks,
Todd

file attachments

comments

tschiller wrote Feb 13, 2013 at 6:20 AM

I misread the debugger -- the bad values appear to be:

namespaceName: System.DiagnosticsmangledTypeName: DebuggableAttribute

tschiller wrote Feb 13, 2013 at 6:51 AM

The attribute that is causing problems is:

.custom instance void [System.Runtime]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00)

When the attribute is from mscorlib (as for the MishraReader.exe from the same project), the DeepCopy works properly:

.custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00)

tschiller wrote Feb 19, 2013 at 6:58 AM

I suspect I'll need to write a custom host to use the portable libraries instead of the default core libraries.

tshaug wrote Feb 5, 2015 at 7:49 PM

Hi,

I ran into the same problem with a portable lib. Can anybody give me some advice... (like how to write a custom host)?

Thnak you very muchThomas

tschiller wrote Feb 14, 2015 at 2:39 PM

I got it working by writing a PortableHost referring to the portable mscorlib. See here: https://code.google.com/p/daikon-dot-net-front-end/source/browse/Celeriac/Celeriac/PortableHost.cs

The main change appears in the definition of the CoreAssemblySymbolicIdentity property.