views:

131

answers:

1

I'm trying to dynamically compile some VB code in my C# project and I'm running into an issue with the VBCodeProvider. It doesn't seem to be honoring the OptionInfer flag that I'm putting in the providerOptions Dictionary.

My code looks like this:

var providerOptions = new Dictionary<string, string>();
providerOptions.Add("CompilerVersion", "v3.5");
providerOptions.Add("OptionInfer", "True");
var provider = new VBCodeProvider(providerOptions);

I set my CompilerParameters.TreatWarningsAsErrors to True, and I get the following error:

Variable declaration without an 'As' clause; type of Object assumed.

However, all is well when I put the "Option Infer On" text at the top of my dynamic source code.

Can anyone shed some light? Am I using the wrong providerOptions key or value? Is there some other setting somewhere else?

A: 

For lack of answers, I decided to plow through Reflector to see what was going on, and it turns out that CompilerVersion appears to be the only provider option that is referenced (in the RedistVersionInfo.GetCompilerPath method).

I was able to get the example working by using CompilerParameters.CompilerOptions member instead.

If there IS a way to do it, I'm all ears.

micahtan