Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Friday, July 06, 2018

Visual Studio : You need to find somefile.cs to view the source

Debugging through some socket code and suddenly the debugger came up with the above when I tried to step into the .NET code.

It was asking for NetworkStream.cs , Socket.cs etc.

Trying to browse to the file wasn't helping.

So Mr. Google to the rescue.

The solution is:

Visual Studio / Tools / Options / Debugging / General / Enable source server support

Problem solved.

Enjoy!

Tuesday, January 23, 2018

Visual Studio : Unable to start debugging on the web server. A debugger is already attached.

Came across this error when we had more than one person working on a VS project which is hosted on a VM.

The setup script for a new user gives each person their own web site.

Because there is only one version of IIS, when multiple people try and debug their version, you get the error:

Unable to start debugging on the web server. A debugger is already attached.

The solution turned out to be simple. The debugger attaches to a process which is itself attached to an application pool.

Give each user an application pool i.e. make a new one in IIS Manager.

Attach each person's web site to their application pool in IIS Manager.

Just make sure that the pool is configured the same way as the original e.g. same .NET framework and managed pipeline.

Problem solved!

Enjoy!

Monday, October 30, 2017

Visual Studio : Unable to connect to web server IIS Express

This is with VS 2017.

I was looking at a .NET Core project and wanted to change from http to https.

So under Properties / Debug, I checked the "Enable SSL" checkbox.

This changes the port so I then did a copy / replace of the old port to the new one and changed the URL to https e.g.

http://localhost:5000 became https://localhost:44326

Then I got "Unable to connect to web server IIS Express".

Consulted with Mr. Google.

The solution that worked for me was to:
  • Close the VS project
  • In File Explorer, navigate to the project and delete the entire ".vs" folder
  • Restart the project
  • Run as "Debug"
  • Works
Apparently, it has something to do with the "applicationhost.config" file.

 Enjoy!

Monday, July 17, 2017

VS : Cannot pull because there are uncommitted changes

Using VS 2015.

The full error is:

"Cannot pull because there are uncommitted changes. Commit or undo your changes before pulling again. See the Output window for details."

So annoying. This happens a lot when trying to pull.

Install Git Bash.

In Windows Explorer, navigate to the directory where your project is and right click.


$ git status
On branch somebranch

...

Check you are on the right branch. You will get messages about the difference with master.

Then:

 $ git pull

Back to VS. Now you get a message about files being updated outside of VS.

Just "Reload all".

Job done!

Enjoy!

Wednesday, April 12, 2017

Visual Studio : ReplacableToken_ApplicationServices on transform

Using VS 2015 and doing a transform on my web.config.

My connection string is something like:

connectionString="data source=.\SQLEXPRESS;Integrated Security ..."

but what appears in the transformed file is:

connectionString="$(ReplacableToken_ApplicationServices-Web.config Connection String_0) ..."

WTF?

Much conversation with Mr. Google and eventually the solution is:

<AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>

You need to add this to the appropriate .pubxml file under Properties\PublishProfiles

Enjoy!

Tuesday, November 01, 2016

Visual Studio : VS 2015 Enterprise takes ages to start up

And it gets slower and slower.

Then I found Slow Visual Studio Performance … Solved!.

Essentially "Delete everything in C:\Users\\AppData\Local\Microsoft\WebSiteCache".

As you load up your projects, the first time they will run slower as it rebuilds the cache but it seems to be a good idea to clear this cache out once in a while.

Use at your own risk but wow - what a difference in start-up!

Enjoy!

Thursday, May 14, 2015

Visual Studio : No STS tool

Inspired by this question on stackoverflow regarding the missing STS tool in VS 2013:

Add sts reference missing in visual studio 2013 update 4

From my answer:

"FedUtil and the "Identity and Access Tool" are no longer available.

The only way to do this is via "Change Authentication" when you create the project and then select "On Premise". Unfortunately, you can only do this when you create the project. You can't retrofit it afterwards. I believe this is changing in VS 2015.

Part of the reason for the tools disappearing is that these tools were WIF based whereas OWIN is the basis for all new VS development.

You can merge the WIF section from the web.config of an old WIF project"

So how do you do the last part.

Create a new project in VS 2013 - I choose MVC - and under "Change Authentication" select "No authentication".

Now find a VS2012 project of yours that uses WIF - with .NET 4.5

Use something like WinMerge and merge the two web.config.

Copy these over:

<configSections>
    <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</configSections>


<system.web>
    <authentication mode="None" />
    <authorization>
      <deny users="?" />
    </authorization>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>


<system.webServer>
    <modules>
      <add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
      <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
    </modules>
  </system.webServer>

as well as the "ida:" lines under appSettings

and the entire system.identitymodel and system.identitymodel.services sections.

Obviously you need to update the URL of your target application .( I assume your IDP and certificates are still the same and are still valid otherwise you need to update them as well).

Add References to:

  • System.IdentityModel
  • System.IdentityModel.Selectors
  • System.IdentityModel.services

Add a NuGet package from Package Manager:

