VS2015 Hangs/Freezes When Adding MVC Controller or View

This issue came to me today at work where two devs said they couldn’t add a new view to a project.  I repro’d it right away and began investigating.

The problem was isolated to one project in the solution.  I compared references between projects and compared the underlying project files.  Each change that I made to bring them closer into alignment didn’t help.

As said many times, the trick to successful debugging is isolation.  So I unloaded every project except for the web project being tested.  The Add dialogs loaded immediately.  So at this point, I had a workaround.  The projects referenced by the web project (only one) could be unloaded when a new view or controller was needed.

Although this was a workaround, it’s hardly a solution.  I continued down that path of figuring out why the MVC Add dialogs were causing VS to hang.

At one point, I was researching online and I noticed that the Add Controller dialog did appear.  It took over 5 minutes to get to that point, but it did show.  So I tried the Add View dialog and it eventually did show as well.  The dropdown list for model classes was populated with every class from the referenced project.  That might have been the cause of the slowdown.

Something about the dialog struck me funny.  They were different between the two projects.  This suggested to me that they were using different libraries.  I loaded up the NuGet package manager between the two projects and saw the functional project used Razor v2.0, but the failing project used v3.2.3.

I downgraded the failing project to Razor 2.0.  This caused a new problem.  I no longer had context menu options to directly add controllers or views.  Fortunately, I knew where to go for this fix.

In the project file is a node called ProjectTypeGuid, which tells VS what menu options to provide.  I could see the non-working project was missing one of  the guids.  I quick copy between the projects restored the context menu options.

TFS 2012 Fails To Create New Team Project

Today, I went to add a new team project to TFS.  I did the usual steps by giving it a name and choosing the template type (not really relevant to me since I’m a solo programmer).  Visual Studio worked for a bit, then failed with the following error in the log file:

Event Description: TF30162: Task "LinkTypes" from Group "WorkItemTracking" failed
Exception Type: Microsoft.TeamFoundation.Client.PcwException
Exception Message: Page not found.

The Internet had plenty of advice to resolve TF30162 errors, but nothing useful for the specific LinkTypes error.  The only suggestion was to reload the project templates.  I was not able to do that because in TFS 2012, those templates are locked and unable to be uploaded and overwritten.

So I attempted a Repair install of TFS 2012.  That had no effect

I then made sure I was on the latest version of TFS, so I installed Update 4.  My scrum project template went from 2.0 to 2.2, but I still got the exact same error.

I then tried to create a new Project Collection and create a team project in that.  Still, no change.

Then I did a repair install on Visual Studio 2015.  This took a very long time and required two restarts.  And after that, no improvement.

So far, I’ve eliminated the TFS binaries, the TFS database, and the VS binaries.  There’s only one element left – IIS.  And that one seems to have potential because of the PageNotFound error.

Poking around the IIS log files, there’s entries in there like this:

2017-01-09 14:27:23 ::1 GET /tfs/_apis/connectionData connectOptions=IncludeServices&lastChangeId=-1&lastChangeId64=-1 8080 MicrosoftAccount\myaccount@domain.com ::1 VSServices/14.98.25331.0+(devenv.exe+,Pro,+SKU:31) – 404 0 0 1719

Looking at IIS log files prior to when my problem happened,  this 404 error has happened before, too.  but there was also other calls to the service like:

2016-03-25 12:43:46 ::1 OPTIONS /tfs/defaultcollection/_apis/ – 8080 MicrosoftAccount\myaccount@domain.com ::1 Team+Foundation+(devenv.exe,+14.0.24712.0,+Pro,+SKU:31)+VSServices/14.0.24712.0+(devenv.exe+,Pro,+SKU:31) – 404 0 0 8

Two suspects come up in Internet searches: Git and IIS plugins.  Disabling some of the plugins in C:\Program Files\Microsoft Team Foundation Server 11.0\Application Tier\Web Services\bin\Plugins made no difference.

