Fixing .NET Framework 4 Client Profile Dependency Issues

Microsoft .NETIf you’ve worked with .NET 4, you might have run into this before. You’re casually typing and clicking along and then you go to add a reference to your project; but suddenly your application won’t build any more. The error complains about your targeted framework and a Microsoft library dependency. This library is included in .NET, but it won’t add to my project! What gives?

The referenced assembly "StructureMap" could not be resolved because it has a dependency on
"System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the
currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references
to assemblies not in the targeted framework or consider retargeting your project.

The Problem

If you take a closer look at the error, you’ll notice the targeted framework includes the text Profile=Client.

The .NET Framework 4 Client Profile is a subset of the .NET Framework 4 that is optimized for client applications; it restricts the set of referenced assemblies to only those that are interesting to a client application. For example, it won’t make System.Web available by default because it is not typically valuable to client apps.

So if you started building a Forms app (or WCF or WPF), Visual Studio might have defaulted you to target the .NET Framework 4 Client Profile instead of just .NET Framework 4. And now, it’s complaining because you want to add libraries that a client application doesn’t typically have any use for.

The Solution

Right-click the project that needs the reference added, click properties, and update the project to target .NET Framework 4 instead of the Client Profile.

Visual Studio Project Properties - .NET Framework 4

Now get back to work!

How To Fix DataGridView Rows Showing Up Without Data

Microsoft .NETThe DataGridView is incredibly helpful for binding data sources to a grid, but sometimes working with it is a bit tricky. If you use the DataGridView control sparingly (or you’re just plain forgetful), you might run into an issue where you can see rows in the grid, but all the cells are empty!

DataGridView Empty Rows

The Problem

Not to worry! If you’re seeing the correct number of rows, you probably just have some visibility problems with the class being used.

In my case, I was trying to bind a list of proxies (List) like this:

private void BindProxyGrid(IList proxies)
{
    var proxiesBindingList = new BindingList(proxies);
    dgvProxies.DataSource = proxiesBindingList;
}

And my proxy class looked something like this:

public class Proxy
{
    public string Ip;
    public int Port;
}

The Solution

So why didn’t it work? Because the DataGridView requires properties and I was using public fields. Updating the class to use properties fixed the problem!

public class Proxy
{
    public string Ip { get; set; }
    public int Port { get; set; }
}

It works!

DataGridView Filled Rows

The Lesson Learned

If you’re using a BindingList with your DataGridView, you may need to adjust the visibility for any class members you want to display in the grid; for example, the DataGridView can’t access public fields or properties marked internal.

Happy coding!

PowerShell Object Tutorial

Windows PowershellCreating objects in PowerShell is… strange, to put it lightly–down right awful if you want to be realistic. But even if the syntax is terrible, objects are still nice to use. Here’s a quick primer on how to create and use an object in PowerShell.

Creating a New Object

First let’s create an object using New-Object.

PS > $myObj = New-Object Object

Continue reading

How to Fix “Could not connect to the feed specified” with NuGet and TeamCity

When using NuGet 1.7 with TeamCity 7, I was receiving an error in the NuGet GUI when trying to connect to our NuGet feed. The error in Visual Studio looked like this:

Could not connect to the feed specified at '$the-server/app/nuget/v1/FeedService.svc'. Please verify the package
source (located in the Package Manager Settings) is valid and ensure your network connectivity.

The solution

This is a confirmed bug in NuGet 1.7, as seen in both this NuGet bug report (2066) and this TeamCity bug report (21011). To fix the problem you need to download a newer version of NuGet that contains the bug fix.

NuGet 1.8

As of this blog post NuGet 1.8 isn’t released, but it should be released soon; try updating your plugin to the latest stable version to see if your problem is resolved.

Update: NuGet 1.8 has been released! Upgrade using the Visual Studio Extension Manager or download it here!

Nightly builds

If the latest stable build doesn’t resolve your issue, you can download a nightly build from NuGet’s CI server.
1. Go to NuGet’s CI server
2. Click the link at the bottom to log in as a guest
3. Under the NuGet section you’ll see a couple of options (currently 1.8 and Default)
4. Mouse over the Artifacts link for whichever build you choose (I chose to download a 1.8 build), click VisualStudioAddIn and then NuGet.Tools.vsix
5. Your download should start; let it finish
6. Probably best to close any open Visual Studio instances
7. Run the vsix installer by double-clicking it

