Roslyn CSharpScript and DateTime Reference error

453 views Asked by At

error CS0246: The type or namespace name 'DateTime' could not be found (are you missing a using directive or an assembly reference?)

When running the following code:

        public string DateCalculationString
        {
            get => _dateCalculationString;
            set
            {
                var options = ScriptOptions.Default.AddReferences(typeof(DateTime).Assembly);
                **var task = CSharpScript.EvaluateAsync<Func<string, DateTime>>(value, options);**
                DateCalculation = task.GetAwaiter().GetResult();
                _dateCalculationString = value;
            }
        }

It appears I am adding the reference incorrectly. Can someone point me in the right direction?

1

There are 1 answers

0
JasonDWilson On

Apparently I needed a reference and an import:

   var options = ScriptOptions.Default.AddReferences("System").AddImports("System");