BadImageFormatException: Include Script using AssetBundle

Hi, I wanted to create a feature where we could import scripts I found this Unity Documentation that let us include scripts on an AssetBundle https://docs.unity3d.com/Manual/scriptsinassetbundles.html

-I’ve edited this much so that it will search my files not web.

-The DebugTest.txt is a c# script that I wanted to import in. its just a Debug.Log() script on an Update to see if its working.

-Had to change bundle.Load into bundle.LoadAsset because Unity says it deprecated.

-At first I got an error called NullReferenceException which means there is nothing inside this line of codes:

TextAsset txt = bundle.LoadAsset("debugTest", typeof(TextAsset)) as TextAsset;

that’s why I had to put an if statement to see if txt is not empty. which is now isn’t so Debug.Log (“txt has something inside”); is working. and so along with the log message. I got the error BadImageFormatException. which probably means. I’m in the right track? probably? cause it didn’t have any compiler error, but starting the game does.

-BadImageFormatException doesn’t give me a line of code error meaning when I click the console to see the line code error… nothing happens. so what I did is put Debug.Log at each and every line of codes after loading the textasset object. It worked and in the console it wen’t up to 1 and then the BadImageFormatException error which means the problem is assembly loading? maybe its deprecated?

this my simple script copied from the Unity Documentation.

using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class ScriptImporter : MonoBehaviour {
     string url ="file:///C:\\Users\\rhylvin2016\\Documents\\ScriptImporter Trial\\Assets\\AssetScripts\\script";
     IEnumerator Start ()
     {
         while (!Caching.ready)
             yield return null;
 
         // Start a download of the given URL
         WWW www = WWW.LoadFromCacheOrDownload (url, 1);
 
         // Wait for download to complete
         yield return www;
 
         // Load and retrieve the AssetBundle
         AssetBundle bundle = www.assetBundle;
 
         // Load the TextAsset object
         TextAsset txt = bundle.LoadAsset("debugTest", typeof(TextAsset)) as TextAsset;
 		if (txt != null)
	{
		Debug.Log ("txt has something inside");
	}
                     Debug.Log ("1");
         // Load the assembly and get a type (class) from it             
         var assembly = System.Reflection.Assembly.Load(txt.bytes);
                     Debug.Log ("2");
         var type = assembly.GetType("DebugTrial");
                     Debug.Log ("3");
         // Instantiate a GameObject and add a component with the loaded class
         GameObject go = new GameObject();
         go.AddComponent(type);
     }
 
 
 }

Hi, Did you resolve your issue? I faced with the same problem.