|
Unity打包运行出现:PlatformNotSupportedException该平台不支持此操作的解决记录
一、前言
今天遇到一个问题PlatformNotSupportedException该平台不支持此操作的解决记录记录一下。
首先,描述一下出现问题的情况,代码在Unity编辑器中运行正常,代码也反复研究了很多遍,都没有问题。
最后没有办法,选择打包启动Debug调试:
然后就出现错误:
PlatformNotSupportedException: Operation is not supported on this platform.
at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDynamicMethod (System. String name, System. Type returnType, System. Type[] parameterTypes, System. Type owner) [0x00018] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory. CreateDefaultConstructor[T] (System. Type type) [0x00010] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator (System. Type createdType) [0x00005] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract (Newtonsoft.Json.Serialization. JsonContract contract) [0x00093] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System. Type objectType) [0x00007] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System. Type objectType) [0x0010f] in <2676a2da6edc420e890ed28aa4572ee5>:0
at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue]. GetOrAdd (TKey key, System. Func`2[T,TResult] valueFactory) [0x00034] in <c79628fadf574d3a8feae0871fad28ef>:0
at Newtonsoft.Json.Utilities.ThreadSafeStore`2[TKey,TValue]. Get (TKey key) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System. Type type) [0x0000b] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContract (System. Object value) [0x00011] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe (System. Object value) [0x00005] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json. JsonWriter jsonWriter, System. Object value, System. Type objectType) [0x00028] in <2
二、分析
根据报错的提示:PlatformNotSupportedException: Operation is not supported on this platform.
然后找到关键词Newtonsoft.Json.Serialization,这是我使用了Newtonsoft.Json序列化Json 工具。
然后注释掉相关的代码后,果然没有再报错,那么剩下来就是解决这部分的代码了。
三、解决方案
首先百度,找到一篇文章:
Unity打包exe(连接MySQL)出现PlatformNotSupportedException: Operation is not supported on this platform.的问题
这篇文章是因为使用MySQl出现了PlatformNotSupportedException: Operation is not supported on this platform问题,跟我们的错误不太一样,抱着试一下的态度进行尝试:
找到Project Settings下面的Api Compatibility Level改成.NET 4.x:
等待编辑器编译结束,没有出现错误,直接打包生成。
没有出现错误,程序也正常了,问题解决。
四、总结
这是一个很好的解决的问题,但是这种问题往往会难住小白一天甚至更久的时间。
但是,我希望有心人可以在这篇文章可以学到点什么东西。
比如说,遇到BUG应该怎么做,怎么发现问题,怎么解决问题,让我们最后再进行以下梳理:
(1)遇到问题
(2)检查代码是否正确,在编辑器运行是否正常
(3)打包后出现问题,使用打包后调试工具:UnityDebugViewer、KGFDebug、UnityIngameDebugConsole
(4)发现问题代码,注释后查看程序是否运行整成。
(5)注释后依旧有问题,重复上述操作,锁定问题代码段
(6)如果可以解决代码问题就解决代码问题,不能解决就百度看是否有相同问题,毕竟你遇到的别人也可能遇到,你踩过的坑是别人已经填好的坑。
(7)解决问题,整理思路,记录问题或者BUG解决,让后面人不再踩坑。
|