Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by TimyPastek · Mar 09, 2015 at 03:28 PM · standalonemonoassemblycompile

How to use CSharpCodeProvider in windows standalone?

Hello,

I try to dynamically compile C# code during execution with CSharpCodeProvider. It work fine in unity Editor but not in windows standalone My code is :

         CSharpCodeProvider provider = new CSharpCodeProvider();
         string source = "using System;" +
                         "public class MyClass" +
                         "{" +
                         "   public MyClass ()"+
                         "   {" +
                         "   }" +
                         "   public static string log()"+
                         "   {"+
                         "      return \"MyClass.log()\";"+
                         "   }"+
                         "}";
 
 
         CompilerParameters cParameters = new CompilerParameters();
         cParameters.ReferencedAssemblies.Add( "System.dll" );
         cParameters.GenerateExecutable = false;
         cParameters.OutputAssembly = "test.dll";
         CompilerResults cResults = provider.CompileAssemblyFromSource(cParameters, source);
     
         if (cResults.Errors.HasErrors)
         {
             foreach (CompilerError ce in cResults.Errors)
                 Debug.LogWarning ("Errors building :" + ce.ToString ());
         } else if (cResults.Errors.HasWarnings)
         {
             foreach (CompilerError ce in cResults.Errors)
                 Debug.LogWarning ("Warning building :" + ce.ToString ());
         } else
         {
             Assembly assembly = cResults.CompiledAssembly;
             System.Type type = assembly.GetType("MyClass");
             Debug.LogWarning( (string) type.InvokeMember("log", BindingFlags.InvokeMethod, null, assembly, null));
         }

And I have this error when I use windows standalone:

 FileNotFoundException: Windows mono path not found: C:\Users\guillaume\Stage\Projects\GUI3\mono\mono\mini\mono.exe
   at Mono.CSharp.CSharpCodeCompiler..cctor () [0x00000] in <filename unknown>:0 
 Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Mono.CSharp.CSharpCodeCompiler
   at Microsoft.CSharp.CSharpCodeProvider.CreateCompiler () [0x00000] in <filename unknown>:0 
 
   at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00000] in <filename unknown>:0 
 
   at Main.Start () [0x00000] in <filename unknown>:0 
  
 (Filename:  Line: -1)
 
 NullReferenceException: Object reference not set to an instance of an object
   at Main.OnApplicationQuit () [0x00000] in <filename unknown>:0 
  
 (Filename:  Line: -1)
 

Anyone having this problem?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheNoobieWaffle · Oct 04, 2017 at 03:32 AM 0
Share

Two and a half years later, this is stall an issue. Ever solve this?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by gregtom7 · Nov 12, 2017 at 02:56 PM

https://answers.unity.com/questions/364580/scripting-works-in-editor-try-it-but-not-build.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there any way to use CSharpCodeProvider in build? 0 Answers

How do you compile a managed dll with mono/mcs targeting .net 2.0 or 3.5 for Unity? 1 Answer

Best way to build a Mono assembly? 1 Answer

Standalone windows build giving mono: dll not found error 2 Answers

Can I use Monodevelop bundled with Unity to debug standalone .NET applications? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges