Il2CppInterop icon indicating copy to clipboard operation
Il2CppInterop copied to clipboard

Loading asset bundles: System.ArgumentNullException: Value cannot be null. (Parameter 'meth')

Open MeblIkea opened this issue 1 year ago • 13 comments

What happened?

Hello! I'm trying to import an asset bundle into an IL2CPP game (built with Unity 2020.3.18 targeting Windows). Well I'm trying via RessourceStream (*note that the exact same error occurs with AssetBundle.LoadFromFile), and I have the following error.

namespace JarodMod;

[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
public class Plugin : BasePlugin
{
    internal static new ManualLogSource Log;

    public override void Load()
    {
        // Plugin startup logic
        Log = base.Log;
        Log.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded UPDATED!");
        Harmony.CreateAndPatchAll(typeof(Plugin));

        // AssetBundle
        using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("JarodMod.jarodbundle");
        var assetBundle = AssetBundle.LoadFromMemory(stream!.ReadBytes());

        Log.LogInfo("AssetBundle loaded successfully.");
    }
}

I've built the Asset Bundle using the same version as the game (mentioned above). I hope you'll be able to help me with this issue. Thanks!

BepInEx Distribution

Bleeding Edge from BepisBuilds

Log outputs

[Error  :   BepInEx] Error loading [Jarod 1.0.0]: System.ArgumentNullException: Value cannot be null. (Parameter 'meth')
   at System.Reflection.Emit.DynamicILGenerator.Emit(OpCode opcode, MethodInfo meth)
   at Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase.InitializerStore`1.Create() in /home/runner/work/Il2CppInterop/Il2CppInterop/Il2CppInterop.Runtime/InteropTypes/Il2CppObjectBase.cs:line 124
   at Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase.InitializerStore`1.get_Initializer() in /home/runner/work/Il2CppInterop/Il2CppInterop/Il2CppInterop.Runtime/InteropTypes/Il2CppObjectBase.cs:line 146
   at Il2CppInterop.Runtime.Runtime.Il2CppObjectPool.Get[T](IntPtr ptr) in /home/runner/work/Il2CppInterop/Il2CppInterop/Il2CppInterop.Runtime/Runtime/Il2CppObjectPool.cs:line 40
   at UnityEngine.AssetBundle.LoadFromMemory_Internal(Il2CppStructArray`1 binary, UInt32 crc)
   at UnityEngine.AssetBundle.LoadFromMemory(Il2CppStructArray`1 binary)
   at JarodMod.Plugin.Load() in E:\SteamLibrary\steamapps\common\Road 96\BepInEx\plugins\JarodMod\Plugin.cs:line 28
   at BepInEx.Unity.IL2CPP.IL2CPPChainloader.LoadPlugin(PluginInfo pluginInfo, Assembly pluginAssembly) in /home/runner/work/BepInEx/BepInEx/Runtimes/Unity/BepInEx.Unity.IL2CPP/IL2CPPChainloader.cs:line 134
   at BepInEx.Bootstrap.BaseChainloader`1.LoadPlugins(IList`1 plugins) in /home/runner/work/BepInEx/BepInEx/BepInEx.Core/Bootstrap/BaseChainloader.cs:line 411

Environment

- OS: Windows 10 22H2
- BepInEx: 6.0.0-be.697 (build commit `53625800b86f6c68751445248260edf0b27a71c2`)
- Game: Road 96

MeblIkea avatar Aug 27 '24 11:08 MeblIkea

Btw, tell me if you need more info, or if I can speed up the process in any way :D

MeblIkea avatar Sep 10 '24 17:09 MeblIkea

Sorry, your issue is outside my area of expertise; I was just labeling GitHub issues. I primarily focus on the generator portion of the codebase.

ds5678 avatar Sep 11 '24 00:09 ds5678

Was there ever a solution to this?

MaxHoliday avatar Apr 01 '25 15:04 MaxHoliday

Was there ever a solution to this?

In order to get Asset Bundles when you get this error, you can use this lib https://github.com/yukieiji/UniverseLib

MeblIkea avatar Apr 05 '25 09:04 MeblIkea

The issue should be resolved. I merged a pr 3 months ago which was supposed to fix this.

ds5678 avatar Apr 05 '25 09:04 ds5678

The issue should be resolved. I merged a pr 3 months ago which was supposed to fix this.

I haven't really had the occasion to try it since. Let's say it works

MeblIkea avatar Apr 05 '25 09:04 MeblIkea

The issue should be resolved. I merged a pr 3 months ago which was supposed to fix this.

I updated to latest BIE Bleeding Edge, and still got the issue D:

I tried loading my Asset Bundle like that this time:

var dogBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "dog"));
        
if (dogBundle == null)
{
      Debug.Log("Failed to load AssetBundle!");
      return;
}
var dogMat = (Material)dogBundle.Load<Material>("dog_mat");

Image

Sorry for not testing before D:

MeblIkea avatar Apr 16 '25 16:04 MeblIkea

The issue should be resolved. I merged a pr 3 months ago which was supposed to fix this.

I updated to latest BIE Bleeding Edge, and still got the issue D:

Are you sure the BIE Bleeding Edge uses the latest Interop commit?

ds5678 avatar Apr 16 '25 18:04 ds5678

No, but I'm not sure how to switch to latest Interop.

MeblIkea avatar Apr 17 '25 13:04 MeblIkea

I think the current version of MelonLoader uses an Interop build with the commit that fixed your issue.

Alternatively, you can build Bepinex from source and update the version before building.

ds5678 avatar Apr 17 '25 13:04 ds5678

Can you not just update BepInEx to actually reflect these changes? It's kinda annoying having to build BepInEx and not being able to properly publish the plugin dll.

MaxtorCoder avatar Apr 25 '25 14:04 MaxtorCoder

Can you not just update BepInEx to actually reflect these changes?

I do not have the permissions required for this action.

ds5678 avatar Apr 25 '25 14:04 ds5678

Can you not just update BepInEx to actually reflect these changes?

I do not have the permissions required for this action.

Guess I'll have to wait then until it's fixed for BepInEx, that is the only part that I am stuck on atm and I cannot use MelonLoader as I cannot use that DLL in Unity for custom component scripts.

MaxtorCoder avatar Apr 25 '25 14:04 MaxtorCoder