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.

5
  • 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. Commented Jan 9, 2018 at 14:08
  • Will CodeDom target the same framework as the project that is creating the .dll/exe dynamically? Commented Jan 22, 2018 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. Commented Jan 22, 2018 at 10:32
  • What if the multiple versions of .net are installed in the user's machine..will it target the latest version Commented Jan 22, 2018 at 12:26
  • There can be only one 4.x install. Commented Jan 22, 2018 at 12:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.