Your new NuGet extension should now be installed and your TeamCity feed URL should now work!

Enjoy NuGetting!

How to Fix Errors with the PowerShell WebAdministration Module

Windows PowershellThe PowerShell WebAdministration module can be finicky. If you’re seeing COMException error messages, here are a few things you could try.

WebAdministration Errors

If you import the module using the 32-bit version of PowerShell, you might see the following.

PS > Import-Module WebAdministration
PS > Get-Website
Get-Website : Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed
  due to the following error: 80040154.
At line:1 char:12
+ Get-Website < <<<
    + CategoryInfo          : NotSpecified: (:) [Get-Website], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.GetWebsite
   Command

If you import the module using the 64-bit version of PowerShell, you might see this error.

PS > Import-Module WebAdministration
PS > Get-Website
format-default : Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
    + CategoryInfo          : NotSpecified: (:) [format-default], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.FormatDefaultCommand

Continue reading

Examining and Recursing Objects in PowerShell

Windows PowershellI’m still somewhat new to PowerShell and all the time I find myself wanting to examine objects to see what properties and methods they have available. The documentation on MSDN and around the web is pretty good, but there are still plenty of situations where it’s just easier or better to ask PowerShell to help you out instead. For instance, when you’re using a third-party module that’s sparsely documented you might want to just examine its objects. Or maybe you just don’t feel like going to Google. Either way, here’s a bunch of ways you can get a better look at an object in PowerShell.

Continue reading

How to Install the Service Trace Viewer Tool (SvcTraceViewer.exe) to View *.svclog Files

Microsoft .NETI work with WCF services day to day, so sometimes I need to check the service logs to debug an issue or provide a stack trace for a bug report. To view *.svclog files, you need to install the Service Trace Viewer Tool from Microsoft.

Installing the Service Trace Viewer Tool

1) Go to the Windows SDK page and click Install Now
2) On the next page click Download and then run the web installer (winsdk_web.exe)
3) The default installation will install a lot of development tools, including the Service Trace Viewer Tool. But if you’re a minimalist and you’re just looking for the Service Trace Viewer Tool, just install the .NET Development Tools.

Install Service Trace Viewer

My machine required those additional reference assemblies, but your mileage may vary depending on what you’ve already installed.

Good luck debugging!

How to Fix “IsCleanMSDeployPackageNeeded” task failed unexpectedly

Microsoft .NETWhen deploying .NET projects, it’s handy to package them up using MSBuild. Recently I ran into an issue where my deployment scripts were working locally, but not on the build server (TeamCity). The error I was receiving looked like this:

C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018: The
        "IsCleanMSDeployPackageNeeded" task failed unexpectedly.

The solution

It was clear to me that something was awry on the build server, but I wasn’t sure what that might be. After looking into it, I realized that packaging your .NET projects like this utilizes Microsoft’s Web Deploy library, which must be installed on the machine.

Click here to visit Microsoft’s official Web Deploy page and download the package.

This must have already been installed on my development machine because I have IIS running; since the build server doesn’t have IIS installed, it needed the package to be installed separately.

Happy coding!

PowerShell for Programmers: Just the Basics

Windows PowershellI recently added PowerShell to my repertoire and noticed it has quite a few interesting quirks. The syntax is a bit odd as well, but overall it’s a pretty handy language to know and it definitely has a place in any developer’s toolkit.

Understanding the ins and outs of PowerShell did require quite a bit of Googling and practice, so I thought it might be nice to document some of what I found and put together a PowerShell for Programmers primer.

Continue reading

How to List Sysadmins in Microsoft SQL Server

Microsoft SQL Server

Sometimes I need to know who has system administrator privileges in Microsoft SQL Server. Here’s a SQL snippet to list the sysadmins.

Listing Sysadmins in MSSQL

SELECT [name] FROM sys.syslogins
WHERE sysadmin=1 AND (isntuser=1 OR isntgroup=1);

Output

You should see something similar to this in response (depending on your version of Windows, SQL Server, and any changes you have made):

[name]
NT AUTHORITY\SYSTEM
NT SERVICE\MSSQL$SQLEXPRESS
NT AUTHORITY\NETWORK SERVICE

Have fun!