Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by godfreyidk · Sep 26, 2019 at 07:18 AM · compile

Why does codeDom generated class NOT COMPILE

I was able to generate and compile generated classes with unity 2019.1. But with 2019.2 the generated class does not want to compile. It just remains with that orange hue on its tab in the Rider editor.

Here are the important class methods responsible for generating some dynamic class:

 private static void CreateBaseGetterClass(string wrappedCompName)
 {
     CodeDomProvider provider = new CSharpCodeProvider();
     CompilerParameters compileParams = 
     CreateCompilerParams();
             
     string sourceCode = "";
     sourceCode += "using UnityEngine;\n";
     sourceCode += "using 
     _Monobehaviours.Abstract_Implementations;\n";
     sourceCode += "using 
     _ScriptableObjects.Implementations.Variables;\n\n";
     sourceCode += "namespace 
     _ScriptableObjects.Abstractions\n";
     sourceCode += "{\n\tpublic abstract class " + 
     _baseGetterClassPrefix + 
     CreateCompName(wrappedCompName) + 
     _baseGetterClassNameSuffix + " : " + 
     $"GetsADataComponent<{
     CreateCompName(wrappedCompName)}>\n";
     sourceCode += "\t{\n"; 
     sourceCode += $"\t\tpublic override 
     {CreateCompName(wrappedCompName)} 
     GetDataComp(ExperiTickerOfStateActions ticker)\n"; 
     sourceCode += "\t\t{\n"; 
     sourceCode += $"\t\t\tif ( !Key.In(ticker.Data, 
     WantedCompKey) ) return null;\n\n"; 
     sourceCode += 
     $"\t\t\t{CreateCompName(wrappedCompName)} 
     {LowerCaseStartedStr(wrappedCompName)} = 
     ticker.Data.Components[WantedCompKey.Value.GetType()].
     Value as {CreateCompName(wrappedCompName)};\n\n"; 
     sourceCode += $"\t\t\treturn ! 
     {LowerCaseStartedStr(wrappedCompName)} ? null : 
     {LowerCaseStartedStr(wrappedCompName)};\n"; 
     sourceCode += "\t\t}\n";
     sourceCode += "\t}\n";
     sourceCode += "}";
             
     WriteAbstractSourceToCsFile(wrappedCompName, 
     sourceCode, provider, compileParams);
 }
         
 private static CompilerParameters CreateCompilerParams()
 {
     CompilerParameters compileParams = new 
     CompilerParameters();
        
     compileParams.GenerateInMemory = true;
     compileParams.GenerateExecutable = false;
             
     compileParams.ReferencedAssemblies.Add("System.dll");
             
     return compileParams;
 }
 
 private static void WriteAbstractSourceToCsFile(string compTypeName, string sourceCodeString, CodeDomProvider provider, CompilerParameters compileParams)
 {
     string classNamePrefix = _baseGetterClassPrefix + 
     CreateCompName(compTypeName) + 
     _baseGetterClassNameSuffix;
             
     string scriptPath = Application.dataPath;
     scriptPath += $"/Scripts/_ScriptableObjects/Abstractions/{
     classNamePrefix}";
     scriptPath += ".cs";
             
     System.IO.File.WriteAllText(scriptPath, sourceCodeString);
             
     provider.CompileAssemblyFromSource(compileParams, 
     sourceCodeString);
 }


And here's a picture of the generated class that remains uncompiled: alt text

class-does-not-compile-in-unity-project-solution.png (297.6 kB)
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

180 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

failed to re pack resources 0 Answers

Error at building and executing project. 0 Answers

My playmode is not running there are an error,I write a script to print i use "Debug.Log" 0 Answers

error CS0117: System.Collections.ObjectModel.Collection> does not contain a definition for Items 0 Answers

Alternative to EditorWindow.OnDisable to run before compiling 2 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