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

Failed to create EntityStore in runtime compiled code #17

Open
inmny opened this issue Sep 24, 2024 · 3 comments
Open

Failed to create EntityStore in runtime compiled code #17

inmny opened this issue Sep 24, 2024 · 3 comments

Comments

@inmny
Copy link

inmny commented Sep 24, 2024

I tried to use your framework(netstandard 2.1) in a unity mod. The mod is compiled and loaded at runtime.

The mod is compiled with "allow unsafe code" on Windows.

Framework version:

  • 3.0.0-preview.13
  • 3.0.0-preview.10
  • 2.2.0

Dependencies version:

  • Friflo.Json.Burst 1.0.2
  • Friflo.Json.Fliox 1.0.2
  • Friflo.Json.Fliox.Annotation 1.0.2
  • System.Runtime.CompilerServices.Unsafe 5.0.2/6.0.0

Log:

[Error  : Unity Log] [NML]: The type initializer for 'Static' threw an exception.
[Error  : Unity Log] [NML]:   at Friflo.Engine.ECS.EntityStoreBase..ctor () [0x00022] in <2760b6615674441eb080f0fb778cfc66>:0
  at Friflo.Engine.ECS.EntityStore..ctor (Friflo.Engine.ECS.PidType pidType) [0x00000] in <2760b6615674441eb080f0fb778cfc66>:0
  at Friflo.Engine.ECS.EntityStore..ctor () [0x00000] in <2760b6615674441eb080f0fb778cfc66>:0
  at Cultiway.ModClass.OnModLoad () [0x00001] in Source\ModClass.cs:13

Code:

using Friflo.Engine.ECS;
using NeoModLoader.api;
using UnityEngine;

namespace Cultiway
{
    internal class ModClass : BasicMod<ModClass>
    {
        protected override void OnModLoad()
        {
            var world = new EntityStore();
            world.CreateEntity<Velocity>(new Velocity() { val = new(1, 1, 1) });
        }
    }

    struct Velocity : IComponent
    {
        public Vector3 val;
    }
}

What should I do for more detailed information?

@friflo
Copy link
Owner

friflo commented Sep 24, 2024

To get more info about the TypeInitializationException add a try / catch and log its InnerException property.
The log should contain the exception class Name, the Message and StackTrace.
In case its InnerException is not null it should also be logged.

@inmny
Copy link
Author

inmny commented Sep 24, 2024

Log code:

LogInfo($"{Type.GetType("UnityEngine.Application, UnityEngine")}");
try
{
    _ = new EntityStore();
}
catch (Exception e)
{
    do
    {
        LogInfo($"Name: {e.GetType().Name}\nMessage: {e.Message}\nStackTrack: {e.StackTrace}");
        e = e.InnerException;
    } while (e != null);
}

Log:

[Info   : Unity Log] [NML]: UnityEngine.Application
[Info   : Unity Log] [NML]: Name: TypeInitializationException
Message: The type initializer for 'Static' threw an exception.
StackTrack:   at Friflo.Engine.ECS.EntityStoreBase..ctor () [0x00022] in <2760b6615674441eb080f0fb778cfc66>:0
  at Friflo.Engine.ECS.EntityStore..ctor (Friflo.Engine.ECS.PidType pidType) [0x00000] in <2760b6615674441eb080f0fb778cfc66>:0
  at Friflo.Engine.ECS.EntityStore..ctor () [0x00000] in <2760b6615674441eb080f0fb778cfc66>:0
  at Cultiway.ModClass.OnModLoad () [0x00002] in Source\ModClass.cs:18
[Info   : Unity Log] [NML]: Name: TypeLoadException
Message: Could not resolve type with token 010000aa (from typeref, class/assembly System.Runtime.CompilerServices.RuntimeFeature, netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51)
StackTrack:   at Friflo.Engine.ECS.SchemaUtils.RegisterSchemaTypes (Friflo.Json.Fliox.Mapper.TypeStore typeStore) [0x00000] in <2760b6615674441eb080f0fb778cfc66>:0
  at Friflo.Engine.ECS.EntityStoreBase+Static..cctor () [0x0000a] in <2760b6615674441eb080f0fb778cfc66>:0

It seems that it is running on NativeAOT. But I am sure that it is in unity runtime.

@inmny
Copy link
Author

inmny commented Sep 24, 2024

I find its problem: It tries to load "RuntimeFeature" type which is only provided by "System.Runtime" when call SchemaUtils.RegisterComponentTypesByReflection no matter whether it is used.

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