Subscribe Now: Feed Icon

Thursday, November 8, 2012

VS2010: “The project type is not supported by this installation.”

Before I found the extension for Windows Live Writer – Paste as Visual Studio code I had (for 3 days) used Code4Blog Extension but I was dismayed by it’s bugs (I opened some of them). I had this draft lying around and decided to just post it because it seems many people suffer from this exception.

In the extension’s page the author wrote:

“Code4Blog is now published on CodePlex. You are welcome to work with the source code directly!”

So I have decided to do just that.

Opening the solution I got the following error in the output window:

C:\…\Code4Blog\Code4Blog\Code4Blog.csproj :

error  : The project file 'C:\…\Code4Blog\Code4Blog\Code4Blog.csproj' cannot be opened.

The project type is not supported by this installation.


So I kinda guessed it has to do with a project for extending VS. But why doesn’t VS2010 give me what project type is missing?

Looking inside the project file (good thing that the project was down Winking smile):


I found the project type here:


 <ProjectTypeGuids> {82b43b9b-a64c-4715-b499-d71e9ca2bd60};

Searching for the first Guid on the list, I found this forum. From there I got to the Extending Visual Studio page and from there to the Visual Studio 2010 SDK. After installing that (you should close VS even though it doesn’t ask you to, because otherwise you won’t be able to open the project) the project worked.

I later found this site with a list of Guid and what they mean some of it is still relevant for VS2010. The only Guid not there was the first I searched for (damn you Murphy) {82b43b9b-a64c-4715-b499-d71e9ca2bd60} (the others mean WPF project and C# project respectively).

Well it might have worked but building failed because one of the resources didn’t work (icon) and changing it to another caused my VS to hang on the build – maybe I should have uninstalled the extension first? Killed the devenv, uninstalled the extension and the build passed.

In the end I decided the hassle was just to great and just used “Paste as Visual Studio code”. If you want to read about all the options I went through you can read them here.



Code4Blog Extension page

Code4Blog CodePlex page

Extending Visual Studio page

Visual Studio 2010 SDK

VS2010 Project Type Guids

Thursday, May 31, 2012

Silverlight: TextBox binding only works when control not in focus

Yesterday I got to the point that most of my priority one tasks were done ahead of schedule so I have decided to go back to old controls and rewrite them to work with the MVVM pattern. I even got to an old argument with my co-worker Felix about using code behind for UI purposes (he is a firm believer in Expression Blend but for implementing Watermarks he decided to use code behind – I refactored it using this).

So after fixing the Watermark and the AutoCompleteBox that used a service to populate the items in the code behind (using this) I got down to the actual minor functionality tweaks. Like when the user presses enter in AutoCompleteBox or TextBox some Action is triggered. For the AutoCompleteBox I used the Attached Property Approach (I changed it a bit to be for KeyUp instead of KeyDown) just without the CommandArgument since the selected item was already with Data Binding. And it worked just fine.

But with TextBox this approach just didn’t work – because TextBox binds the data only when it is out of focus!

I found some more people with the same problem:

Go4Answers: TextBox TextChanged event doesn't cause data binding to update

Silverlight Forum: TextBox TextChanged event doesn't cause data binding to...

They used the behavior solution (which while browsing for solutions I missed (I guess I am turning lazy because in StackOverflow I would have gotten the right answer in the first page/answer)). I just decided to use the CommandArgument from Attached Property Approach (the same one I didn’t need for AutoCompleteBox):

<TextBox Text="{Binding Path=SomeText, Mode=TwoWay}" Components:EnterKeyUp.Command="{Binding Path=EnterSomeTextCommand}"
            Components:EnterKeyUp.CommandArgument="{Binding Path=Text,RelativeSource={RelativeSource Self}}">

The View Model:

public RelayCommand<string> EnterSomeTextCommand
    private set;

(using GalaSoft MvvmLight)

Now you can just use the value.



@yesez5 in the comments have added his blog post (in Spanish, or in English (using Google Translate)) about using a built-in behavior from the Prism Library (that way you don’t even have to add code implementations for Action triggers or Behaviors in your project).



IBlog<Johan>: Silverlight Watermark TextBox Behavior

Peter Kuhn: Using the AutoCompleteBox

StackOverflow: Invoke Command When “ENTER” Key Is Pressed In XAML (and Answer)

Go4Answers: TextBox TextChanged event doesn't cause data binding to update

Silverlight Forum: TextBox TextChanged event doesn't cause data binding to...

Zoltan's Dev Corner: Binding update on TextBox.TextChanged event using Behaviors

GalaSoft MvvmLight

Lightside: Update TextBox binding when the value changes

Sunday, May 20, 2012

Default Browsers bug in VS2010

If you don't know (or haven't encountered it yet) there is a bug in VS that causes the settings of the default browser to not save.