Install-Package System.IdentityModel.Tokens.ValidatingIssuerNameRegistry -Version 4.5.0

and you are done.

Enjoy!

Tuesday, March 31, 2015

Visual Studio : Missing metadata

Out of the blue, starting getting:

Metadata file '...\abc\xyz.dll' could not be found

Look in the folder - there it is - WTF?

Mr. Google and figured out that something had changed in my build order.

To get the build order, right click the solution - "Project Build Order".

Then build all the dll first and then the projects that consume the .dll.

You can do this by playing around with the dependencies.

Enjoy!

Wednesday, March 11, 2015

WIF : WIF10201: No valid key mapping

The full error is:



WIF10201: No valid key mapping found for securityToken: 'System.IdentityModel.Tokens.X509SecurityToken' and issuer: 'http://xxx/adfs/services/trust'.


This is with ADFS 3.0 and the base VS 2013 with ASP.NET MVC.

Long discussion with Mr. Google - many entries, many explanations - "remove the trailing slash" , blah, blah, the most bizarre was "This is because WIF doesn't support SAML".

Yes - that statement's true but WTF does it have to do with the problem?

Google quality is getting exponentially worse and worse.

I knew this error rang a bell and after some quite reflection I remembered why. Vittorio had mentioned it:


His article didn't apply in my case because I get the error straight away - the home page doesn't display so there's no "Sign up for this application" link.

The article goes on to say that this "issue will be fixed soon".

So I took a punt and upgraded to VS 2013 Update 4.

Created a new project - problem solved.

Enjoy!

Tuesday, January 06, 2015

Visual Studio : Missing dll

So there I am - back to work in 2015 and rebuilding a MVC project which I haven't touched for a while and bang - error after error after ...

WTF - Happy New Year!

A long conversation with Mr. Google and:

Errors like:

Could not load file or assembly 'file:///C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Microsoft.VisualStudio.Web.Publish.dll' or one of its dependencies. The system cannot find the file specified.

and

Could not load file or assembly 'file:///C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Web Tools\Scaffolding\Microsoft.AspNet.Scaffolding.VSExtension.12.0.dll' or one of its dependencies. The system cannot find the file specified.

and

Could not load file or assembly 'file:///C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Web Tools\Languages\Microsoft.VisualStudio.JavaScript.Web.Extensions.dll' or one of its dependencies. The system cannot find the file specified.

etc.

This is related to VS 2013 Update 4 with ancillary suspects the Azure SDK 2.5 and O365 API Tools.

The solution is to repair VS 2013 Update 4.

I have Windows 7 so:

Control Panel - Programs and Features - Installed Updates - Visual Studio 2013 Update 4 (KB2829760) - Repair.

Just take a looong break while it's running.

Enjoy!

Wednesday, May 28, 2014

Visual Studio : Extending the user profile for organisational accounts in Azure

When you use VS 2013 and choose the web application option and then change the authentication options to use organisational accounts, you get a lot of template code which shows you some of the attributes in the user profile derived from Azure Active Directory (AAD).

You can see this if you click on the name of the logged-in user once the application is running and you have authenticated.

What if you want to extend this?

The first step is to find out what the attribute is called?

The easiest way to do this is to use the Graph Explorer.

Click "Use Demo Company" then "Get" then click on:

"https://graph.windows.net/GraphDir1.OnMicrosoft.com/users".

You'll get a list of the AAD schema attributes e.g if you want the user department, you'll see the name is "department".

In the VS project under "Models / HomeViewModels.cs" add another line e.g.

public string Department { get; set; }

Under "Views / Home / UserProfile.cshtml" add another line e.g.

<td>Department</td>
<td>@Model.department</td>
This uses Razor syntax - you may have something different but you get the general idea.

The key to this is under "Controllers / HomeController.cs" where:

UserProfile profile = JsonConvert.DeserializeObject(responseString);
 leverages the power of the JSON library to serialize the attributes you have defined.

Job done.

Enjoy!

Tuesday, April 01, 2014

Visual Studio : Unable to locate NuGet.exe

Actual message is:

Error - Unable to locate 'C:\.....\.nuget\NuGet.exe'   

You sometimes get this when building a project that you cloned from GitHub.

Under .nuget/nuget.Targets in your project, change:


<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false ...
 
to 
 
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">true ...

Enjoy!

Thursday, October 31, 2013

Visual Studio : Version issues

Once upon a time, we had VS 2010 and a tool called FedUtil which could be run many times to change the WIF parameters for different hosts, certificates etc.

Also, FedUtil could be run standalone so you could use it on different boxes when you promoted a build from e.g. Dev to Test.

There was no internal STS so we all used SelfSTS.

Then we had VS 2012, where FedUtil morphed to the "Identity and Access Tool" which added some capability but could no longer be run standalone. The "Identity and Access Tool" could be run many times.

It included an internal STS.

Now we have VS 2013 which has a "Change Authentication" feature invoked when you create a project.

There is no internal STS.

You cannot run it standalone and worse of all you cannot run it after the project has been created.

So what happens when I want to migrate my VS 2012 projects to VS 2013?

