Problem/Solution: Error in publishing ASP.NET MVC with MvcBuildViews ON from Visual Studio 2012

Note: This post is contributed by Matthew Seng. He is one of my colleagues and we are working in same project together.

ASP.NET Publish Error

Error Message

It is an error to use a section registered as allowDefinition=’MachineToApplication’ beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

Steps to replicate the issue

  1. Create a new ASP.NET MVC 4 project in Visual Studio 2012
  2. Set true to MvcBuildViews in csproj (<MvcBuildViews>true</MvcBuildViews>)
  3. Publish the project. (Observe: it will work fine.)
  4. Publish it again (Observe: You will see the error message and you won’t be able to publish the project anymore.)

Temporary solution:

  • Delete obj folder from your MVC project.

Permanent solution:

  • Delete obj folder from your MVC project.
  • Add the following below the MvcBuildViews property:<BaseIntermediateOutputPath>..\obj</BaseIntermediateOutputPath>

Root cause:

MvcBuildViews property (This is to allow view errors to be shown when building solution) set to true in project file and multiple web.config confuses compiler. Learn more at:

Tips for setting up TeamCity with SQLExpress

Team City + SQL Express 2012

Jetbrains has a nice document for setting up an External Database but i run into a few problems and it took me a while to figure out it so I thought I could share it here and hope that it might be helpful for those who are having the same problem.

Here is the link for the installers and its versions.

The following are the issues that I faced when I was setting up the SQL express an external database for TeamCity.

Issues

  • teamcity SQL exception: Network error IOException: Connection refused: connect
  • SQL error when doing: Connecting to MSSQL: I/O Error: SSO Failed: Native SSPI library not loaded. Check the java.library.path system property.
  • SQL exception: Cannot open database “TeamCityDb” requested by the login. The login failed
  • Database is empty or doesn’t exist

Connection string in database.properties file

The string below is the connection string that I am using in database.properties file.

connectionUrl=jdbc:jtds:sqlserver://localhost:1433/TeamCityDb;instance=sqlexpress

Ok. I am going to share the problem/solution one by one here.

#1. Connection refused: connect

Error: teamcity SQL exception: Network error IOException: Connection refused: connect

Root cause: I got this error because JTDS JDBC driver connection string in database.properties file is using TCP/IP and SQL express comes with TCP/IP disabled by default.

Solution:

  1. Open SQL Configuration Manager
  2. Go to “Protocols for SQLExpress” under “SQL Server Network Configuration”
  3. Open the properties dialog of TCP/IP and select “Yes” for Enabled
    TCPIP in SQL Server Configuration Manager
  4. After that, go to “IP addresses” and set 1433 to “TCP port” property. Note: Please refer to my connection string above. I am using 1433 port but if you are using different tcp port then you need to set your port in this property.
    TCPIP in SQL Server Configuration Manager - 1

#2. Native SSPI library not loaded.

Error: SQL error when doing: Connecting to MSSQL: I/O Error: SSO Failed: Native SSPI library not loaded. Check the java.library.path system property.

Root cause:This error occurs because I am using windows authentication and I didn’t put the correct build of ntlmauth.dll. If you are using windows authentication, you need to copy ntlmauth.dll from \jtds-1.3.1-dist\x86\SSO\ folder to \TeamCity\bin folder. But I wrongly copied that dll from x64 folder instead of x86 so I was getting this error message.

Solution:   Copy ntlmauth.dll from \jtds-1.3.1-dist\x86\SSO\ folder to \TeamCity\bin folder. “x86” not “x64”.

#3. Cannot open database “TeamCityDb” requested by the login.

Error: 

Cannot open database “TeamCityDb” requested by the login. The login failed.
SQL query: connect
SQL exception: Cannot open database “TeamCityDb” requested by the login. The login failed

Root cause: There is no database called “TeamCityDb”  in SQL express.

Solution: Please create new database called “TeamCityDb” in SQL express.

#4. Database is empty or doesn’t exist

Error: Database is empty or doesn’t exist 

Error #2: Could not take a connection from data source: Cannot open database “TeamCityDb” requested by the login

Root cause: I am not very sure about it but the troubleshooting guide for Team City said that it’s something to do with database schema but I already gave the sysadmin role to “NT Authoriy\System” in SQL but still couldn’t solve the issue.

Solution: 

  1. You will see the error message below when you access the webapp of TeamCity. Please click on “I’m a server administrator. show me the details” link. It will ask you to enter the token. You can get the token under \TeamCity\logs\teamcity-server.log.
    TeamCity Database Creation - 2
  2. Enter the token and you will see this screen.
    TeamCity Database Creation
  3. Just click on “Proceed” and wait a few minutes while TeamCity is setting the settings.

Yap! Those are the issues that I faced when I was setting up SQL express for TeamCity. Hope you find it useful. Please feel free to share your TC tips/tricks with me and my blog readers too. Thanks!

