Well, I finally have generics working again…sort of, and currently only in Net Framework apps. Unfortunately, I’m back in dll/assembly hell. When I try to find List<> in Net Core’s System.Collections.dll, it isn’t there. Where is it? And, why am I even looking in the file if Campy BCL has a replacement?
Starting with a specific example, and using DotPeek of the Campy Net Core test program ConsoleApp1/bin/Debug/netcoreapp2.0/win-x64/publish/ConsoleApp1.dll, this is what I can figure out:
- The metadata for TypeRef table containing List`1 in “ConsoleApp1.dll” says the type is in AssemblyRef 0x23000004, major version 4, minor version 1, name “System.Collections”. Since “publish” is a self-contained app, I open “System.Collections.dll” in the same directory.
- DotPeek of “System.Collections.dll” indicates it does not define a type “List`1”. So, looking at the TypeRef’s and AssemblyRef’s in the metadata, it should be in AsmRef 0x23000001, System.Private.CoreLib, major version 4, minor version 0.
- DotPeek of “System.Private.CoreLib.dll” indicates it defines a type “List`1”, and this is in fact where implementation for List<> lives. (Note, List`1 is way down in the TypeDef’s table with id 0x0200040e. So using DotPeek to find the type is basically impossible, because the “find” function in DotPeek crashes with this file. I’m writing a program called Campy.Find that will help with these kinds of queries.)
In fact, there’s already a bit of kludgy code in Campy that does something like this, between “public static IntPtr GetBclType(Type type)” in C# code that looks up the type hierarchy to load in specific files and types, and “function_space_specifier tMetaData* CLIFile_GetMetaDataForAssembly(char * fileName)” in C code within DNA that loads an assembly, probing if needed. But, clearly, it should all be done in DNA. Fortunately, DNA can load files from the host OS file system since I do provide a wrapper for DNA that is called from C#.
Once I have this search coded up in DNA–and patching up DNA to read FieldMarshal tables, which are in System.Private.CoreLib.dll–I’m hoping generics will generally start to work, and the code a little cleaner to boot.