Nice article on: JavaScript variable scope hoisting

https://www.sitepoint.com/demystifying-javascript-variable-scope-hoisting

Things to Remember

  • All declarations, both functions and variables, are hoisted to the top of the containing scope, before any part of your code is executed.
  • Functions are hoisted first, and then variables.
  • Function declarations have priority over variable declarations, but not over variable assignments.

Fix: error CS0234: The type or namespace name ‘Helpers’ does not exist in the namespace ‘System.Web’, when using multiple virtual IIS web applications

I have a ASP .NET 4.5.2 MVC web application running on an IIS website and I wanted to run a separate ASP .NET 4.5.2. web api application under the MVC web site.

Both projects worked just fine, when hosting them as separate IIS websites, but when the web api was “mounted” as virtual web application under the MVC website I was getting the errors below, when hitting the web api application:

error CS0234: The type or namespace name 'Helpers' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

Line 150:    <pages controlRenderingCompatibilityVersion="4.0">
Line 151:      <namespaces>
Line 152:        <add namespace="System.Web.Helpers" />
Line 153:        <add namespace="System.Web.Mvc" />
Line 154:        <add namespace="System.Web.Mvc.Ajax" />

So I was hitting the web api, but got an error on the parent MVC web application???

Turns out, I had to remove these namespaces in the web api web.config, because those dll’s are not in the web api project.

Adding the following lines to the web.config of the web api project, solved the errors.

<configuration>

<system.web>

<pages controlRenderingCompatibilityVersion="4.0">

      <namespaces>

         <clear/>

      </namespaces>

    </pages>

Fixing errors CS1525 and CS1003 in MSBuild

When building a Microsoft Visual Studio 2017 solution that uses C#6 and C#7 features from the command line (PowerShell), I was getting the errors:

MyClass.cs(845,112): error CS1525: Invalid expression term ‘decimal’ [Web.csproj]
MyClass.cs(845,120): error CS1003: Syntax error, ‘,’ expected [Web.csproj]
MyClass.cs(870,116): error CS1525: Invalid expression term ‘decimal’ [Web.csproj]
MyClass.cs(870,124): error CS1003: Syntax error, ‘,’ expected [Web.csproj]

This was caused by using the wrong version of MSBuild.

I used "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" after switching to

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" the problem was resolved.