For example: I am using Firefox as my default Windows browser but prefer debugging using IE (mainly because if IE dies my browser is still alive). And I have to change the browser much too often.

There isn't a fix for this but there is a workaround:

From VS -> Tools -> Extension Manager


-> Online Gallery -> Search:

WoVS Default Browser Switcher


Download and install the extension and when prompt restart VS.

Now in VS: View -> Toolbar -> enable: Default Browser Switcher


And you will get:

(image from WoVS Default Browser Switcher extension page)

And you will see what default browser is turned on.


I prefer putting it just below the debug toolbar so that it will be in front of my eyes but you can place it where ever you may like…


There is also a context menu for viewing web pages but it is not as useful as the toolbar.

You can read more about it here.




Microsoft connect: VS2010 forgets default browser settings

Extension: WoVS Default Browser Switcher

Wednesday, May 9, 2012

A day without the Debugger

On Sunday morning I found out the Visual Studio 2010 Debugger has stopped working for me. It wasn’t isolated to a single project or technology. Attach to process didn’t work in Silverlight and running Unit Tests in debug mode gave the usual “The breakpoint will not be hit. No symbols have been loaded for this document.”:


Visual Studio was in Debug mode just didn’t pass through any breakpoint (just to check that the Unit Tests used the latest build I added Assert.Fail and the Unit Test failed).

So, first I thought to give myself a challenge and try to work without a debugger. All was of the good until I had a small and stupid bug that I was sure I could just solve using Unit Tests, but the server side worked and I could see the data passing from the client using Fiddler. It didn’t help that in the front of my mind I just knew that with a Debugger this will be solved in minutes. So I dropped the challenge and started investigating the problem.


First I went through the usual suspects:


  • Restarted the computer
  • Enabled Just My Code (Options-> Debugging –> General), since I like having symbol debugging it was turned off
  • Reset the setting using Devenv.exe /resetsettings 
  • I decided against using Devenv.exe /SafeMode (but next time I will use it)

I was very close to trying the repair on the windows Control Panel. But then I noticed that while the debugger didn’t break on any breakpoint it did show a few BadImageFormatException exceptions being thrown, setting Visual Studio to break on those exceptions (Debug menu –> Exceptions… (or Ctrl+D+E) –> Find: “BadImageFormatException” and checking the thrown:


Running it again:

System.BadImageFormatException occurred
  Message=Could not load file or assembly 'dbghelp.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
       at System.Reflection.AssemblyName.nGetFileInformation(String s)
       at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile)
  InnerException: System.BadImageFormatException
       Message=Could not load file or assembly 'dbghelp.dll' or one of its dependencies. The module was expected to contain an assembly manifest.

Or just the Dlls:

  • dbghelp.dll
  • DDConfig.dll
  • LanguagePackage.dll
  • Microsoft.VisualStudio.Coverage.Symbols.dll
  • Microsoft.VisualStudio.ProgressionIcons.dll
  • Microsoft.VisualStudio.QualityTools.RecorderBarBHO100.dll
  • pidgenx.dll
  • SqlTDiagN.dll
  • SqlToolsVSNativeHelpers.dll
  • symsrv.dll

