-
Notifications
You must be signed in to change notification settings - Fork 31
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
I want a way to initialize hxbit at the right time in C# #47
Comments
Right, I guess we could add some support for this in hxbit, or another way would be a way to "preload" (and thus force statics init) some classes in C#, I'm not sure how this would work since I'm not familiar with the platform. |
Thanks for the reply! I'm going to post the code I want to work on for your reference. class SerializeTest {
static function main() {
var serializer = new hxbit.Serializer();
var a = new Hoge(5);
trace('a = $a');
var serializedA = serializer.serialize(a);
trace('serializedA = ${serializedA.toHex()}');
var b = serializer.unserialize(serializedA, Hoge);
trace('b = $b');
var serializedB = serializer.serialize(b);
trace('serializedB = ${serializedB.toHex()}');
}
}
class Hoge implements hxbit.Serializable {
public function new(x: Int) {
this.x = x;
}
@:s public var x: Int;
} haxe -main SerializeTest -lib hxbit --interp
SerializeTest.hx:6: a = Hoge
SerializeTest.hx:9: serializedA = 0105
SerializeTest.hx:12: b = Hoge
SerializeTest.hx:15: serializedB = 0105 haxe -main SerializeTest -lib hxbit -cs serialize_test_cs && mono ./serialize_test_cs/bin/SerializeTest.exe
haxelib run hxcs hxcs_build.txt --haxe-version 4005 --feature-level 1
Note: dmcs is deprecated, please use mcs instead!
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Hoge' threw an exception. ---> haxe.lang.HaxeException: Too late to register class
at hxbit.Serializer.registerClass (System.Type c) [0x00014] in <c0688911d66645dda3a6efebf799a0fc>:0
at Hoge..cctor () [0x00000] in <c0688911d66645dda3a6efebf799a0fc>:0
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)
at SerializeTest.main () [0x00006] in <c0688911d66645dda3a6efebf799a0fc>:0
at SerializeTest.Main () [0x00005] in <c0688911d66645dda3a6efebf799a0fc>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'Hoge' threw an exception. ---> haxe.lang.HaxeException: Too late to register class
at hxbit.Serializer.registerClass (System.Type c) [0x00014] in <c0688911d66645dda3a6efebf799a0fc>:0
at Hoge..cctor () [0x00000] in <c0688911d66645dda3a6efebf799a0fc>:0
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)
at SerializeTest.main () [0x00006] in <c0688911d66645dda3a6efebf799a0fc>:0
at SerializeTest.Main () [0x00005] in <c0688911d66645dda3a6efebf799a0fc>:0 |
I have tried to fix this problem, but this fix is not very good. |
I'm having trouble with the "Too late to register class" error.
#24
HaxeFoundation/haxe#4091
HaxeFoundation/haxe#7561
The answer is "Haxe's problem", but Haxe doesn't seem to have any plans to address it either.
Could you please provide a way for all classes to be initialized when you create the Serializer for hxbit, or manually initialize hxbit?
The text was updated successfully, but these errors were encountered: