Unable to launch the IIS Express Web server

Unable to launch the IIS Express Web server.
Output from IIS Express. Failed to register URL for site. The format of the specified network name is invalid 0x800704BE.

The error occured beacause I had a IP binding to 192.168.0.50 added with: “netsh http add iplisten 192.168.0.50”

To remove IP-binding you can use the following command (requires admin permission)

1. Remove current ip listening: netsh http delete iplisten {ip-address}
2. Listen to all ip addresses: netsh http add iplisten 0.0.0.0

Export PFX file from CRT/CER/P7B

Certificate handling. If you want to export a PFX file from a .CRT, .CER or .P7B file, follow these steps:

1. Install Windows 10 SDK (https://developer.microsoft.com/sv-se/windows/downloads/windows-10-sdk).

2. Navigate to folder: C:\Program Files (x86)\Windows Kits\10\bin\10.0.16299.0\x64.

3. Start “certmgr.exe”.

4. In the window that opens you will se a list of all the certificates that are installed. Select the certificate you want export. The click on the button “Export”.

5. Follow the Export Wizard. You will now be able to select export as a PFX file.

Could not load file or assembly System.Web.WebPages.Razor

Suddenly got the error message when starting a MVC application:

Could not load file or assembly ‘System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly ‘System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.

[FileNotFoundException: Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Web.Mvc.PreApplicationStartCode.Start() +0

[InvalidOperationException: The pre-application start initialization method Start on type System.Web.Mvc.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +615
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +141
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +549

[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.Mvc.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10085804
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Solution

Run following command in the package manager console:
Update-Package Microsoft.AspNet.Mvc -Reinstall

Visual Studio 2017 changing font colors

Have had some problems with Visual Studio 2017 and my color scheme (self created). But at every startup VS changed the color scheme to something completely different. No other settings where affected only the colors were changed. This bug have now been fixed in the latest update to VS.
You can follow the thread at:
https://developercommunity.visualstudio.com/content/problem/44258/visual-studio-2017-randomly-changing-font-colors.html

Submit dynamically created form using jQuery

jqueryTried to submit a dynamically created form from an ajax response using jQuery. But couldn’t get it to work. Used the call $(“#formId”).submit();

At last I found the cause why the form wasn’t submitting. In the form a button element with name “submit” was existing once i renamed the button, the form could be submitted. =)
Example:

<form id="theForm" method="post">
<input type="hidden" value="0">
<button name="submit" type="button">
</button>
</form>

Renamed the button, then the form could be submitted!

Lines between braces in Visual Studio 2017

Have recently installed Visual Studio 2017 (release candidate version). And I’m not a big fan of the vertical lines between if declarations, methods, classes and namespaces. It becomes very cluttered when you have a lot of if’s or short methods.
But fourtunately it’s easy to hide the lines, uncheck the option “Show structure guide lines” in Tools > Options > Text Editor > General > Display.

Hide lines between braces option:

show structure guide lines

show structure guide lines

VS 2017 RC

Wow now is Visual Studio 2017 available for test (release candidate version). Microsoft seems to release a new version every second year now of Visual Studio. Some new features I really like so far:

  • Visual Studio has been optimized to reduce startup time and solution load time. The very first launch of Visual Studio is at least 50% faster. I mean who likes slow software. =)
  • Reference method returns.
  • Value tuples where you could convert anonymous object to a tuple.

Get i from: https://www.visualstudio.com/vs/visual-studio-2017-rc/

 

Benchmarking – SQL with and without index

Everybody likes when processes are running at optimal performance. SQL queries is a typical example where the answer of the two equal queries can be delivered with different speed.
Indexes on a table can have a large impact on the performance of a SQL query. I’ve done some benchmark tests running the same query on a table with and without a index.

The table structure: TestIndex (rowId PK int, productId int not null, countryId int not null). The table contains of 100000 rows.

The SQL query:
set statistics time on;
select productId, count(productId) name, min(countryId)
from testindex T2
where productId > 29500000 and productId < 30000000 AND productId IN
(
select productId from testindex
group by productId having count(productId) < 2
)
AND
productId IN
(
select productId from testindex
group by productId having count(productId) < 3
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
group by productid, name, countryId
order by productId desc
set statistics time off;

The index was created like this:
CREATE NONCLUSTERED INDEX testIndexOne
ON testindex (productId)

Benchmark results

CPU time no index CPU time with index Elapsed time no index Elapsed time with index
94 0 7006 60
15 0 6267 30
31 0 6000 61
47 0 6218 32
235 0 6276 31

As you can see in the benchmark results above there is a huge different in both CPU- and elapsed time for running the exactly the same query. The only difference was an added index on one of the columns in the table that was queried.

Unable to launch the IIS Express Web server

Failed to register URL “http://localhost:63647” for site application. Error description: The process cannot access the file because it is being used by another process (0x80070020).

1. Open project properties.
2. Choose “Web” on the left hand side.
3. Update the port number in the project URL. Then click yes if you want to update the virtual directory.
VisualStudio_Project URL

4. Save and restart Visual studio, then you should be good to go! =)