Unity 3d 和 RavenDB:System.InvalidOperationException:无法转换文档 System.FormatException:输入字符串的格式不正确
Unity 3d and RavenDB : System.InvalidOperationException: Could not convert document System.FormatException: Input string was not in a correct format
我遇到了一些问题。我不确定是数据还是 Raven。我在 Unity3d 中使用 Raven。我已经在支持下工作了一两个星期,试图让一切都摆平,他们甚至实施了一些补丁以使其正常工作。我现在真的很接近了,但是将 运行 保留在 "System.InvalidOperationException: Could not convert document System.FormatException: Input string was not in a correct format." 的错误中数据库中的数据当前来自 3.x 版本的数据转储,所以我不确定是否存在结构上是否有任何差异或我没有考虑到的任何事情,但我使用了内置的导入器,它很好地处理了数据,没有给出任何其他错误或表明这是一个问题,据我所知.
我会尽力解释和展示一些代码,如果有人有任何建议,我将不胜感激。我 运行 一开始遇到的一个问题是我使用的游戏框架最初是几年前制作的,我更新了。它使用 Raven 3.x,而尝试将其更新为 4.x 时发现兼容性问题,因为 Unity 尚未实现 .netstandard 2.0。随着上周发布的 Unity 2018.1 RC1 支持 .netstandard,所以我终于能够真正实现 Unity 和 Raven 之间的通信。
目前是游戏尝试查询数据库以获取 NPC 和项目详细信息以存储在缓存中。
下面是使用 Raven 时的原始查询 3.x(行 n => n.ZoneId == this.id 正在比较分配给 NPC 的 ZoneId 和 ZoneId调用数据的脚本的名称。实际上没有任何内容是指我找到的文档 ID)
using (var session = this.world.WorldDatabase.OpenSession())
{
// load all npcs
foreach (var npcData in session.Query<NpcData>("Npc/ByZoneId").Where(n => n.ZoneId == this.id))
{
var npc = new Npc(this, npcData.Guid, npcData.GroupId, (NpcType) npcData.NpcType, npcData);
this.objectCache.AddItem(npc);
var position = npcData.Position.ToVector();
position.Y = this.GetHeight(position.X, position.Z);
var rotation = Quaternion.CreateEular(0, npcData.Orientation, 0);
this.PrimaryFiber.Enqueue(() => npc.Spawn(position, rotation));
}
我不确定它是否不喜欢那样,所以我尝试按照文档的方式进行操作,如下所示。
IList<NpcData> query = session
.Query<NpcData>("Npc/ByZoneId")
.Where(n => n.ZoneId == zid)
.ToList();
foreach (var npcData in query)
{
var npc = new Npc(this, npcData.Guid, npcData.GroupId, (NpcType) npcData.NpcType, npcData);
this.objectCache.AddItem(npc);
var position = npcData.Position.ToVector();
position.Y = this.GetHeight(position.X, position.Z);
var rotation = Quaternion.CreateEular(0, npcData.Orientation, 0);
this.PrimaryFiber.Enqueue(() => npc.Spawn(position, rotation));
}
我有一个界面设置:
IRavenQueryable<T> Query<T>(string indexName) where T : IDataObject;
然后是 DatabaseFactory 设置:
public IRavenQueryable<T> Query<T>(string indexName) where T : IDataObject
{
using (var session = store.OpenSession())
{
return session.Query<T>(indexName);
}
}
数据库中的数据如下所示,我认为图像是个好主意,这样您也可以看到实际的文档名称,以防万一:
https://i.imgur.com/Bb39WNm.png
无论我尝试什么,我都会不断返回该错误。如果有帮助,完整的错误在下面。如果需要更多详细信息,请告诉我,我会提供。
提前致谢!
System.InvalidOperationException:无法将文档 NPC/1818637598 转换为 Framework.Server.Data.NpcData 类型的实体 ---> System.FormatException:输入字符串的格式不正确。
在 System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00057] in :0
在 System.Number.ParseInt32(System.String s,System.Globalization.NumberStyles 样式,System.Globalization.NumberFormatInfo 信息)[0x00013] in :0
在 System.Int32.Parse(System.String s,System.Globalization.NumberStyles 样式,System.IFormatProvider 提供者)[0x0000e] in :0
在 System.Convert.ToInt32(System.String 值,System.IFormatProvider 提供者)[0x00005] in :0
在 System.String.System.IConvertible.ToInt32(System.IFormatProvider 提供商)[0x00000] 中:0
在 System.Convert.ChangeType(System.Object 值,System.Type 转换类型,System.IFormatProvider 提供商)[0x0011a] in :0
在 Raven.Client.Json.BlittableJsonReader.ReadAsInt32 () [0x000c7] 在 <3af6f962c10f46e297126f8db0cace22>:0
在 Newtonsoft.Json.JsonReader.ReadForType(Newtonsoft.Json.Serialization.JsonContract 合约,System.Boolean hasConverter)[0x0004a] in :0
在 Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues (Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x000db] in :0
在 Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.Serialization.ObjectConstructor1[T] creator, System.String id) [0x000b2] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract objectContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id, System.Boolean& createdFromNonDefaultCreator) [0x0008b] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00148] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0006d] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00053] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Raven.Client.Documents.Conventions.JsonNetBlittableEntitySerializer.EntityFromJsonStream (System.Type type, Sparrow.Json.BlittableJsonReaderObject jsonObject) [0x0006e] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.EntityToBlittable.ConvertToEntity (System.Type entityType, System.String id, Sparrow.Json.BlittableJsonReaderObject document) [0x0009b] in <3af6f962c10f46e297126f8db0cace22>:0
--- End of inner exception stack trace ---
at Raven.Client.Documents.Session.EntityToBlittable.ConvertToEntity (System.Type entityType, System.String id, Sparrow.Json.BlittableJsonReaderObject document) [0x000e1] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.TrackEntity (System.Type entityType, System.String id, Sparrow.Json.BlittableJsonReaderObject document, Sparrow.Json.BlittableJsonReaderObject metadata, System.Boolean noTracking) [0x000d0] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.TrackEntity[T] (System.String id, Sparrow.Json.BlittableJsonReaderObject document, Sparrow.Json.BlittableJsonReaderObject metadata, System.Boolean noTracking) [0x00000] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.Operations.QueryOperation.Deserialize[T] (System.String id, Sparrow.Json.BlittableJsonReaderObject document, Sparrow.Json.BlittableJsonReaderObject metadata, Raven.Client.Documents.Session.Tokens.FieldsToFetchToken fieldsToFetch, System.Boolean disableEntitiesTracking, Raven.Client.Documents.Session.InMemoryDocumentSessionOperations session) [0x0000d] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.Operations.QueryOperation.Complete[T] () [0x0007f] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.DocumentQuery
1[T].ExecuteQueryOperation (System.Nullable1[T] take) [0x0005c] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.DocumentQuery
1[T].GetEnumerator () [0x00000] 在 <3af6f962c10f46e297126f8db0cace22>:0
在 Raven.Client.Documents.Linq.RavenQueryInspector1[T].GetEnumerator () [0x00011] in <3af6f962c10f46e297126f8db0cace22>:0
at System.Collections.Generic.List
1[T]..ctor(System.Collections.Generic.IEnumerable1[T] collection) [0x00062] in <e1a80661d61443feb3dbdaac88eeb776>:0
at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable
1[T] 来源)[0x00018] 在 <839a3cb835c04d14aeb58d83bb7bc4bd>:0
在 Framework.Server.Game.MmoZone.LoadZone () [0x00215] in :0 捕获到异常。
我都搞定了。结果是因为我使用的是 enum/byte,RavenDB 4.x 现在只使用字符串和数字,所以我不得不添加一些额外的 json 反序列化/转换方法来获取数据以加载到我的游戏中,但现在一切正常。非常感谢 Raven 的 Oren 花了将近一个星期的时间与我一起工作,使它一切正常。他有圣人般的耐心。我强烈推荐这个数据库!
我遇到了一些问题。我不确定是数据还是 Raven。我在 Unity3d 中使用 Raven。我已经在支持下工作了一两个星期,试图让一切都摆平,他们甚至实施了一些补丁以使其正常工作。我现在真的很接近了,但是将 运行 保留在 "System.InvalidOperationException: Could not convert document System.FormatException: Input string was not in a correct format." 的错误中数据库中的数据当前来自 3.x 版本的数据转储,所以我不确定是否存在结构上是否有任何差异或我没有考虑到的任何事情,但我使用了内置的导入器,它很好地处理了数据,没有给出任何其他错误或表明这是一个问题,据我所知.
我会尽力解释和展示一些代码,如果有人有任何建议,我将不胜感激。我 运行 一开始遇到的一个问题是我使用的游戏框架最初是几年前制作的,我更新了。它使用 Raven 3.x,而尝试将其更新为 4.x 时发现兼容性问题,因为 Unity 尚未实现 .netstandard 2.0。随着上周发布的 Unity 2018.1 RC1 支持 .netstandard,所以我终于能够真正实现 Unity 和 Raven 之间的通信。
目前是游戏尝试查询数据库以获取 NPC 和项目详细信息以存储在缓存中。
下面是使用 Raven 时的原始查询 3.x(行 n => n.ZoneId == this.id 正在比较分配给 NPC 的 ZoneId 和 ZoneId调用数据的脚本的名称。实际上没有任何内容是指我找到的文档 ID)
using (var session = this.world.WorldDatabase.OpenSession())
{
// load all npcs
foreach (var npcData in session.Query<NpcData>("Npc/ByZoneId").Where(n => n.ZoneId == this.id))
{
var npc = new Npc(this, npcData.Guid, npcData.GroupId, (NpcType) npcData.NpcType, npcData);
this.objectCache.AddItem(npc);
var position = npcData.Position.ToVector();
position.Y = this.GetHeight(position.X, position.Z);
var rotation = Quaternion.CreateEular(0, npcData.Orientation, 0);
this.PrimaryFiber.Enqueue(() => npc.Spawn(position, rotation));
}
我不确定它是否不喜欢那样,所以我尝试按照文档的方式进行操作,如下所示。
IList<NpcData> query = session
.Query<NpcData>("Npc/ByZoneId")
.Where(n => n.ZoneId == zid)
.ToList();
foreach (var npcData in query)
{
var npc = new Npc(this, npcData.Guid, npcData.GroupId, (NpcType) npcData.NpcType, npcData);
this.objectCache.AddItem(npc);
var position = npcData.Position.ToVector();
position.Y = this.GetHeight(position.X, position.Z);
var rotation = Quaternion.CreateEular(0, npcData.Orientation, 0);
this.PrimaryFiber.Enqueue(() => npc.Spawn(position, rotation));
}
我有一个界面设置:
IRavenQueryable<T> Query<T>(string indexName) where T : IDataObject;
然后是 DatabaseFactory 设置:
public IRavenQueryable<T> Query<T>(string indexName) where T : IDataObject
{
using (var session = store.OpenSession())
{
return session.Query<T>(indexName);
}
}
数据库中的数据如下所示,我认为图像是个好主意,这样您也可以看到实际的文档名称,以防万一:
https://i.imgur.com/Bb39WNm.png
无论我尝试什么,我都会不断返回该错误。如果有帮助,完整的错误在下面。如果需要更多详细信息,请告诉我,我会提供。
提前致谢!
System.InvalidOperationException:无法将文档 NPC/1818637598 转换为 Framework.Server.Data.NpcData 类型的实体 ---> System.FormatException:输入字符串的格式不正确。
在 System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00057] in :0
在 System.Number.ParseInt32(System.String s,System.Globalization.NumberStyles 样式,System.Globalization.NumberFormatInfo 信息)[0x00013] in :0
在 System.Int32.Parse(System.String s,System.Globalization.NumberStyles 样式,System.IFormatProvider 提供者)[0x0000e] in :0
在 System.Convert.ToInt32(System.String 值,System.IFormatProvider 提供者)[0x00005] in :0
在 System.String.System.IConvertible.ToInt32(System.IFormatProvider 提供商)[0x00000] 中:0
在 System.Convert.ChangeType(System.Object 值,System.Type 转换类型,System.IFormatProvider 提供商)[0x0011a] in :0
在 Raven.Client.Json.BlittableJsonReader.ReadAsInt32 () [0x000c7] 在 <3af6f962c10f46e297126f8db0cace22>:0
在 Newtonsoft.Json.JsonReader.ReadForType(Newtonsoft.Json.Serialization.JsonContract 合约,System.Boolean hasConverter)[0x0004a] in :0
在 Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues (Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x000db] in :0
在 Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.Serialization.ObjectConstructor1[T] creator, System.String id) [0x000b2] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract objectContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id, System.Boolean& createdFromNonDefaultCreator) [0x0008b] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00148] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0006d] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00053] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <dc86da7fc46c487ba6c7ab826da479cc>:0
at Raven.Client.Documents.Conventions.JsonNetBlittableEntitySerializer.EntityFromJsonStream (System.Type type, Sparrow.Json.BlittableJsonReaderObject jsonObject) [0x0006e] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.EntityToBlittable.ConvertToEntity (System.Type entityType, System.String id, Sparrow.Json.BlittableJsonReaderObject document) [0x0009b] in <3af6f962c10f46e297126f8db0cace22>:0
--- End of inner exception stack trace ---
at Raven.Client.Documents.Session.EntityToBlittable.ConvertToEntity (System.Type entityType, System.String id, Sparrow.Json.BlittableJsonReaderObject document) [0x000e1] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.TrackEntity (System.Type entityType, System.String id, Sparrow.Json.BlittableJsonReaderObject document, Sparrow.Json.BlittableJsonReaderObject metadata, System.Boolean noTracking) [0x000d0] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.TrackEntity[T] (System.String id, Sparrow.Json.BlittableJsonReaderObject document, Sparrow.Json.BlittableJsonReaderObject metadata, System.Boolean noTracking) [0x00000] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.Operations.QueryOperation.Deserialize[T] (System.String id, Sparrow.Json.BlittableJsonReaderObject document, Sparrow.Json.BlittableJsonReaderObject metadata, Raven.Client.Documents.Session.Tokens.FieldsToFetchToken fieldsToFetch, System.Boolean disableEntitiesTracking, Raven.Client.Documents.Session.InMemoryDocumentSessionOperations session) [0x0000d] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.Operations.QueryOperation.Complete[T] () [0x0007f] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.DocumentQuery
1[T].ExecuteQueryOperation (System.Nullable1[T] take) [0x0005c] in <3af6f962c10f46e297126f8db0cace22>:0
at Raven.Client.Documents.Session.DocumentQuery
1[T].GetEnumerator () [0x00000] 在 <3af6f962c10f46e297126f8db0cace22>:0
在 Raven.Client.Documents.Linq.RavenQueryInspector1[T].GetEnumerator () [0x00011] in <3af6f962c10f46e297126f8db0cace22>:0
at System.Collections.Generic.List
1[T]..ctor(System.Collections.Generic.IEnumerable1[T] collection) [0x00062] in <e1a80661d61443feb3dbdaac88eeb776>:0
at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable
1[T] 来源)[0x00018] 在 <839a3cb835c04d14aeb58d83bb7bc4bd>:0
在 Framework.Server.Game.MmoZone.LoadZone () [0x00215] in :0 捕获到异常。
我都搞定了。结果是因为我使用的是 enum/byte,RavenDB 4.x 现在只使用字符串和数字,所以我不得不添加一些额外的 json 反序列化/转换方法来获取数据以加载到我的游戏中,但现在一切正常。非常感谢 Raven 的 Oren 花了将近一个星期的时间与我一起工作,使它一切正常。他有圣人般的耐心。我强烈推荐这个数据库!