Search Issue Tracker

By Design

Votes

13

Found in

Issue ID

1034782

Regression

No

System.Configuration.ConfigurationErrorsException: Failed to load configuration section for dataContractSerializer

Scripting

-

-

Priority: 3Not yet prioritized for a release

-

Severity: 3Secondary functionality broken

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)

Response avatar

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.

Comments (12)

  1. Fce3e3d2efda68ca57faeae49efe4493?d=mm

    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?

  2. Ff24d144bb948a8bd596b72ed6ece9a3?d=mm

    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.

  3. Ff24d144bb948a8bd596b72ed6ece9a3?d=mm

    HambaliJ

    Nov 16, 2018 08:36

    The error still persist in 2018.3.0b9.

    Android build also affected

  4. 8b1a42e8bcbf816696f60a10cfa3b940?d=mm

    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>: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.

  5. Fdaa270cca64b7a1918de416d4d6ca9a?d=mm

    CatherineIrkalla

    Aug 27, 2018 01:07

    Can confirm same issue on UWP.

  6. De2a1e57672f86438dbae1a0c307ad45?d=mm

    Mgravitus

    Aug 06, 2018 02:07

    Same issue on uwp. Any work arounds?

  7. Fdaa270cca64b7a1918de416d4d6ca9a?d=mm

    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.

  8. Fdaa270cca64b7a1918de416d4d6ca9a?d=mm

    CatherineIrkalla

    Jul 30, 2018 01:17

    I notice Severity = 3 "Workaround is possible" any ideas what the workaround might be?

  9. Fdaa270cca64b7a1918de416d4d6ca9a?d=mm

    CatherineIrkalla

    Jul 30, 2018 01:13

    More info:

    * the same error happens when trying to save files on Android in our application, it isn't limited to loding.

    * Our serialization classes are here: https://gitlab.com/youreperfectstudio/StageMechanic/tree/master/StageMechanic/Assets/SaveLoadSupport

    * The issue only happens when dealing with file save/load on Android.

    * Our "undo" support when playing in the game uses the Binary serializer (in memory) and works just fine - it is either related to dealing with the filesystem or the Json serializer.

  10. Fdaa270cca64b7a1918de416d4d6ca9a?d=mm

    CatherineIrkalla

    Jul 30, 2018 01:06

    Hmm I can't seem to edit the post I made earlier but if more info is needed when using our codebase to debug the issue please log onto our Discord server at: https://discord.gg/TBU4MyE
    and ping any mod.

    To load a file in the application simply click Load on the main menu and select a .json file from the .zip I linked in the other post and click the load button on the bottom right - then find error in the Android log.

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.