This SUCKS massively big time.

Is there anyone at Microsoft that actually uses these tools in the real world. Because if there was they wouldn't introduce such restrictions.

Seriously people, get your stuff together!

If you agree, vote here:

In VS 2013, allow ability to run the "Change Authentication" wizard AFTER project is created

Enjoy!

Monday, July 29, 2013

Visual Studio : Could not write lines to file xxx Access to the path yyy is denied

Using Visual Studio 2012, checked a project into TFS and got the above error.

WTF?

Mr. Google to the rescue and the majority view was either:
  • Make the file readable i.e. no readonly
  • Delete the /bin and /obj directories and rebuild
The file was R/W already so went for option 2 and the error disappeared.

All good!

Enjoy!


Friday, November 16, 2012

Visual Studio : Cannot import the following key file

 

When you have a signed project in TFS, every time a new person gets it out, they have this problem. So they create a new certificate, check it all in and the next person has the same problem. WTF.

The error is:

“Cannot import the following key file: xxx.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_blah”

Mr Google to the rescue. Found a number of “solutions” but then stumbled across one that worked.

In the project properties under “Signing”, click the dropdown arrow and click on the pfx file name. This invokes the password dialogue so you can type in the new password and Bingo!

All then compiles.

Enjoy!

Wednesday, September 05, 2012

Visual Studio : XML comments

 

Also called programmatic comments or xml documentation.

If you have a method like:

public void blah (String a, int b)
{

}


and you want the comments, just type /// on the line before and you get:



/// <summary>
///
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public void blah (String a, int b)
{

}


If you have ReSharper, put the cursor over the method name i.e. “blah” and press Ctrl / Shift / F1.



You get a neat popup window.

Enjoy!

Wednesday, February 29, 2012

Visual Studio : "Set As Start Page" doesn't work in the real world

I have a web site that contains a "Default.aspx" but I want the start page to be "abc.aspx".

So in Visual Studio 2010, I right click the "abc.aspx" page and select "Set As Start Page".

Hit F5 - works perfectly.

Deploy it to a real IIS 7 server and WTF - Default.aspx is displayed in all its delights?

Turns out the "Set As Start Page" option only applies to Cassini - the VS internal web server (which is why it works when you hit Run ( = F5)).

In the real world, you have to go to the web site inside the IIS Manager, select "Default Document" and then type abc.aspx and move it up to the top.

There you go!

Enjoy!

msdeploy : Package installation failed - 'managedRuntimeVersion' differs

So there I was trying to use msdeploy to deploy a web site from Visual Studio 2010 into an IIS 7 server on another box using the "Build Deployment Package".

I got the error:

The package installation failed.
Details:
The application pool that you are trying to use has the 'managedRuntimeVersion' property set to 'v4.0'. This application requires 'v2.0'.

My web application used the "Default Web Site" and the application pool that it was connected to (DefaultAppPool) was .NET Framework 2.0. Yeah - I screw around with IIS a lot!

Of course, where I was deploying it to was the more usual .NET Framework 4.0.

Mr. Google to the rescue and the answer is to set the following options under the project / Properties / Package/Publish Web:



You need to tick the two text boxes "Include IIS Settings" and "Include application pool settings".
And away you go with msdeploy.

Enjoy!



Wednesday, February 08, 2012

Visual Studio : Showing the active file in the Solution Explorer tree

So there I was doing some consultancy work on site and I noticed that when you click through the open files in the file bar on the top, their Visual Studio tracks the active file in the tree.

Something I've always thought would be really useful.

Turns out the way to do this is via:

Tools / Options / Projects and Solutions / General / Click "Track Active Item in Solution Explorer".

WTF isn't this the default?

Enjoy!

Thursday, November 24, 2011

Visual Studio : Web deploy - Files\IIS\Microsoft was unexpected at this time

Built a project using the standard VS 2010 SP1 - Right click on the project - Build Deployment Package.

Then tried to deploy it via:

xxx.deploy.cmd /T

The /T does a whatif - always a good idea to check first!

Then run the following when you are happy:

xxx.deploy.cmd /Y


Got the error - "Files\IIS\Microsoft was unexpected at this time". WTF?

First off when you set the environment variable as per the txt file:

set MSDeployPath="C:\Program Files\IIS\Microsoft Web Deploy V2\"

Do NOT put the quotes in and remove the end \ i.e.

set MSDeployPath=C:\Program Files\IIS\Microsoft Web Deploy V2

What the script does is search for this variable and if it's missing, it tries to find the path in the registry via this code:

if "%MSDeployPath%" == "" (


for /F "usebackq tokens=1,2,*" %%h in (`reg query "HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy" /s ^
findstr -i "InstallPath"`) do (

if /I "%%h" == "InstallPath" (

if /I "%%i" == "REG_SZ" (

if not "%%j" == "" (

if "%%~dpj" == "%%j" (

set MSDeployPath=%%j

))))))

I have Web Deploy V2 deployed and I don't have such a registry entry? It's this piece of script that produces the error. Just comment it out and all will be sweetness and light.

Enjoy!