At this point, I suspect an incompatibility between VS2015 and TFS 2012, so I upgrade my TFS install to 2015.  What else could it be?  A call is being made to a REST service that doesn’t exist, or is different enough that the inbound parameters don’t match up.  This TFS upgrade requires SQLExpress to be upgraded as well.  The rabbit hole keeps going deeper and deeper.

After that entire install and restart, I was finally able to create a new Team Project.  The new default project template is “Agile”, not that I care much.

So, the short solution for my error: Upgrade TFS from 2012 to 2015.  It must’ve become incompatible after a VS update somewhere along the way.

Handling JPEG XR (HD Photos/Windows Media Photos)

I recently found some images on the internet in a format that I couldn’t directly support in my applications.  The images were in JPEG XR, with a .jxr extension.  These images would fail with a “The parameter is incorrect” error when loading the byte array into a System.Drawing.Bitmap (using Image.FromStream).

A little bit of research showed that the standard Drawing classes wouldn’t support this format.  I would need to use classes from the WPF library.  I added references to PresentationCore and WindowsBase, then wrote this function to convert the bytes of a JXR image to a standard bitmap:

 

    Private Function JXRToBitmap(bytes() As Byte) As Bitmap
        Dim s As IO.MemoryStream
        Dim dec As Windows.Media.Imaging.WmpBitmapDecoder
        Dim enc As Windows.Media.Imaging.BmpBitmapEncoder
        Dim bmp As Bitmap

        s = New IO.MemoryStream
        dec = New Windows.Media.Imaging.WmpBitmapDecoder(New IO.MemoryStream(bytes), Windows.Media.Imaging.BitmapCreateOptions.None, Windows.Media.Imaging.BitmapCacheOption.Default)
        enc = New Windows.Media.Imaging.BmpBitmapEncoder

        enc.Frames.Add(Windows.Media.Imaging.BitmapFrame.Create(dec.Frames(0)))
        enc.Save(s)

        bmp = New Bitmap(s)

        s.Dispose()

        Return bmp

    End Function

Since I didn’t know in advance what the file format was, the best I could do was attempt to load the bitmap and if it threw an exception, I would try to load it again using this function in the Catch block.  If that failed, then it would be a true exception.

Visual Studio 2015 + Silverlight In VB.NET

At work, I was the first to upgrade my machine to Windows 10 and Visual Studio 2015.  Opening our application’s solution, I started resolving little errors here and there.  One problem was not so simple and had a very obscure solution.

We have a small collection of Silverlight apps written in VB.NET.  With the upgrade to Visual Studio 2015, they would not compile.  The errors returned were:

Microsoft (R) Visual Basic Compiler version 1.0.0.50618
Copyright (C) Microsoft Corporation. All rights reserved.

vbc : error BC30002: Type ‘Global.Microsoft.VisualBasic.ApplicationServices.ApplicationBase’ is not defined.
vbc : error BC30002: Type ‘Global.Microsoft.VisualBasic.Devices.Computer’ is not defined.
vbc : error BC30002: Type ‘Global.Microsoft.VisualBasic.MyServices.Internal.ContextValue’ is not defined.
vbc : error BC30002: Type ‘Global.Microsoft.VisualBasic.ApplicationServices.User’ is not defined.
vbc : error BC30002: Type ‘Global.System.ComponentModel.Design.HelpKeyword’ is not defined.

In the course of troubleshooting, I excluded everything from the project except the AssemblyInfo file and I still got the errors.  So I created a new Silverlight project, which built fine, and compared the Detailed compiler output.  The compiler line in the 2015-created project had a slightly different parameter (difference highlighted):

/define:"CONFIG=\"Debug\",DEBUG=-1,TRACE=-1,_MyType=\"Empty\",PLATFORM=\"AnyCPU\",SILVERLIGHT=1"

This clicked with me from my experience with building Silverlight apps for the Zune, where you had to exclude the My namespace that is created with VB.NET applications.  Look at the assemblies being referenced.  ApplicationServices.ApplicationBase (My.Application), Devices.Computer (My.Computer), ApplicationServices.User (My.User).

So, how do you get this extra compile setting?  It’s in the .vbproj – there’s no UI for it.  You’ll have to edit the vbproj file directly.

