1

When I compile VB code using CodeDom, I need not specify fully qualified path for system references. For example:

Dim param As New CompilerParameters
param.ReferencedAssemblies.Add("System.dll")

works as expected.

But when I do the same using roslyn, it is expecting me to give a fully qualified path. For example:

MetadataReference.CreateFromFile("System.dll")

is throwing an exception.

I am not able to figure out how the Codedom is getting the fully qualified path for the system references.

Anoop
  • 101
  • 1
  • 10
  • 2
    CodeDom relies on the installed framework version with a standard path for the reference assemblies. Like it used to work in the olden days, c:\windows\microsoft.net\framework\v4.0.30319 directory. Also the basic reason why you can't target a higher framework version than 4 and why the compiled code cannot use recent language features. Roslyn does not have these limitations. – Hans Passant Jan 09 '18 at 14:08
  • Will CodeDom target the same framework as the project that is creating the .dll/exe dynamically? – Anoop Jan 22 '18 at 10:21
  • No, as noted it always targets the framework that's installed on the user's machine. This is possible because the compiler runs on the user's machine and not on your dev machine. If you generate code that requires a more recent framework version then you must select that version as your project target to force the user to install that framework version. This is a distinct concern from the C# language version. – Hans Passant Jan 22 '18 at 10:32
  • What if the multiple versions of .net are installed in the user's machine..will it target the latest version – Anoop Jan 22 '18 at 12:26
  • There can be only one 4.x install. – Hans Passant Jan 22 '18 at 12:35

0 Answers0