basic-reference-assemblies icon indicating copy to clipboard operation
basic-reference-assemblies copied to clipboard

What is the difference between 'DependencyContext' and 'basic-reference-assemblies'?

Open NMSAzulX opened this issue 3 years ago • 3 comments

Hello. I am using DependencyContext .Default .CompileLibraries to get references. which namespace in Microsoft.Extensions.DependencyModel.

It works(However, there are some fields or attributes whose metadata cannot be found during dynamic compilation).

What is the difference between Microsoft.Extensions.DependencyModel and basic-reference-assemblies?

NMSAzulX avatar May 11 '21 02:05 NMSAzulX

Can you link to any docs to that API? I'm unfamiliar with that so hard to say how it relates to this project.

jaredpar avatar May 19 '21 01:05 jaredpar

@jaredpar https://github.com/dotnet/runtime/tree/main/src/libraries/Microsoft.Extensions.DependencyModel

When I used dynamic compilation before, the roslyn error could not find the object reference. For dynamic compilation is a very troublesome thing, currently I use


foreach (var asm in DependencyContext
            .Default
            .CompileLibraries
            .SelectMany(cl => cl.ResolveReferencePaths()))
            {
                DomainManagement.Default.AddReferencesFromDllFile(asm);
            }

this code to solve the problem.

NMSAzulX avatar May 19 '21 01:05 NMSAzulX

When I use the dll file provided by DependencyContext to reflect private fields, such as _size of List<int>. It will indicate that this field cannot be found. So I have to reload typeof (List<int>). Assenbly.Location into the reference to find _size;. I suspect DependencyContext can't provide metadata other than public level, or I'm not familiar with it.

NMSAzulX avatar May 19 '21 01:05 NMSAzulX