Unload the Silverlight project, right-click it, and choose Edit .vbproj.  Look for the node <NoStdLib>true</NoStdLib> (there will be one per project configuration) and after it, add: <MyType>Empty</MyType>.  This node is included with new Silverlight projects in VS2015.

Save and reload the project and the MyType flag will be included in the vbc command line, which will allow the Silverlight application to compile.

Of course, a lot of people will probably create a new Silverlight project and move all their code into it and be just as successful.  But, if you don’t want that hassle, or if you just want to know why (as I did), there’s the solution.

Azure Aftermath

After the mess with the Azure SDK reserving ports that conflicted with my development environment, and the fact that the SDK didn’t do anything for the automated publishing I was looking for, I decided to uninstall it.  Well, that wasn’t a good idea.  You could say it was “Azure disaster.”

First off, the uninstall of the multiple elements of the Azure SDK did not remove the NETSH entries for the Azure Storage Emulator. so those had to be manually removed. Then, I reopened VS 2013 and suddenly none of my web projects open, saying they are all incompatible with this version of Visual Studio.  I tried to create a new web application and got the useful error:

image

So now I can’t open or create any web applications in Visual Studio.  I decide I should reinstall the Azure SDK to put back what was taken away, although in my mind I realize this is a ridiculous concept.

I download the SDK and run it.  I then get this error from the installer:

image

Absolutely incredible.  This is like dealing with anti-psychotic medication.  “Whoa whoa whoa, you just can’t uninstall Pericyazine, that can cause a psychotic episode.”

Next thing to do is a Repair of the Visual Studio installation, which is going to be at least an hour…  And that has fixed the web project issue, so at least uninstalling the Azure SDK is recoverable.  You just need to make sure you manually get rid of the ACL entries with these statements (at an Administrator command prompt):

netsh http delete urlacl url=http://127.0.0.1:10000/
netsh http delete urlacl url=http://127.0.0.1:10001/
netsh http delete urlacl url=http://127.0.0.1:10002/

Yes, I do believe when Windows 10 and VS 2015 come out, this work machine is due for a reformat.

IISExpress – Error description: Access is denied. (0x80070005)

Today, I spent my entire work day trying to find the solution to this error.

When I would launch a web project from Visual Studio, IIS Express would fail to load.  The error reported was:

Failed to register URL "http://localhost:10000/" for site "Portal3" application "/". Error description: Access is denied. (0x80070005)

I started down the obvious track of checking permissions.  IISExpress would operate just fine when run as Administrator, but not as my normal user.  I was an administrator on the local machine, so that didn’t make any sense.

The only thing I had done that morning was use Disk Cleanup to delete all my temp files and archived error reports.  I checked %temp%\iisexpress.  I checked my *.config files in Documents\IISExpress over and over.  I restored configs from backups.  I read many potential solutions, some as crazy as not being able to use a user name with “bg” in it.

I tried an older iteration of the web application.  It worked.  I tried other web projects in the solution.  They worked.  At this point, I was the only developer in my team who had a single web project that wouldn’t launch.

Then, late as usual, I finally remembered the Windows Event Viewer.  IISExpress was logging these two events:

Event ID: 2269: The worker process for app pool ‘Clr4IntegratedAppPool’, PID=’7536′, failed to initialize the http.sys communication when asked to start processing http requests and therefore will be considered ill by W3SVC and terminated.  The data field contains the error number.

EventID 2276: The worker process failed to initialize correctly and therefore could not be started.  The data is the error.

That lead me down a totally different troubleshooting path.  While doing so, I set up a new website in IIS on port 8085.  Oddly, my new websites and application pools didn’t refresh after being created, which led me to think there was even more wrong with my workstation.  An IISRESET resolved that problem and I was able to browse to the web project using IIS.

So IIS would work on port 8085 but IISExpress would not work on port 10000.  And IIS would work for any other project on seemingly any other port. 

In a comment on one of the web posts that I read, I saw this command:

netsh http add urlacl url=http://localhost:10000/ user=everyone