Searching the file system for one of them dbghelp.dll,the icon for the DLLs was for dotPeek which got me thinking about uninstalling JetBrains early access tools dotPeek and dotCover (after closing VS) – just to be sure it wasn’t them…

Trying Debug again and everything worked.


The weird part is trying to reinstall those apps (with the exact same MSIs) didn’t reproduce the problem. Looking back I remember restarting my computer before all this started but even restart won’t reproduce the problem.

Another case for the “computer's nondeterministic nature”…



Peter Gfader 's .NET Blog: VS2010 - Debugging not working

StackOverflow: debugging is not working in my visual studio 2010

MSDN Forums: Debugger not working on Visual Studio 2010

Wednesday, April 11, 2012

COMException: Abstract Data Types not supported

“Full” Exception:

System.Runtime.InteropServices.COMException: Abstract Data Types not supported [SHEMA.LAYER][STATE_ID = 0]


The real problem:

When calling:


(where workspace is IFeatureWorkspace)

with a layer that was not defined in the SDE. You will get the given error.


Why did it happen to me?

When we moved to Oracle we decided to create our tables using plain SQL and define our shape columns as SDO_GEOMETRY. This was done so other teams working on our DB on their computer won’t need to install SDE and could run Unit Tests using non geography data. Obviously we forgot to run the register command on one of our tables and I got this lovely exception…


The fix:

Registering the  layer using:

sdelayer -o register –s SERVER –u DB p PASSWORD –i SDE_INSTANCE -t SDO_GEOMETRY -e p –l  LAYER,shape -R 2 -C OBJECTID,SDE

(in red what you must change, blue should be according to your DB).


One ESRI exception mapped, an to go…

Sunday, March 4, 2012

Selecting Distinct Rows

Or how the definition of the request can get us confused?

One of my team members asked me today to help her in a SQL query and although I hate SQL I tried to help her. She wanted to select a row by a distinct field – ColumnA and to view other columns in that row, so I started the query with the distinct keyword:

  2. FROM SomeTable

But run into the problem that she wanted those other columns of the row which weren’t distinct.

So I Googled Distinct and got lost. After taking a coffee break I changed my search to “sql select id of first distinct” the first link was of StackOverFlow: SQL SELECT DISTINCT ID from copies ORDER BY CID

Which told me of course that I was using the wrong keyword and should have used the Group by keyword.

The end result query:

  1. SELECT *
  2. FROM SomeTable
  4.                     FROM SomeTable
  5.                     GROUP BY ColumnA)

Was what she wanted.

God bless coffee (and StackOverFlow)…



Saturday, March 3, 2012

SQL Server 2008: Forget a user/password

For a long time now I am stuck with a saved user in SQL Server 2008 that I just didn’t want to use:


Once upon a time I used that user (that has almost no permissions) for just one action – unfortunately I checked the “Remember password” and whenever I choose that server in the servers combo box I got that damn user. Well I finally had enough!

So I Googled “remove sql server 2008 user password Remember password” and found this StackOverFlow post.

The solution is fairly easy, just rename: C:\Users\%username%\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin to SqlStudio.bin0 (as a rule I never delete a file I don’t have a backup to). And now SQL Server doesn’t remember anything (not even the servers I was on):


But that is just a hundred times better than the previous headache…



StackOverFlow: Removing the remembered login and password list in SQL Management Studio

Thursday, February 9, 2012

PowerShell: Event Viewer saver

Two weeks ago I was helping out at my old company (it is part of my old contract with them). When one of my friends there told me they just can’t look at the Event Viewer anymore. Why? Well it seems another friend got a little overboard in logging stuff and the Event Viewer turned from logging Errors and important events to “real time logging” (their words). So being the helpful guy that I am I told them about PowerShell. I even pointed them to some blogs in the web.

