2

Short: Which assemblies (Framework DLLs) are included by default in .NET CodeDom Compilers (CSharpCodeProvider or VBCodeProvider) without explicitely adding the reference to CompilerParameters?


I am using the CodeDom tools, namely CSharpCodeProvider and VBCodeProvider, to compile assemblies at runtime. I noticed, that some but not all .NET reference assemblies are included by default.

I can use everything in System.dll without adding the reference in the CompilerParameters but nothing from System.Numerics.dll for example. For the latter I need to add params.ReferencedAssemblies.Add("System.Numerics.dll") to my code.

Hence my question: How do I know, which assemblies are referenced by default, and which are not?

Relevant code:

This code can be compiled without added references:

Imports System
Public Class Foo
    Public Sub TestClass
        Dim t = Tuple.Create(23,241)
    End Sub
End Class

This code can not:

Imports System
Imports System.Numerics
Public Class Foo
    Public Sub TestClass
        Dim t = Tuple.Create(23,241)
        Dim n As New Complex(32,112)
    End Sub
End Class

The code I use to compile (abbreviated):

Dim params As New CompilerParameters()
'The path of the assembly to create
params.OutputAssembly = active.OutputName

'Compile as dll
params.GenerateExecutable = False

Dim vb As New VBCodeProvider
Dim res = vb.CompileAssemblyFromSource(params, active.Code)
Jens
  • 6,275
  • 2
  • 25
  • 51
  • I think the answer is None. Though it has been a while, every article I recall reading added even System to the mix. – Ňɏssa Pøngjǣrdenlarp Apr 01 '15 at 19:45
  • @Plutonix That would be the expected thing. The `ReferencedAssemblies` collection of CompilerParameters is empty to begin with as well. But in the code to compile I can use namespaces like `System`, `System.IO` and so on without explicitely referencing `System.dll`. – Jens Apr 02 '15 at 06:12

0 Answers0