I’d only ever used NETSH maybe once or twice for some obscure reason, but the inclusion of “ACL” in the command was encouraging.  Amazingly, the command worked!  Although I was happy, I was also disappointed that I wouldn’t be able to see what the value was previously so I could find out the root cause.

So I ran:

netsh http show urlacl

And that displayed a bunch of entries that included these as well (User and SDDL changed):

Reserved URL            : http://127.0.0.1:10000/
    User: Me 
        Listen: Yes
        Delegate: No
        SDDL: D:(A;;GX;;;S-1-5-21-)

Reserved URL            : http://127.0.0.1:10001/
    User: Me
        Listen: Yes
        Delegate: No
        SDDL: D:(A;;GX;;;S-1-5-21-

Reserved URL            : http://127.0.0.1:10002/
    User: Me
        Listen: Yes
        Delegate: No
        SDDL: D:(A;;GX;;;S-1-5-21-)

Where did these come from?  I ran netsh http delete urlacl url=http://localhost:10000/ and removed the entry and confirmed IISExpress stopped working.  Then I ran netsh http delete urlacl url=http://127.0.0.1:10000/ and IISExpress started working again.

Something had added ACL entries for ports 10000-10002 that were conflicting with my web project, which was trying to run on port 10000 using IISExpress.  How did they get there?  I looked in Add/Remove Programs to get a clue as to what could have added these entries.  Who’s to blame?  The Azure SDK.  Azure Storage Emulator uses ports 10000-10002 and creates reservations for them.  This was installed during my attempts at getting command-line Web Publishing to work.

I never would have known anything about this unless I had read the Azure SDK documentation.  The error message I was given said nothing about port conflicts.  nothing led me down that path at all.  And it’s entirely possible no one else would have this problem unless they were running IISExpress on port 10000.

But the important takeaway from this is that NETSH will allow you to create reservations for port numbers that may conflict with other applications.

Adventures In Installing

A pretty common feature in applications is the ability to automatically update when a new version is available.  Of course many designs have been created to address this, from having pre-launchers, to ClickOnce, to web services, to notifications, and on and on.  There’s plenty of ways to solve the problem, each with its own set of benefits and drawbacks.

The design I recently faced was one where the app would launch, check the database for a new version and if one existed, would display a notification, launch the installer and exit the application.  A couple of things were less than ideal with this.  First, the installer would be the standard interactive install, so you got used to hitting Enter 3 times to jump through the screens.  Second, after install, you’d need to relaunch the application.  So I decided to try and resolve these issues.

The first step I thought would be easy.  I would launch the install using MSIEXEC and use the /QR to make the install non-interactive.  This seemed really nice until a bug surfaced where the /QR switch would not perform an uninstall of the previous version, resulting in multiple entries in the Add/Remove Programs list.  This bug was reported back in 2010 and with VS 2012 coming out, I guess it will never be resolved.  With a lot of trial and error, since there seems to be no workaround for the problem on the Internet, I found that the /PASSIVE switch will uninstall the old version, so that was my new plan.  However, with /PASSIVE, there is no notification the install is complete.  That’s fine for now, because I was going to make the app relaunch after completion.

After a lot of study on custom actions, I got the application to launch after the install.  Now I have a problem where the application is being launched as SYSTEM instead of the current user.  This would make the database access fail.  More trial and error, because there doesn’t seem to be any info on this issue either, and I found that when you choose the InstallAllUsers=true option, MSIEXEC runs as SYSTEM, which makes sense since it would need access to write to the All Users sections.  But if you set InstallAllUsers=false, then MSIEXEC runs as the current user, which then would launch the application as the current user and all would be well.  That is, if you’re willing to give up the All Users install.

adsutil.vbs Error 462

While trying to create a script to stop and start web sites on multiple servers, I got an error on 3 of the four servers:

The remote server machine does not exist or is unavailable
ErrNumber: 462 (0x1CE)
Error trying to open the object: w3svc/8

Capture1

After a lot of hunting around, I discovered that the problem was that the Windows Firewall was turned on.

Capture2

I changed the Domain Profile to have the firewall disabled and left the others enabled.

Capture3

Running the script again, I was able to connect to the remote computer and stop the web site.

Capture4

Staying On The Correct Path

In a current task where I had to consolidate the structure of a website and organize the files better, I ran across this interesting quirk.  When developing, we work in a virtual directory on our local machine, while on a real server, it runs in the root directory.  This poses problems whenever we want to use relative paths to images, style sheets, etc.

The key to fixing this is the VirtualPathUtility, which has the logic in it to determine the root of the web application and return a proper path.  I thought it would be easy to just use this object right in the markup like:

<head runat="server">
    <title></title>
    <link id="cssLinkOutside" href='<%=System.Web.VirtualPathUtility.ToAbsolute("~/StyleSheet.css")%>' rel="stylesheet" type="text/css" />
</head>

That didn’t work.  The rendered HTML turned out to be:

<link id="cssLinkOutside" href="&lt;%=System.Web.VirtualPathUtility.ToAbsolute(&quot;~/StyleSheet.css&quot;)%>" rel="stylesheet" type="text/css" />

Pretty literal.  The cause of this odd behavior is that the HEAD tag is set to runat=”server”.  If that piece is taken out, the embedded code works well.  So if you need the HEAD to be a server control – like when using themes – then what?  You can add code in the code-behind to do an attributes.add() on the LINK tag.  But having to add code in two places for such a simple need is just too much, especially when I was looking at updating a couple dozen pages.

The workaround is kind of surprising: Wrap the tag that contains dynamic code in a placeholder.

<head runat="server">
    <title></title>
    <asp:PlaceHolder runat="server" id="holder">
        <link id="cssLinkInside" href='<%=System.Web.VirtualPathUtility.ToAbsolute("~/StyleSheet.css")%>' rel="stylesheet" type="text/css" />
    </asp:PlaceHolder>
</head>

This renders the tag properly:

<link id="cssLinkInside" href='/WebTestbed/StyleSheet.css' rel="stylesheet" type="text/css" />

Now This is Something Worth Looking Into

When you see something like this in the call stack, you have to know more:

[InvalidOperationException: This SqlTransaction has completed; it is no longer usable.]
   System.Data.SqlClient.SqlTransaction.ZombieCheck() +1623536
   System.Data.SqlClient.SqlTransaction.Rollback() +172
   Framework.Common.Database.RollbackTransaction() in C:\Framework\Common\Database.vb:413 
   Test.uxCreate_Click(Object sender, EventArgs e) in C:\Test.aspx.vb:47
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691

And the error message is interesting as well: “This SqlTransaction has completed; it is no longer usable”.

A little background on what is going on: this is a database class that is managing a SQL transaction to be used by multiple objects.  The database object instance gets passed along to the different objects and they use it, participating in the transaction.  Somewhere along the way, maybe a commit is occurring and then the transaction becomes invalid.  That’s how it seems.

Tossing in a bunch of debug.writelines to see what what happening inside the methods popped up a message about a SQLException being raised because of a non-existent column name.  Fixing the schema problem fixed the zombie problem.  But what was the reason for the original error?

Let’s say you bring a sandwich into work.  You give that sandwich to someone and tell them to put it in the refrigerator for you.  This person (the fridgemaster) puts it in the fridge and comes back to the refrigerator a little later to find your sandwich moldy and spoiled, so he throws the sandwich out.  Later on yet, you go to the fridgemaster and ask for your sandwich.  He says “this sandwich has spoiled; it is no longer usable.”  In response to your puzzled look, the fridgemaster says “I did a ZombieCheck and it was moldy.”

In coding terms, the order of events was: TX started, SQL error occurred, TX rolled back (by SQL Server), SQLException raised and caught, TX rolled back in catch block (by user code) and unable to because the TX already was rolled back by SQL Server.  This rollback behavior is dependent on the severity of the error. In the case of the schema error, which presumably was interpreted as “this will NEVER work”, this equated to being severe enough to roll back the transaction.