Search Issue Tracker
By Design
Votes
13
Found in
Issue ID
1034782
Regression
No
System.Configuration.ConfigurationErrorsException: Failed to load configuration section for dataContractSerializer
Using works fine in editor, but on device (iOS / Android) we are getting the error below. Looks like others have encountered this (https://forum.unity.com/threads/uwp-datacontractserializer-fails-to-load-configuration-section.507801/)
The Error:
[WARNING] System.Configuration.ConfigurationErrorsException: Failed to load configuration section for dataContractSerializer.
at System.Runtime.Serialization.Configuration.DataContractSerializerSection.UnsafeGetSection () [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.Serialization.DataContract.get_ConfigSection () [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.Serialization.DataContract.LoadKnownTypesFromConfig (System.Type type, System.Collections.Generic.Dictionary`2[TKey,TValue] typesChecked, System.Collections.Generic.Dictionary`2[System.Xml.XmlQualifiedName,System.Runtime.Serialization.DataContract]& knownDataContracts) [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.Serialization.DataContract.ImportKnownTypeAttributes (System.Type type, System.Collections.Generic.Dictionary`2[TKey,TValue] typesChecked, System.Collections.Generic.Dictionary`2[System.Xml.XmlQualifiedName,System.Runtime.Serialization.DataContract]& knownDataContracts) [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.Serialization.DataContract.ImportKnownTypeAttributes (System.Type type) [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.Serialization.ClassDataContract+ClassDataContractCriticalHelper.get_KnownDataContracts () [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType (System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, System.Object obj, System.RuntimeTypeHandle declaredTypeHandle) [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalWriteObjectContent (System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph) [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalWriteObject (System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph) [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions (System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph, System.Runtime.Serialization.DataContractResolver dataContractResolver) [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.Serialization.Json.DataContractJsonSerializer.WriteObject (System.IO.Stream stream, System.Object graph) [0x00000] in <00000000000000000000000000000000>:0
at WBG.Common.Request.WBGRequest.SerializeType[T] (T data) [0x00000] in <00000000000000000000000000000000>:0
at WBG.Common.Request.WBGRequest.Send[SendType,RespType] (System.String url, WBG.Common.Request.WBGRequest+Verb verb, System.Collections.Generic.Dictionary`2[TKey,TValue] headers, SendType data) [0x00000] in <00000000000000000000000000000000>:0
at Iridium.IR_Request.SendRequest[SendType,RespType] (System.String url, WBG.Common.Request.WBGRequest+Verb verb, SendType data) [0x00000] in <00000000000000000000000000000000>:0
at IridiumSDK.SendRequest[SendType,RespType] (System.String url, WBG.Common.Request.WBGRequest+Verb verb, SendType data) [0x00000] in <00000000000000000000000000000000>:0
at IridiumEATService.GetActionTimerEntities (System.String playerId) [0x00000] in <00000000000000000000000000000000>:0
at DreadAPI.DN_EAT.GetActionTimerEntities (System.String playerId) [0x00000] in <00000000000000000000000000000000>:0
at ActionTimerEntityManager.RefreshActionTimersData (WBG.Common.Callbacks+AsynchronousCallbackType callback) [0x00000] in <00000000000000000000000000000000>:0
at WBG.Common.WBGAsync._Next (System.String error, System.Object retval) [0x00000] in <00000000000000000000000000000000>:0
at WBG.Assets.HttpAssetBundleLoader+<DownloadAssetBundleWithCoroutine>c__Iterator0.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0
WBG.Logging.Internal.UnityConsoleDescriptor:Write(StringBuilder)
WBG.Logging.Internal.LogManager:WriteToDescriptors(StringBuilder)
IridiumEATService:GetActionTimerEntities(String)
DreadAPI.DN_EAT:GetActionTimerEntities(String)
ActionTimerEntityManager:RefreshActionTimersData(AsynchronousCallbackType)
WBG.Common.WBGAsync:_Next(String, Object)
WBG.Assets.<DownloadAssetBundleWithCoroutine>c__Iterator0:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
-
jleemans
Sep 15, 2021 15:55
Hi, I still have this issue with Unity 2020.3.16f1 with XmlSerializer
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Runtime.Serialization.XmlFormatWriterInterpreter.TryWritePrimitive (System.Type type, System.Func`1[TResult] value, System.Reflection.MemberInfo memberInfo, System.Nullable`1[T] arrayItemIndex, System.Xml.XmlDictionaryString ns, System.Xml.XmlDictionaryString name, System.Int32 nameIndex) [0x00000] in <00000000000000000000000000000000>:0 -
andycan
May 31, 2019 10:31
problem still persists in version 2019.1.1f1,
when scripting mono backend, on ILCPP it works!! -
FunRobDev
Apr 16, 2019 22:17
Please reopen this issue!.
It is still not working in Unity 2019.1.0f2
with Api Compatibility Level = .NET 4x
I am using the mentioned link.xml -
msawayda
Feb 09, 2019 02:53
I am having the same issue. I have a Wcf method that returns a [DataContract]. My unity project is making a call to the Wcf endpoint and getting the [DataContract] object back. This works fine in the Unity Editor but throws an error with "FAILED TO LOAD CONFIGURATION SECTION FOR DATACONTRACTSERIALIZER" when I run it on a mobile device(in my case android).
I have upgraded Unity to 2018.3.4f1 because Josh Peterson(https://forum.unity.com/members/joshpeterson.660077/) said it was fixed in Unity 2018.3.
I have also added the link.xml file to my Assets folder and switched my android Api Compatibility Level to .NET 4.x.
What version of Unity is this fixed in? Or are there any workarounds to getting this to work?
-
HambaliJ
Nov 29, 2018 05:16
@JOSHPETERSON The issue still persist in 2018.3.0b9. Can you provide me the exact version of 2018.3 you're mentioning.
-
HambaliJ
Nov 16, 2018 08:36
The error still persist in 2018.3.0b9.
Android build also affected
-
JoshPeterson
Sep 04, 2018 11:54
I've seen two different errors in this case, based on the Api Compatibility Level setting.
If the Api Compatibility Level for the project is .NET 4.x, the error originally reported in this thread will occur.
If the Api Compatibility Level for the project is .NET Standard 2.0, I see an exception that starts like this:
NullReferenceException: Object reference not set to an instance of an object.
at System.Runtime.Serialization.Json.JsonFormatWriterInterpreter.TryWritePrimitive (System.Type type, System.Func`1[TResult] value, System.Reflection.MemberInfo memberInfo, System.Nullable`1[T] arrayItemIndex, System.Xml.XmlDictionaryString name, System.Int32 nameIndex) [0x00000] in <00000000000000000000000000000000>:0If you are using Unity 2018.2 or newer, you can work around this issue by doing the following:
1. Choose the .NET Standard 2.0 Api Compatibility Level
2. Add a link.xml file to the Assets folder of your project with the following contents:<linker>
<assembly fullname="System.Runtime.Serialization" preserve="all"/>
</linker>The problem here is that the DataContractJsonSerializer implementation in the class library assembly System.Runtime.Serialization.dll uses reflection to access some methods. The Unity managed code linker strips away these methods, and the DataContractJsonSerializer class fails to work properly. By preserving everything in System.Runtime.Serialization.dll, those methods are kept.
Note that this is a different problem with the .NET 4.x Api Compatibility Level. That one is a little more involved. We've corrected it in 2018.3, which should be public beta soon. Prior to that release, you will need to use the .NET Standard 2.0 Api Compatibility Level to work around this issue. Once 2018.3 is available, the link.xml file provided here will still be necessary to make this work properly with either Api Compatibility Level option.
-
CatherineIrkalla
Aug 27, 2018 01:07
Can confirm same issue on UWP.
-
Mgravitus
Aug 06, 2018 02:07
Same issue on uwp. Any work arounds?
-
CatherineIrkalla
Jul 30, 2018 15:30
Update: this commit shows the bug is specifically related to the Json serializer/deserializer and not file loading or at least some other types of serializers.
https://gitlab.com/youreperfectstudio/StageMechanic/commit/a955b34a0e23da30f3b0989e60ce0990f952078a
Our save/load start state (which happens in memory) was broken the same as file loading/saving. We changed it to Binary format and now it works. Of course our users already have .json save files from the desktop version of our application (and they are designed to be portable/sharable) so "just use binary format for your save files" isn't a good option.
Note: we did not test XML serialization only json and binary.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- [Linux] "Trying to load color backbuffer into a complex RenderPass setup" error is thrown after entering Play mode in AR Mobile template project
- [Android] Neither of the callbacks are called when several videos with VideoPlayer are spawned on the target on the Google Pixel devices
- Texture2D memory allocation size is significantly increased when running on iOS device
- No data received in Profiler when connecting to WebGL Player without "Autoconnect Profiler" option enabled
- Screen Space Ambient Occlusion is ignored when toggling "Post Processing" visibility in the Scene window overlay
Resolution Note:
Thanks for submitting this issue. I don't think this is a problem on the Unity side, as we do have a good work around for this issue. I've updated the forum thread with details, and I'll include the same details here:
I've seen two different errors in this case, based on the Api Compatibility Level setting.
If the Api Compatibility Level for the project is .NET 4.x, the error originally reported in this thread will occur.
If the Api Compatibility Level for the project is .NET Standard 2.0, I see an exception that starts like this:
NullReferenceException: Object reference not set to an instance of an object.
at System.Runtime.Serialization.Json.JsonFormatWriterInterpreter.TryWritePrimitive (System.Type type, System.Func`1[TResult] value, System.Reflection.MemberInfo memberInfo, System.Nullable`1[T] arrayItemIndex, System.Xml.XmlDictionaryString name, System.Int32 nameIndex) [0x00000] in <00000000000000000000000000000000>:0
If you are using Unity 2018.2 or newer, you can work around this issue by doing the following:
1. Choose the .NET Standard 2.0 Api Compatibility Level
2. Add a link.xml file to the Assets folder of your project with the following contents:
<linker>
<assembly fullname="System.Runtime.Serialization" preserve="all"/>
</linker>
The problem here is that the DataContractJsonSerializer implementation in the class library assembly System.Runtime.Serialization.dll uses reflection to access some methods. The Unity managed code linker strips away these methods, and the DataContractJsonSerializer class fails to work properly. By preserving everything in System.Runtime.Serialization.dll, those methods are kept.
Note that this is a different problem with the .NET 4.x Api Compatibility Level. That one is a little more involved. We've corrected it in 2018.3, which should be public beta soon. Prior to that release, you will need to use the .NET Standard 2.0 Api Compatibility Level to work around this issue. Once 2018.3 is available, the link.xml file provided here will still be necessary to make this work properly with either Api Compatibility Level option.