SlowCheetah + ClickOnce Issue

If you are using SlowCheetah + ClickOnce in your project,

Demo: ConsoleApplication6.rar (4.93 MB)

SlowCheateh+ClickOnce

Error 1 Could not copy the file “bin\Release\ConsoleApplication6.exe.config” because it was not found. ConsoleApplication6

Steps to replicate

  1. Create a console application in VS 2012
  2. Add transformation to your config. (If you already have SlowCheatah tool installed, it will automatically download the SlowCheetah package from nuget. Otherwise, please add it manually)
  3. Publish (Observe: It will work)
  4. After publishing, please try to build or publish again. (Observe: You will see the error above.)

Solution

  • Delete “app.manifest” under “Properties” in Solution Explorer.
  • If you don’t see that file, go to Properties -> Security and check/uncheck “Enable Clickonce security setting”. It will re-generate that manifest file.
  • Note: If you are a ClickOnce user, you might check this project “Shimmer (It’s like ClickOnce but Works™)” as well.

SlowCheateh+ClickOnce - Solution

Visual Studio 2012 – Exception in adding new controller to MVC4 project

Problem: VS11 (Visual Studio 2012) throws the following exception when I add new controller in ASP.NET MVC4 project.

VS 2012 issue with MVC 4

—————————

The templates had the following 1 error(s) when running:
—————————
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates\AddController\Controller.tt(-1,-1) : error : There was a problem getting an AppDomain to run the transformation from the host. The process cannot continue.

—————————
OK
—————————

Environment

  • Windows 7 Professional (Version 6.1 – Build 7601: Service Pack 1)
  • Microsoft Visual Studio Ultimate 2012 (Version 11.0.60610.01 Update 3)
  • Microsoft .NET Framework Version 4.5.50709

Workaround

Just restart the Visual Studio.

Note: There is a bug report VS 11 – Error when Attempting to Add New Controller to Project in MS connect but as of now, there is no official word on this issue. I will update this post again if I get any input from somewhere.

Update #1.

I got another exception when I try to add new view to the same project.

VS 2012 issue with MVC 4-2

—————————
The templates had the following 1 error(s) when running:
—————————
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates\AddView\CSHTML\Empty.tt(-1,-1) : error : There was a problem getting an AppDomain to run the transformation from the host. The process cannot continue.
—————————
OK
—————————

Canon MG3170 / MG3100 Printer Driver Issue

Note: It’s just a nonsense post that I wrote when I got nothing better to do. :) 

My good old printer “Canon MP198” went to coma last month after working for me about 5 years.  It’s sad but no choice. I have to move on and buy a new one “Canon MG3170” which is a sibling of my good old printer today. She(It) looks stunning with red dress. She can do scanning, printing, copying very well just like her old sibling used to do but she got something called Wi-fi that I never tried it before.

mg3170-b6_v3

I am quite happy with that red little girl but the problem comes when I start asking her to do a test print. She doesn’t understand me at all. We have a communication issue. I am stretching my head to find the solution about how to communicate and then I realize that I am having problem in getting rid of my old communication pattern that I used to use with her old sibling. That’s why I keep on getting this response whenever I tried to talk to her.

—————————
MP Drivers
—————————
Printer driver is currently in use. If you are not using the printer driver, it may be used by other users on this computer.
Exit all applications and printer properties and then try again.
If you still have a problem, restart the computer and then try again.
—————————
OK
—————————

MP Drivers Uninstallation

So, I start getting rid of everything related to my good printer but the auto-setup communication program that comes with my new red little girl still doesn’t work. Then, I decided to take the protocol from auto-setup and give it to her directly then it works like a charm. I ask her to do some printing, scanning and copying now and she perform well like a good little girl. Thanks girl! You made my day beautiful! :)

Printer

.NET 4.5 – Visual Studio Web Designer API bug

Recently, we developed one REST service using ASP.NET Web API. We have used a lot of  async/await in that projects. Before we deploy this project on our staging web server that has a few ASP.NET 4.0 websites, we installed .NET 4.5 on one of our local server and requested QA team to test all of our existing ASP.NET 4.0 websites. I know that it’s the extra effort for our QA team but we got no choice since .NET 4.5 can’t be installed side by side with .NET 4.0. Luckily, QA reported only one issue that I am going to share in this post.

The error message that we got is as below.

Error Message: The ‘VirtualItemCount’ property cannot be set declaratively.

.NET 4.5 error

There is a custom control that we are using in our exisitng ASP.NET 4.0 project. There is the code that set VirtualItemCount in aspx but it stopped working after installing .NET 4.5 on the server.

Unfortunately, it turns out that it’s a known issue that has been reported in MS Connect. You can read about this bug report here. Microsoft didn’t mention about fixing this bug so far but there is a workaround that you can use before Microsoft release the fixes.

Workaround

In the meantime, you can apply an easy workaround which is to set the custom control’s property value in code behind and remove the affected property from the mark up.