Problem with System.CodeDom in C#

Hey,

I'm currently playing around with dynamic c# code creation, which I've used successfully in non-Unity programming. However, when I try to use any classes from the System.CodeDom namespace Unity doesn't seem to be able to find it. For example, the following line of code:

System.CodeDom.Compiler.CompilerParameters compilerParams;

Gives the following error:

Assets/ScriptLoader.cs(8,33): error CS0234: The type or namespace name `CompilerParameters' does not exist in the namespace`System.CodeDom.Compiler'. Are you missing an assembly reference?

I've checked which assembly System.CodeDom is located in and it seems it should be System.dll. The Unity Script Reference for Mono Compatibility also seems to indicate that System.CodeDom should be supported.

All in all, I have no idea what, if anything, I am doing wrong, and any help would be greatly appreciated.

Thanks,

Wibbs

For anyone wondering, the fix is to explicitly set the api compatibility level to .NET 4.x under Edit → Project Settings → Player

Hmm, just tried it and it seems that it works in an editor script but not in a runtime script. I haven't used System.CodeDom yet so i don't know anything about it, but i guess it's not supported by the Unity-Engine.


edit

Just figured it out :wink:

My test project works still with the “.NET subset” option. Just go to EditProject SettingsPlayer and select the .NET option under Optimization.