Today I decided to follow my own advice and check out PowerShell (and maybe write something they could use). So I went through some basic tutorials (1, 2, 3 reading briefly, 4, 5, 6 (can be skipped), 7, 8, 9, there are more tutorials but they are not needed for this simple task). When following tutorials I sometimes like to use my own example, that way I can be sure I am understanding things like a human and not like a monkey (“Monkey see, monkey do”).

On the second tutorial I already knew I had to use ‘get-eventlog’ or the newer ‘get-winevent’ command (by using ‘get-command -Verb Get’ and looking at the options). By looking at the help for these commands (by using ‘get-help get-eventlog’) I found out that get-winevent needs newer operating systems (minimum Windows Vista) which are not available to my friends…


So what do I want my script to do?

1. Display only the errors from Event Viewer’s Application log (and filter by the application name).

  • Looking at the examples was enough for this:
  1. get-eventlog -logname System -EntryType Error
  • Wanting something more advanced (I learned that you shouldn’t use TimeWritten in the where since it is a string object, see sorting below):
  1. Get-Eventlog Application -After ([datetime]::Parse("2012-02-08 17:00")) | where {($_.entryType -eq "Error")}
  • This way you can “add” warnings not just errors:
  1. Get-Eventlog Application -After ([datetime]::Parse("2012-02-08 17:00")) | where {(($_.entryType -eq "Error") -or ($_.entryType -eq "Warning"))}
  • Adding sorting to view the errors from old to new, added difficulty because TimeWritten is a string with a problematic format (M/d/yyyy h:m:s AM/PM) that doesn’t work with string comparison:
  1. Get-Eventlog Application -After ([datetime]::Parse("2012-02-08 17:00")) | where {($_.entryType -eq "Error")} | select EntryType,InstanceId,Message,Category,Source, @{Name="TimeWritten";Expression={  ([datetime]::Parse($_.TimeWritten)).ToString("yyyy-MM-dd HH:mm:ss") }}  | sort -Property TimeWritten
  • Wanting to actually see the message (since PowerShell by default limits the column size):
  1. Get-Eventlog Application -After ([datetime]::Parse("2012-02-08 17:00")) | where {($_.entryType -eq "Error")} | select EntryType,InstanceId,Message,Category,Source, @{Name="TimeWritten";Expression={  ([datetime]::Parse($_.TimeWritten)).ToString("yyyy-MM-dd HH:mm:ss") }} | Format-list -Property EntryType, Source, Message, TimeWritten

2. Export the errors from 1 to a csv file (so that the errors will become less real time and more all time).

As seen in the bottom of tutorial 5:

  1. Get-Eventlog Application -After ([datetime]::Parse("2012-02-08 17:00")) | where {($_.entryType -eq "Error")} | select EntryType,InstanceId,Message,Category,Source, @{Name="TimeWritten";Expression={  ([datetime]::Parse($_.TimeWritten)).ToString("yyyy-MM-dd HH:mm:ss") }} | Export-CSV "EventErrors.csv"

3. Do an infinite loop that does 2 on new errors, so that errors in the night shift will be stored.

