A lot of .NET assemblies ship with a reference only version which is stripped of actual code, and only has the metadata.
For example, I can find System.Core.dll at several locations on my machine, two of which are:
- C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Core.dll Size: 276 KB
- C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll Size: 1291 KB
The first one only has metadata, and loading it in default load context throws a BadImageFormat exception.
System.BadImageFormatException: Could not load file or assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context
Given the path to an assembly, is it possible to find out if it is a "reference assembly"?
I can check the path for keyword "Reference Assemblies", but that is hacky and won't work if the assembly is copied to a different location. I have the freedom to first load the assembly in reflection only context if that would help.