Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why isnt my assembly file loading?

Discussion in 'Scripting' started by UnityUser9860, Dec 13, 2017.

  1. UnityUser9860

    UnityUser9860

    Joined:
    Dec 8, 2015
    Posts:
    179
    Hello Im trying to get an external text file with this code in it, for modding purposes.
    Code (CSharp):
    1. public class code {
    2.  
    3. }
    To get the text file with the code im using this code
    Code (CSharp):
    1.  
    2. path = Path.Combine("", dirName + "/");
    3. var myLoadedAssetBundle = AssetBundle.LoadFromFile(path+ modName);
    4.  
    5. // Load the string object
    6. string txt = readTextFile(path+"code.txt");
    7.  
    8. Debug.Log(txt+":"+ path + "code.txt");
    9.  
    10. // Load the assembly and get a type (class) from it
    11. var assembly = System.Reflection.Assembly.Load(txt);
    12. var type = assembly.GetType("code");
    But its giving me this error
    Code (CSharp):
    1. FileNotFoundException: Could not load file or assembly 'public class code {' or one of its dependencies. The system cannot find the file specified.
    2. System.AppDomain.Load (System.String assemblyString, System.Security.Policy.Evidence assemblySecurity, Boolean refonly) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/AppDomain.cs:746)
    3. System.AppDomain.Load (System.String assemblyString) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/AppDomain.cs:728)
    4. (wrapper remoting-invoke-with-check) System.AppDomain:Load (string)
    5. System.Reflection.Assembly.Load (System.String assemblyString) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/Assembly.cs:576)
    6. ModSys.InstantiateMod (System.String modName, System.String dirName) (at Assets/ModSys.cs:90)
    7. ModSys.LoadModData () (at Assets/ModSys.cs:48)
    8. DataFileReader.LoadMods () (at Assets/Scripts/Mechanics/DataFileReader.cs:170)
    9. DataFileReader.Start () (at Assets/Scripts/Mechanics/DataFileReader.cs:45)
    Does anyone know why this is happening?
    Thank you in advance!
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539