How can I load System.CodeDom.CodeCompileUnit?

Hey All,

I am trying to use the System.CodeDom to compile some code dynamically. I have an external DLL that handles all the CodeDom related code, and I am referencing that in my Unity project. However, when I implement the code using that DLL, when I switch back to Unity it throws this error:

Internal compiler error. See the console log for more information. output was:
Unhandled Exception: System.TypeLoadException: Could not load type 'System.CodeDom.CodeCompileUnit' from assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
  at (wrapper managed-to-native) System.MonoType:GetMethodsByName (string,System.Reflection.BindingFlags,bool,System.Type)....

You’ll see in that exception that it says Version=2.0.0.0 That is because I recompiled my DLL to target .Mono 2.0 instead of Mono 4.0, thinking that would help, but it didnt.

I already checked that my Edit → Project Settings → Player Settings → .NET 2.0 Subset was checked, per a previous post on here.

Any suggestions on how to fix this issue?

1 Answer

1

Well, after typing this out and reading it I realized that when the previous post said ‘Make sure that in your settings .NET 2.0 Subset is checked’ that it probably meant, make sure its NOT checked. It didnt seem right that I would want a Subset, I want the whole thing. So I changed that to .NET 2.0 and NOT .NET 2.0 Subset, rebuilt my DLLs for Mono 4.0 and now it works!

Here is the other question that confused/helped me. Problem with System.CodeDom in C# - Questions & Answers - Unity Discussions