0

Visual Studio 2015 Update 3, .Net 4.7.1. Referencing: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.1\Microsoft.CSharp.dll

CompilerParameters looks like:

_parameters.GenerateInMemory = true;
_parameters.GenerateExecutable = false;
_parameters.CompilerOptions = "/optimize";
_parameters.ReferencedAssemblies.Add("System.dll");
_parameters.ReferencedAssemblies.Add("System.ServiceModel.dll");

Trying to compile a snippet that looks like this:

SomeMethod(someClass.Exception.ToString());

This works fine.

However, when I try to compile:

SomeMethod(someClass.Exception?.ToString());

With the question mark added, I get compiler errors saying invalid expression term '.'. Is the ?. not supported? Or do I need to set some other option somewhere?

SledgeHammer
  • 7,338
  • 6
  • 41
  • 86
  • A little more information about the "duplicate". CodeDom doesn't support C# 6 or newer (because it is still using the "old" `csc.exe` of pre-Roslyn times from `C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe`), which you attempt to use a feature of. There are some options to deal with that (see duplicate). – Christian.K Mar 22 '18 at 17:36
  • @Christian.K That sucks. I started adding the Roslyn compiler, but then I saw the \rosyln directory. 14MB of extra crap is a bit too much bloat for my needs. I guess I'll just not use that syntax. – SledgeHammer Mar 22 '18 at 19:13

0 Answers0