That was a bit more complex simply because I wanted to append rows to the CSV.

  1. $currentTime = get-date
  2. $currentDate = get-date -format "yyyy_MM_dd"
  3. if(test-path "EventErrors_$currentDate.csv")
  4. {
  5.     $record = Import-CSV "EventErrors_$currentDate.csv" | sort -Property TimeWritten | Select-Object -Last 1 | select TimeWritten
  6.     $currentTime = [datetime]::Parse($record.TimeWritten)
  7. }
  9. while($true)
  10. {
  11.     $currentDate = get-date -format "yyyy_MM_dd"
  12.     $data = Get-Eventlog Application -After $currentTime | where {($_.entryType -eq "Error")} | select EntryType,InstanceId,Message,Category,Source, @{Name="TimeWritten";Expression={  ([datetime]::Parse($_.TimeWritten)).ToString("yyyy-MM-dd HH:mm:ss") }}
  13.     $currentTime = get-date
  15.     if($data -ne $NULL)
  16.     {
  17.         if(test-path "EventErrors_$currentDate.csv")
  18.         {
  19.             "File EventErrors_$currentDate.csv exists, importing data."
  20.             $data = (Import-CSV "EventErrors_$currentDate.csv") + $data | sort -Property TimeWritten
  21.         }
  22.         $data | Export-CSV "EventErrors_$currentDate.csv"
  23.     }
  25.     Start-Sleep -s 20
  26.     "Ping $currentTime"
  27. }


  • The script won’t work if the file is opened in Excel (but the csv can be copied or opened with notepad).
  • You can adjust the sleep time, I choose 20 seconds.
  • Since it’s an infinite loop it can only be exited by Ctrl+C

Output in Excel:


By the way an advanced script to this could be outputting the errors to the DB… But that can be considered a version in some companies.



PowerShell Tutorial 1: Configuring the PowerShell Console

PowerShell Tutorial 2: PowerShell Commands – Cmdlet

PowerShell Tutorial 3: PowerShell Aliases

PowerShell Tutorial 4: Using Cmdlet Options

PowerShell Tutorial 5: Windows PowerShell Providers

PowerShell Tutorial 7: Accumulate, Recall, and Modify Data

PowerShell Tutorial 8: Conditional Logic (if, elseif, else, and switch)

PowerShell Tutorial 9: Getting Loopy

Wednesday, January 25, 2012

Silverlight Windows Authentication (the Prism way)

Note: this was done with Silverlight 5 and Prism 4

In the past month our team started a new project and after many discussions of how to build it right, decided to use the Prism framework (you an read more on Prism here). I was put in charge of providing a service (as in a Silverlight utility class) for Authentication and Authorization using Windows Authentication and Active Directory groups.

The way we handled that in our previous project was using the built in services in RIA services (the only use we had for RIA Services). But that implementation used:

  1. Code in the main Silverlight Application project (not in Class Library projects)
  2. Configuration in App.Xaml
  3. Configuration in web.config

So I tried for two days to create the code in a Silverlight Application project that is not the main project (not the one referenced in the ASPX page), with no success and many errors. I found many forum posts that claim it is possible but all the examples were either Forms Authentication or used the main Silverlight Application (like this one or this one). The main problem I found is the configuration that should be put in the App.Xaml:

  1. <Application.ApplicationLifetimeObjects>
  2.     <app:WebContext>
  3.         <app:WebContext.Authentication>
  4.             <appsvc:WindowsAuthentication/>
  5.         </app:WebContext.Authentication>
  6.     </app:WebContext>
  7. </Application.ApplicationLifetimeObjects>

The app preface is from the generated code that is generated in a Module Silverlight Application, but the App.Xaml is in the Main Silverlight Application and it just doesn’t work to use it outside of the project it was generated at. Adding App.xaml in the Module Silverlight Application won’t work either because Prism doesn’t call the App.Xaml of inner Modules (though having that Module run as it’s own main application does work).


In the end I decided to try to implement the RIA Authentication myself using WCF Services (me and my team leader have burned to much time on RIA by that point… and since we use it for just authentication it didn’t seem justified).

