JasonXuDeveloper/Nino

热更工程 反序列化失败

fenglindubu opened this issue · 1 comments

主工程:
`using Nino.Serialization;

namespace NinoData.Chat
{
[NinoSerialize]
public partial class SystemData
{
[NinoMember(1)]
public string name;
[NinoMember(2)]
public string notice;
}
}
`

热更工程:
` NinoData.Chat.SystemData systemData=new NinoData.Chat.SystemData() { name="111",notice="222"};
var dt = Nino.Serialization.Serializer.Serialize(systemData);
JEngine.Core.Log.PrintError(BitConverter.ToString(dt));
Nino.Serialization.Deserializer.Deserialize<NinoData.Chat.SystemData> (dt);

        Debug.LogError("热更新"+ systemData.name);`

能输出序列化的byte 反序列化报错:
TargetException: Non-static field requires a target
System.Reflection.RuntimeFieldInfo.SetValue (System.Object obj, System.Object val, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Globalization.CultureInfo culture) (at <1f66344f2f89470293d8b67d71308c07>:0)
System.Reflection.FieldInfo.SetValue (System.Object obj, System.Object value) (at <1f66344f2f89470293d8b67d71308c07>:0)
Nino.Serialization.Deserializer.Deserialize (System.Type type, System.Object val, System.Span1[T] data, Nino.Serialization.Reader reader, Nino.Serialization.CompressOption option, System.Boolean returnDispose) (at Assets/Dependencies/Nino/Serialization/Deserializer.cs:268) Nino.Serialization.Deserializer.Deserialize (System.Type type, System.Byte[] data, Nino.Serialization.CompressOption option) (at Assets/Dependencies/Nino/Serialization/Deserializer.cs:68) Nino.Serialization.ILRuntimeResolver.Deserialize_0 (ILRuntime.Runtime.Intepreter.ILIntepreter intp, ILRuntime.Runtime.Stack.StackObject* esp, System.Collections.Generic.List1[T] mStack, ILRuntime.CLR.Method.CLRMethod method, System.Boolean isNewObj) (at Assets/Dependencies/Nino/Serialization/ILRuntimeResolver.cs:193)
ILRuntime.Runtime.Intepreter.ILIntepreter.Execute (ILRuntime.CLR.Method.ILMethod method, ILRuntime.Runtime.Stack.StackObject* esp, System.Boolean& unhandledException) (at Assets/Dependencies/ILRuntime/ILRuntime/Runtime/Intepreter/ILIntepreter.cs:2087)
Rethrow as ILRuntimeException: Non-static field requires a target
IL_006a: call !!0 Nino.Serialization.Deserializer::Deserialize<NinoData.Chat.SystemData>(System.Byte[],Nino.Serialization.CompressOption)
UI.LoginGame.LoginGame.Start() (at HotUpdateScripts/UI/LoginGame/LoginGame.cs:38)
IL_006a: call !!0 Nino.Serialization.Deserializer::Deserialize<NinoData.Chat.SystemData>(System.Byte[],Nino.Serialization.CompressOption)
UI.LoginGame.LoginGame.Start() (at HotUpdateScripts/UI/LoginGame/LoginGame.cs:38)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
JEngine.Core.Logger:LogException(Exception, Object) (at Assets/Dependencies/JEngine/Core/Logger/LogHandler.cs:201)
UnityEngine.Debug:LogException(Exception)
JEngine.Core.LifeCycleMgr:ExecuteItems(List1, Boolean, Func2) (at Assets/Dependencies/JEngine/Core/Manager/LifeCycleMgr.cs:326)
JEngine.Core.LifeCycleMgr:LateUpdate() (at Assets/Dependencies/JEngine/Core/Manager/LifeCycleMgr.cs:485)

按F12 查看热更工程的SystemData:
`#region 程序集 Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// F:\MoeMaster\MoeMaster\Library\ScriptAssemblies\Assembly-CSharp.dll
#endregion

using Nino.Serialization;

namespace NinoData.Chat
{
[NinoSerialize(false)]
public class SystemData
{
[NinoMemberAttribute(1)]
public string name;
[NinoMemberAttribute(2)]
public string notice;

    public SystemData();
}

}`

找到问题了,如果结构体在主工程,在热更工程里调用反序列化会出现如上问题。如果结构体在热更工程,在热更工程里使用正常