Ideas and thoughts about Microsoft Identity, C# development, cabbages and kings and random flotsam on the incoming tide
Friday, July 06, 2018
Visual Studio : You need to find somefile.cs to view the source
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.
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
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
Enjoy!
Monday, July 17, 2017
VS : Cannot pull because there are uncommitted changes
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
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
Then I found Slow Visual Studio Performance … Solved!.
Essentially "Delete everything in C:\Users\
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
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
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
WIF10201: No valid key mapping found for securityToken: 'System.IdentityModel.Tokens.X509SecurityToken' and issuer: 'http://xxx/adfs/services/trust'.
Tuesday, January 06, 2015
Visual Studio : Missing dll
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
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.
This uses Razor syntax - you may have something different but you get the general idea.<td>Department</td> <td>@Model.department</td>
The key to this is under "Controllers / HomeController.cs" where:
UserProfile profile = JsonConvert.DeserializeObjectleverages the power of the JSON library to serialize the attributes you have defined.(responseString);
Job done.
Enjoy!
Tuesday, April 01, 2014
Visual Studio : Unable to locate NuGet.exe
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
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
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
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
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
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
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
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!
