Upgrade from .net 4 to 4.5 breaks Html.Raw call in Javascript - asp.net-mvc-4

I have the following code in a c# MVC 3 razor page where I am passing serialized data into a javascript variable for KnockoutJs:
#{
var listData = new JavaScriptSerializer().Serialize(Model.ListItems);
var pagerData = new JavaScriptSerializer().Serialize(Model.Pager);
}
// additional code
<script type="text/javascript" >
var ListData = #(Html.Raw(listData)); // <-- Syntax Error here
var PagerData = #(Html.Raw(pagerData)); // <-- Syntax Error here
// additional js code
</script>
After upgrading to VS 2012, I am getting error squiggles after the javascript semi-colons at the end the Html.Raw lines above. The project complies but VS 2012 displays 'Syntax Error' in the Error List for each line. Without the semi-colons the javascript also shows a 'Syntax Error'.
This code worked without issues in the previous version. Is this a bug in the VS 2012 parser and is there a way to avoid the generated errors?
Edit
Anyone else seeing this issue? Below is a simplified version with the same issue isolated in a new page. If you add a semi-colon at the end of the ListData line you get a javascript syntax error, without one it is on the next line. Is this a bug in the javascript compiler between VS2010 and VS2012?
#{
var listData = "test";
var pagerData = "test2";
}
<script type="text/javascript" >
var ListData = #(Html.Raw(listData))
var PagerData = #(Html.Raw(pagerData))
</script>

Please add vote on this connect issue. We will address this issue in next version of VS. I have attached your repro code to this bug and added link to this post as another manifestation of the issue.

This issue still exist in Visual Studio 2013 SP 2
To fix this warning message initialize javascript variable first. IMO Visual studio think var as implicitly typed if any var followed by #.
var ListData;
var PagerData;
ListData = #(Html.Raw(listData));
PagerData = #(Html.Raw(pagerData));

