ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

【Unity3D日常BUG记录】Unity打包运行出现:PlatformNotSupportedException该平台不支持此操作的解决记录

2022-01-13 11:02:51  阅读:229  来源: 互联网

标签:Unity3D Newtonsoft 记录 System value Unity Json Serialization Type


推荐阅读

大家好,我是佛系工程师☆恬静的小魔龙☆,不定时更新Unity开发技巧,觉得有用记得一键三连哦。

一、前言

今天遇到一个问题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 <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json. JsonWriter jsonWriter, System. Object value, System. Type objectType) [0x0023a] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json. JsonWriter jsonWriter, System. Object value, System. Type objectType) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System. Object value, System. Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00028] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.JsonConvert.SerializeObject (System. Object value, System. Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x00007] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at Newtonsoft.Json.JsonConvert.SerializeObject (System. Object value) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0 
at MainControl. ReturnJson () [0x00087] in E:\Working\PantsDesign_HDR\Assets\Scripts\Global\MainControl.cs:85 
at MainControl. CurrentStepSave () [0x00028] in E:\Working\PantsDesign_HDR\Assets\Scripts\Global\MainControl.cs:60 
at PageChange. ChangePage (System. Int32 index1, System. Int32 index2, System. String step, ExpStepSwitch step2) [0x00018] in E:\Working\PantsDesign_HDR\Assets\Scripts\Global\MainControl.cs:241 
at MainControl. CurrentStepParse () [0x00267] in E:\Working\PantsDesign_HDR\Assets\Scripts\Global\MainControl.cs:147 
at LoginControl. LoginReceive (System. String value) [0x0010f] in E:\Working\PantsDesign_HDR\Assets\Scripts\1_Login\LoginControl.cs:240 
at WebRequestControl+<>c__DisplayClass1_0. <RequestDataFormat>b__0 (System. String value) [0x00001] in E:\Working\PantsDesign_HDR\Assets\Scripts\Web\WebRequestControl.cs:23 
at WebRequestControl+<RequestData>d__2. MoveNext () [0x000cf] in E:\Working\PantsDesign_HDR\Assets\Scripts\Web\WebRequestControl.cs:47 
at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections. IEnumerator enumerator, System. IntPtr returnValueAddress) [0x00026] in <11823353802e452f95fbecfc4daf365f>:0 

二、分析

根据报错的提示: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)打包后出现问题,使用打包后调试工具:UnityDebugViewerKGFDebugUnityIngameDebugConsole
  • (4)发现问题代码,注释后查看程序是否运行整成。
  • (5)注释后依旧有问题,重复上述操作,锁定问题代码段
  • (6)如果可以解决代码问题就解决代码问题,不能解决就百度看是否有相同问题,毕竟你遇到的别人也可能遇到,你踩过的坑是别人已经填好的坑。
  • (7)解决问题,整理思路,记录问题或者BUG解决,让后面人不再踩坑。

标签:Unity3D,Newtonsoft,记录,System,value,Unity,Json,Serialization,Type
来源: https://blog.csdn.net/q764424567/article/details/122468626

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有