में टाइप 'System.Collections.Generic.List`1' नहीं मिला। मैं C# unity3d में किसी ऑब्जेक्ट को क्रमबद्ध और deserialize करने का प्रयास कर रहा हूं। इसके लिए मैं नीचे दिए गए कोड का उपयोग कर रहा हूं। लेकिन मुझे नीचे उल्लिखित त्रुटि मिल रही है। जब मैं फाइल करने के लिए बचाने वस्तु को क्रमानुसार और फ़ाइल से लोड करते समय मैं बाहर खेल रोक के साथ खेल खेल रहा हूँसीरियलाइजेशन अपवाद: सी # unity3d
Error: SerializationException: Could not find type 'System.Collections.Generic.List`1[[ABC, Assembly-CSharp, Version=1.0.2.18931, Culture=neutral, PublicKeyToken=null]]'.
यह नहीं हो रहा है।
लेकिन त्रुटि तब होती है जब मैं गेम को रोकता हूं और कोड की किसी भी पंक्ति को बदलता हूं (धारावाहिक और deserialization के लिए अप्रासंगिक) और पहले सहेजी गई फ़ाइल से डेटा लोड और deserialize करने की कोशिश कर रहा है मुझे SerializationException
मिल रहा है।
मैं दृश्य स्टूडियो संपादक और unity3d संस्करण का उपयोग कर रहा 5.5.4
मैं कुछ बहुत ही सरल बात याद आ रही हो सकता है। क्या कोई इसे हल करने में मेरी मदद कर सकता है।
धन्यवाद।
public static string SerializeObject<T>(T objectToSerialize)
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream memStr = new MemoryStream();
try
{
bf.Serialize(memStr, objectToSerialize);
memStr.Position = 0;
return Convert.ToBase64String(memStr.ToArray());
}
finally
{
memStr.Close();
}
}
public static T DeserializeObject<T>(string str)
{
BinaryFormatter bf = new BinaryFormatter();
bf.Binder = new CurrentAssemblyDeserializationBinder();
byte[] b = Convert.FromBase64String(str);
MemoryStream ms = new MemoryStream(b);
try
{
return (T)bf.Deserialize(ms);
}
finally
{
ms.Close();
}
}
कक्षा मैं उपयोग कर रहा हूँ:
public sealed class CurrentAssemblyDeserializationBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
Version assemVer1 = Assembly.GetExecutingAssembly().GetName().Version;
Debug.Log("ASSEM VER: " + assemVer1 + "--NAME--" + assemblyName + " --OVERAL-- " + Assembly.GetExecutingAssembly().FullName + " --TYPE-- " + typeName);
//assemblyName = Assembly.GetExecutingAssembly().FullName.Replace(assemVer1.ToString(), "1.0.2.23455");
//string assemblyNameCustom = "Assembly-CSharp, Version=1.0.2.18931, Culture=neutral, PublicKeyToken=null";
bool isList = false;
if (typeName.Contains("List`1"))
isList = true;
// other generics need to go here
if (isList)
return Type.GetType(string.Format("System.Collections.Generic.List`1[[{0}, {1}]]", "ABC", "Assembly-CSharp, Version=1.0.2.18931, Culture=neutral, PublicKeyToken=null"));
else
return Type.GetType(string.Format("{0}, {1}", assemblyName, typeName));
}
}
लेकिन मैं एक ही अपवाद और BindToType
में लॉग हो रही है कभी नहीं छपा है:
[Serializable]
public class ABC : ISerializable
{
public SerializableDictionary<int, ExampleClass> a = new SerializableDictionary<int, ExampleClass>();
public GameObject b;
public GameObject c;
public bool d = false;
public ABC e;
public int f;
public string g = "";
public int h = -1;
public int i = -1;
public int j = -1;
public string k = "default";
public XYZ l = XYZ.P;
}
[Serializable]
public enum XYZ
{
P,
Q
}
[Serializable()]
public class ABCListWrapper : ISerializable
{
public List<ABC> abcMappings = new List<ABC>();
public string version = "1.53";
public float interval;
}
//Serilization
abcLW = new ABCListWrapper();
abcW = getABCListWObj();
string abcWString = SerializeObject(abcW);
File.WriteAllText(Application.streamingAssetsPath + "/filename.json", abcWString);
//Deserilization call
ABCListWrapper l = new ABCListWrapper();
string l_1 = File.ReadAllText(Application.streamingAssetsPath + "/filename.json");
l = DeserializeObject<ABCListWrapper>(l_1);
समस्या को हल करने का प्रयास। तो इसका मतलब है BindToType
SerilizationBinder
में फ़ंक्शन BindToType
।
कृपया उस कक्षा को पोस्ट करें जिसे आप इसका उपयोग करने का प्रयास कर रहे हैं। यह भी दिखाएं कि आप इन कार्यों को कैसे कॉल कर रहे हैं और जहां त्रुटि हो रही है। – Programmer
कोई तरीका है कि मैं आपको निजी रूप से फाइल भेज रहा हूं क्योंकि इसकी एक तृतीय पक्ष संपत्ति मैं उपयोग कर रहा हूं और मैं इसे यहां सीधे पोस्ट नहीं कर सकता – djkp
मैं एक फाइल नहीं मांग रहा हूं। जिस श्रेणी में आप serizele/deserialize की कोशिश कर रहे हैं और आप इस कक्षा – Programmer