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

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

作者:互联网

推荐阅读

大家好,我是佛系工程师☆恬静的小魔龙☆,不定时更新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应该怎么做,怎么发现问题,怎么解决问题,让我们最后再进行以下梳理:

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