I'm using MVC5 and finding the same issue, so I solved it this way, which should work in all versions
#Html.Raw("var myData = " + Json.Encode(this.Model.MyData) + ";" )
However, I would use this only in the simplest situations since you lose any intellisense as to VAR type (although it does treat it as a global instance and the compiler doesn't throw a wobbler), so for now I think an initial, empty definition is probably the best way to proceed.

I have had the same thing happen, but it does so at random.
What I have tried to resolve it is the following:
Make sure you can compile/build/debug in Debug mode, switch to Release mode and attempt to debug/publish from that mode.
Switch back to Debug mode and re-attempt the publish.
Some combination of switching modes does the trick, I just can'y nail down what it is exactly.
Once you get it working, don't close VS ;-)
Let's hope MS gets this fixed in SP1.

Related

way to use 'lowdb' in 'express'

Recently, I am trying to make a web page using express, and I am trying to manage login session information and bulletin board data through lowdb.
But when I try to generate and run the code that requires lowdb and controls lowdb,
There is a error with the require syntax with the err_code 'ERR_REQUIRE_ESM'.
When I googled it, it said that it was a syntax compatibility problem between commonjs and ESM, so do I have to convert all other codes to ESM because of one lowdb?
The code below is the code I made to control lowdb.
var low = require('lowdb');
var FileSync = require('lowdb/adapters/FileSync');
var adapter = new FileSync('db.json');
var db = low(adapter);
db.defaults({users:[], topics:[]}).write();
module.exports = db;
I don't want to convert the whole code to ESM because of lowdb, I want to use lowdb through commonjs. Or is there any other good way to handle local db via json file like lowdb?
Use lowdb#1.0.0 and it will work.
npm i lowdb#1.0.0

Getting FusionAuthClient is not a constructor error

I am trying the fusionauth-node-client and following the wiki https://fusionauth.io/docs/v1/tech/client-libraries/node. But I am getting the following error
const client = new FusionAuthClient('6b87a398-39f2-4692-927b-13188a81a9a3', 'http://localhost:9011');
^
TypeError: FusionAuthClient is not a constructor
at Object.<anonymous>
I have pasted the exact code mentioned in the doc still it is not working. Can anyone help me in identifying what I am missing here.
I dug around in the library and noticed that we are exporting several objects and our example is no longer correct.
To get the client you need to change your syntax a little bit to get the correct object.
const {FusionAuthClient} = require('fusionauth-node-client');
This translates to: require the library fusionauth-node-client and give me the FusionAuthClient from inside it. There are also a RESTClient and JWTManager available in the library but you shouldn't need either of those to code with FusionAuth.
I will also update our example to correct this discrepancy.

Magento SOAP API: Error in retrieving catalogCategoryTree

Currently I'm using Magento 1.9.01 and PHP 5.3.28. In ASP .NET I'm trying to retrieve the catalog tree by using the SOAP API using the following code:
var magentoService = new MagentoService.Mage_Api_Model_Server_Wsi_HandlerPortTypeClient();
var sessionId = magentoService.login(userName, apiKey);
var categoryTree = magentoService.catalogCategoryTree(sessionId, "", "");
The errror I get is "Internal Error. Please see log for details."
And in the logs I can see the following:
Argument 1 passed to Mage_Catalog_Model_Category_Api::_nodeToArray() must be an instance of Varien_Data_Tree_Node, null given
From what I've read it can be a bug with PHP 5.4 or greater, but not the version I'm using... So if someone has any idea how to solve this, it will be greatly appreaciated.
Seems pretty straight forward, though the error thrown suggests a much bigger problem. First make sure that the variables are exactly as you specified in your Magento installation (pay attention to caps). Second you can't pass empty strings, instead try "Null".
Good luck

Casperjs "casper.test property is only available using the `casperjs test` command" but not calling casper test

The error:
casper.test property is only available using the `casperjs test` command
Searched my entire codebase for "casper.test", "this.test", "#test", etc, and none are present. Looking at the casper code, one of these needs to be triggered for this error to be raised.
The error is intermittent and only occurs on some casper runs. Has anyone else gotten this bug? I'm running 1.1.0-beta3.
You can add
phantom.casperTest = true;
at the top of the test file.
Have you launch your script like this ?
casperjs test yourScript.js
It has nothing to do with launching it. Not sure why, but I also received this error on my code before writing to file. It went away after removing...
JSON.stringify(obj);
Again, I dont know what caused the issue. And it may be something else causing it for you. But if you find which piece of code is causing it, I have a solution.
My solution:
Use a handler for errors with a basic variable switch and turn off the error log for that portion of the step.
casper.on("error", function(err) {
if(custLog) {console.log(err);} //log the error
});
and in the step...
casper.then(function() {
custLog = false;
fs.write(fileName, JSON.stringify(content), 'w');
custLog = true;
});
You may or may not need to order the reorder the inner stack there.

Fetching Publishing Pages from Pages Library in SharePoint 2010 ECMAScript OM

i want to fetch all the pages in a specific Publishing Web using JavaScript and Client Object Model, it keeps giving
The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
Here's the code,
var selectedDoc;
var ctx = new SP.ClientContext.get_current();
var site = ctx.get_site();
//('created ctx');
//loading the Library
var pagesLib = site.openWeb('/Ar/News').get_lists().getByTitle('Pages');
if (missionType == 'All') {
var query = new SP.CamlQuery();
query.set_viewXml("<View><RowLimit>10</RowLimit></View>");
selectedDoc = pagesLib.getItems(query);
ctx.load(selectedDoc,'Include(Title)');
ctx.executeQueryAsync(getAllNewsWithQuerySuccess(this,this.onListLoadSuccess), getAllNewsWithQueryFailure(this,this.onQueryFailed));
You might be missing a load call. Try this right after you assign pagesLib:
ctx.load(pagesLib);
I'm guessing the error is due to pagesLib not having been populated before you execute the CAML query against it.
You might be missing a load call. Try this right after you assign pagesLib:
ctx.load(pagesLib);
I'm guessing the error is due to pagesLib not having been populated before you execute the CAML query against it.