Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with Unity on Android #348

Open
yt6983138 opened this issue Nov 4, 2023 · 2 comments
Open

Error with Unity on Android #348

yt6983138 opened this issue Nov 4, 2023 · 2 comments

Comments

@yt6983138
Copy link

I tried to use this on Unity on Android, and I end up with error like this:

11-04 18:47:23.718  4156  4301 E Unity   : TypeLoadException: Could not load type of field 'CSScriptLib.Runtime:CreateUnloadableAssemblyLoadContext' (2) due to: Could not resolve type with token 0100003e from typeref (expected class 'System.Runtime.Loader.AssemblyLoadContext' in assembly 'System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') assembly:System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type:System.Runtime.Loader.AssemblyLoadContext member:(null)
11-04 18:47:23.718  4156  4301 E Unity   :   at CSScriptLib.CodeDomEvaluator+<>c__DisplayClass7_0.<ReferenceAssembly>b__0 (System.String x) [0x00000] in <2d2b17d233f24918b1e8f6536596dfe2>:0
11-04 18:47:23.718  4156  4301 E Unity   :   at System.Linq.Enumerable.TryGetFirst[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate, System.Boolean& found) [0x0003f] in <22d097c9c77e4fb3988dec23d55249ed>:0
11-04 18:47:23.718  4156  4301 E Unity   :   at System.Linq.Enumerable.FirstOrDefault[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x00000] in <22d097c9c77

However, it runs completely fine on windows, here my code is:

IScript script = (IScript)CSScript.Evaluator.LoadCode(
    (string)Skins.ReadSkin().Properties[AssignedObject.name][Resource.keyRefrence["Execute"]]
);
AssignedObject.GetComponent<Button>().onClick.AddListener(delegate
{
    script.Execute(AssignedObject);
});
// Can be turned into this(simplified code): --------------------------------------------------------
IScript script = (IScript)CSScript.Evaluator.LoadCode(
    "using System; using UnityEngine; using UnityEngine.SceneManagement; class Script : IScript { public void Execute(GameObject obj) { SceneManager.LoadScene(\"Settings\"); } }" 
    //sorry for 1 line code
);
script.Execute(GameObjectHere); // type GameObject is defined in UnityEngine
// interface IScript -------------------------------------------------------
public interface IScript
{
    public void Execute(GameObject obj);
}

Also I tried both roslyn and codedom evaluator, neither of them works.
btw, what I'm trying to do is make a scripting engine on my game, which user can define what to do when button clicked.
Configuration:
Mono compiler(didn't try il2cpp because obviously it wouldn't work), android 11 with root access, 6g ram on phone, Unity 2022.3.10f1

ps: if i didnt reply for a long time its prob because 11.5hrs of school every weekday 😭

@oleg-shilo
Copy link
Owner

It looks like there is a difference between an Android and a desktop .NET distro.
Not sure if there is a work around

@yt6983138
Copy link
Author

aw, i guess ill have to leave scripting feature in my game unimplemented
thanks for the reply anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants