[ https://issues.apache.org/jira/browse/CB-8968?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14532958#comment-14532958 ]
ASF GitHub Bot commented on CB-8968: ------------------------------------ Github user brodybits commented on the pull request: https://github.com/apache/cordova-wp8/pull/79#issuecomment-99931329 The Newtonsoft JSON library does seem much easier to use and perhaps more efficient as well, but unlike the .NET JSON `DataContractJsonSerializer`, Newtonsoft does not support serialization of arbitrary types. This becomes a problem with the cordova-file-plugin when it attempts to send a PluginResult with a byte array (`byte[]`) in response to a `readAsArrayBuffer` request. This is the cause of CB-8968, and it could affect other plugins as well. I have identified two alternative solutions to fix CB-8968: I. Fix `File.cs` in cordova-plugin-file to send the `PluginResult` with a normal integer array: ```diff --- a/src/wp/File.cs +++ b/src/wp/File.cs @@ -695,7 +695,10 @@ public void readAsArrayBuffer(string options) buffer = readFileBytes(filePath, startPos, endPos, isoFile); } - DispatchCommandResult(new PluginResult(PluginResult.Status.OK, buffer), callbackId); + int[] bufferAsIntArray = new int[buffer.Length]; + for (int i=0; i<buffer.Length; ++i) bufferAsIntArray[i] = buffer[i]; + + DispatchCommandResult(new PluginResult(PluginResult.Status.OK, bufferAsIntArray), callbackId); } catch (Exception ex) { ``` Idea thanks to: http://stackoverflow.com/questions/15226921/how-to-serialize-byte-as-simple-json-array-and-not-as-base64-in-json-net II. In `template/cordovalib/JSON/JsonHelper.cs` add a new function such as `public static string SerializeAny(object obj)` with what used to be the contents of `JSON.JsonHelper.Serialize`, and call this function instead of `JsonConvert.SerializeObject` in `PluginResult.cs`. I am not sure which solution would have better performance. Solution II only goes through the data once, but solution II delegates the looping to the framework libraries, which *could* do the hard work in C/C++/assembly. I am happy to issue a PR for either solution. Solution I would be easiest. > File failures on WP8 > -------------------- > > Key: CB-8968 > URL: https://issues.apache.org/jira/browse/CB-8968 > Project: Apache Cordova > Issue Type: Bug > Components: Plugin File, WP8 > Reporter: Alexander Sorokin > Assignee: Jesse MacFadyen > > New failures showed up in mobilespec for wp8: > {code} > cordova-plugin-file-tests.tests >> File API Read method file.spec.87 should > read file properly, readAsArrayBuffer > cordova-plugin-file-tests.tests >> File API Read method file.spec.94 should > read sliced file properly, readAsArrayBuffer > cordova-plugin-file-tests.tests >> File API FileWriter file.spec.106 should > be able to write a File to a FileWriter > cordova-plugin-file-tests.tests >> File API FileWriter file.spec.107 should > be able to write a sliced File to a FileWriter > cordova-plugin-file-tests.tests >> File API FileWriter file.spec.108 should > be able to write binary data from a File > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For additional commands, e-mail: issues-h...@cordova.apache.org