locked
Upgraded a VS2013 LightSwitch HTML app to VS2015, now "Save Operation Failed" RRS feed

  • Question

  • I have a web app that I created in LightSwitch HTML. This app works fine in Visual Studio 2013. I need (ok, want) to upgrade it to a Visual Studio 2015 project.

    I opened the solution in VS2015, it went through the upgrade process fine, and I can run the app from VS. It opens and reads data populating a table. But when I try to update a field, using screen.commitchanges(), I get an error:

    Save operation failed

    'vwMyDataItem' resource not found

    'vwMyDataItem' is the name of the table VS created when I imported a view from my SQL server.

    Is there anything I can look at? Or am I permenantly stuck in Visual Studio 2013?

    Thanks,

    Jeremy


    Jeremy

    Thursday, October 19, 2017 8:22 PM

All replies

  • Hi Jeremy,

    You could check this link which tell us how to upgrade the project correctly:

    https://msdn.microsoft.com/en-us/library/hh674025.aspx

    In addition, you could try to run visual studio as administrator.

    Best Regards,

    Yuk Ding

    Friday, October 20, 2017 3:40 AM
  • Thank you for your suggestions Yuk. However that did not change the issue.

    I had read that article on MS website earlier, and it basically just says that if you had compile errors in 2013 not to attempt an upgrade. I am not sure why someone would attempt to upgrade to 2015 if the project was not working in 2013...

    Has anyone successfully upgraded a 2013 LightSwitch project to 2015, a project that updates data as well as reads it?

    Thanks,

    Jeremy


    Jeremy

    Friday, October 20, 2017 1:29 PM
  • I would run Fiddler  or use your browser's Dev Tools (F12 for IE) and look for a 404 then look at the oData POST/PATCH that caused the 404 to see what data is being sent.

    This is likely a simple oversight.

    Friday, October 20, 2017 2:21 PM
  • Hi Ian,

    I am not familiar with using IE's F12... I did that and the pane at the bottom opened up with DOM Explorer, Console, Debugger.... while my app was running.

    Where do I look for the error?

    Thanks,

    Jeremy


    Jeremy

    Friday, October 20, 2017 2:34 PM
  • You need to click on the Network tab to see the traffic while running your application. It's going to take some hacking to learn how this all works. 

    It's best to unpin the Developer Tools pane ... there is a button or press Control + P.

    Friday, October 20, 2017 2:38 PM
  • Thanks for this, I am new to 'Web' development. I usually stick to SQL, SSAS, SSIS... anything BI related. I was able to capture the Network traffic while I clicked my save button. Below is the Request Body and the Response Body:

    --batch_72f2-1def-8f06

    Content-Type: multipart/mixed; boundary=changeset_09e8-498b-f549

     

    --changeset_09e8-498b-f549

    Content-Type: application/http

    Content-Transfer-Encoding: binary

     

    MERGE vwMyData(Manager_Name='Doe%252CJohn%2520A',Employee_UID='0101010101') HTTP/1.1

    Content-ID: 0

    DataServiceVersion: 3.0

    If-Match: W/"null,null,null,null,null,'John%20Title%20Name',null,null,'ABC',null,null,null,null,null,null,0.0200M,null,null,null,null,'ABC%20ABC',null,'Emp%2CName%20J',null,null,null,null,'12121212','Mgr%2CName%20W',null,null,null,1000"

    Prefer: return-content

    Accept: application/atomsvc+xml;q=0.8, application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1

    Content-Type: application/json;odata=verbose

    MaxDataServiceVersion: 3.0

    {"Total__":"0.025"}

    --changeset_09e8-498b-f549--

    --batch_72f2-1def-8f06--

    That Total___ in bold is the field and value I am updating. Here is the Response Body that has the error in it:

    --batchresponse_fe9934ac-fe63-473e-8c6a-b5baeb5777fd

    Content-Type: multipart/mixed; boundary=changesetresponse_ff68c23d-c169-43f2-b3cf-2d22af8d5c3f

     

    --changesetresponse_ff68c23d-c169-43f2-b3cf-2d22af8d5c3f

    Content-Type: application/http

    Content-Transfer-Encoding: binary

     

    HTTP/1.1 404 Not Found

    Content-ID: 0

    X-Content-Type-Options: nosniff

    DataServiceVersion: 3.0;

    Content-Type: application/json;odata=fullmetadata;streaming=true;charset=utf-8

     

    {"odata.error":{"code":"1","message":{"lang":"en-US","value":"<?xml version=\"1.0\" encoding=\"utf-16\"?><ExceptionInfo><Message>vwMyDataItem' resource not found.</Message><StackTrace>   at System.Data.Services.DataService`1.BatchDataService.HandleBatchContent(Stream responseStream)</StackTrace></ExceptionInfo>"}}}

    --changesetresponse_ff68c23d-c169-43f2-b3cf-2d22af8d5c3f--

    --batchresponse_fe9934ac-fe63-473e-8c6a-b5baeb5777fd--


    Jeremy


    Friday, October 20, 2017 4:48 PM
  • You will get a 404 if a table does not exist or if a join is not satisfied.

    This is what's causing your problem:

    vwMyData(Manager_Name='Doe%252CJohn%2520A',Employee_UID='0101010101')

    The Manager_Name is not correctly escaped.

    %20 = ' ', %25 = '%' and %2C = ','. 

    Is it Doe%,John or I suspect it's Doe,John.

    HTH, It should at least get you closer to where the problem lies.


    • Edited by Ian E Friday, October 20, 2017 5:07 PM
    Friday, October 20, 2017 5:03 PM
  • Yikes, good catch. I would never have even looked at that! Here are how 2013 and 2015 are submitting that:

    2013 = MERGE vwMyData(Manager_Name='Doe%2CJohn%20A',Employee_UID='0101010101') HTTP/1.1
    2015 = MERGE vwMyData(Manager_Name='Doe%252CJohn%2520A',Employee_UID='0101010101') HTTP/1.1

    So its an issue with the javascript encoding? Preliminary Google'ing is telling me it is being URL encoded twice... that is where the %252C is coming from.

    Any idea where in LightSwitch that string is being encoded?

    Actual Text is 'Doe,John A'


    Friday, October 20, 2017 5:33 PM
  • So I created a brand new LightSwitch project in VS2015. My thinking was that perhaps the upgrade process broke something.

    I added the same view that the 2013 project uses and a few fields to a table making one editable. Ran it and it has the same Save operation Failed error, with the oData MERGE statement's Manager_Name being double URL encoded.Maybe something in my VS2015 needs upgrading? Or one of the .js scripts?


    Jeremy

    Friday, October 20, 2017 6:37 PM
  • Never seen this but have had problems similar. How you debug them:

    1. In default.htm, change .min to .js (uncompressed JavaScript files) for the msls and data libraries.

    2. Set a break point at your commitChanges.

    3. Step into the msls library until you get to the data.js library or where you see the double encoding. This can be time consuming so it is sometimes better to start from the bottom using step 4.

    4. You could also search the data.js and find where the batch action is taken. Set a break point then look at the call stack until you find where the encoding is being done.

    I suspect you will find the error is caused by something simple.

    Another way of handling this is to copy all the msls files from 2013 to the 2015 project if they are a different version. If they are the same, you can use Nuget to update msls or create a new 2015 LS project and copy them over.

    Note that you need the .js and .css files and then modify the default.htm to point to the 2013 libraries.

    I hope this makes sense.

    Friday, October 20, 2017 6:45 PM
  • It was the msls-2.5.3.js :)

    VS2013 was using 2.5.2, and when I copied that file from 2013 into the 2015 project and changed the reference in default.htm the save started working again.

    I see there is a 2.5.4 version as well... I'll download fresh copies of each and test.

    Thanks for your help :)


    Jeremy

    Friday, October 20, 2017 7:14 PM
  • I found the problem in the newer msls 2.5.2:

    request.requestUri = metadata.uri.substr(
         dataServiceDetails._serviceUri.length + 1);

    was change to:

    request.requestUri = encodeURI(metadata.uri.substr(
         dataServiceDetails._serviceUri.length + 1));

    I guess the metadata.uri has already been encoded.


    Jeremy

    Friday, October 20, 2017 7:59 PM
  • Hi Jeremy Crouch,

    Thanks for sharing your experience.

    Best Regards,

    Yuk Ding

    Wednesday, October 25, 2017 7:32 AM