The WCF Services web site must be configured in IIS to use Windows Authentication. The code for the service is:

  1. [ServiceContract]
  2. public interface IAuthenticationService
  3. {
  4.     [OperationContract]
  5.     User GetUser();
  6. }
  1. [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  2. public class AuthenticationService : IAuthenticationService
  3. {
  4.     public User GetUser()
  5.     {
  6.         var result = new User { Name = OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name };
  7.         if (OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Groups != null)
  8.         {
  9.             result.Groups = new List<string>();
  10.             foreach (var userGroup in OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Groups)
  11.             {
  12.                 result.Groups.Add(userGroup.Translate(typeof(NTAccount)).Value);
  13.             }
  14.         }
  15.         return result;
  16.     }
  17. }

The user groups default values are in SID format so the code:

  1. userGroup.Translate(typeof(NTAccount)).Value

translate it to readable text.

User is defined as:

  1. [DataContract]
  2. public class User
  3. {
  4.     [DataMember]
  5.     public string Name { get; set; }
  7.     [DataMember]
  8.     public IList<string> Groups { get; set; }
  9. }

Web.Config code:

  1. <configuration>
  2.   <system.web>
  3.     <compilation debug="true" targetFramework="4.0" />
  4.     <authentication mode="Windows" />
  5.   </system.web>
  6.   <system.serviceModel>
  7.     <behaviors>
  8.       <serviceBehaviors>
  9.         <behavior name="AllServicesBehavior">
  10.           <serviceMetadata httpGetEnabled="true" />
  11.           <serviceDebug includeExceptionDetailInFaults="true" />
  12.           <dataContractSerializer maxItemsInObjectGraph="2147483647" />
  13.         </behavior>
  14.         <behavior name="">
  15.           <serviceMetadata httpGetEnabled="true" />
  16.           <serviceDebug includeExceptionDetailInFaults="false" />
  17.         </behavior>
  18.       </serviceBehaviors>
  19.     </behaviors>
  20.     <bindings>
  21.       <customBinding>
  22.         <binding name="customBinaryEncodedBinding">
  23.           <binaryMessageEncoding/>
  24.           <httpTransport authenticationScheme="Negotiate"/>
  25.         </binding>
  26.       </customBinding>
  27.     </bindings>
  28.     <services>
  29.       <service behaviorConfiguration="AllServicesBehavior" name="DllShepherd.AuthenticationService">
  30.         <endpoint address="" binding="customBinding" bindingConfiguration="customBinaryEncodedBinding" contract="DllShepherd.IAuthenticationService"/>
  31.       </service>
  32.     </services>
  33.   </system.serviceModel>
  34. </configuration>

The important part is:

  1. <httpTransport authenticationScheme="Negotiate"/>


  1. <authentication mode="Windows" />

that enables the authentication and binaryMessageEncoding for Silverlight.


In the Silverlight Services Class Library project (Services is part of the Prism terminology for client services, usually Singleton utility classes), add the service reference (I do this part usually in code) and consume it using usual Silverlight code:

  1. public string UserName { get; private set; }
  3. public event EventHandler UserLoaded;
  5. public void GetUser()
  6. {
  7.     Client.Begin("GetUser", GetUserCompleted, null, null);
  8. }
  10. private void GetUserCompleted(object sender, ObjectClient<DllShepherd.IAuthenticationService>.ClientEventArgs e)
  11. {
  12.     Dispatcher.BeginInvoke(() =>
  13.     {
  14.         var result = e.LoadResult<User>();
  15.         UserName = result.Name;
  16.         AuthorizationService.Roles = result.Groups;
  17.         if (UserLoaded != null)
  18.             UserLoaded(this, null);
  19.     });
  20. }

AuthorizationService will later use the Groups to check if the user is authorized to view Modules, Views or data.


In the Prism way the Modules now know only the interface for this Silverlight service (the interface is in the Infrastructure project which everyone knows), which look something like:

  1. public interface IAuthenticationService
  2. {
  3.     #region EVENTS
  5.     event EventHandler UserLoaded;
  7.     #endregion
  9.     #region METHODS
  11.     void GetUser();
  13.     #endregion
  15.     string UserName { get; }
  16. }

But the implementation is only known by the Application (not the Modules which just use IAuthenticationService with a Prism Import) and there is no special code or configuration needed in the Application.



Silverlight.Net Forum - Prism, RIA & Authentication (VS 2010)

Silverlight.Net Forum - PRISM 4 and RIA services

Prism for Silverlight/MEF in Easy Samples. Part 1 - Prism Modules (there are three parts)