2008.05.12

New .NET Versions and the CLR

This weekend I had the pleasure of attending and speaking at the Tulsa School of Dev.  While there, I got to catch up with my long-time friend, Brett Schuchert.  Brett is quite the programming language buff, an knows the C++, Java, and C# inner workings very well.  We got into a discussion about virtual tables being constructed at compile vs. load time and he asked if I had heard of any advances in the newer versions of .NET.  But as I recalled (and have now verified), .NET v3.0 and v3.5 both run on the same old .NET v2.0 CLR.

2008.05.01

Free eBooks for LINQ, ASP.NET AJAX, and Silverlight

I'm here at Microsoft listening to Jef talk about LINQ internals at the Dallas C# SIG meeting. Since I love to multitask, I wanted to take the opportunity to post this link to free eBooks for LINQ, ASP.NET AJAX, and Silverlight. I've only started reading the LINQ book, but really like it so far.

eBooks for LINQ, AJAX, Silverlight

Fair warning: you need to have an MCP number to register and download these eBooks. But of course, if you want to become a Microsoft Certified Professional, contact Improving for training and "second chance" exam retake coupons.

2008.04.21

This is a post for my class

on c# agile dev using visual studio.net 2008. Nothing to see here. Move along.

2008.04.04

SvnBridge

Last night, I presented at the Dallas C# SIG on behavior-driven development.  During the conversation, SvnBridge came up, and I misspoke by saying that SvnBridge was a server-side thing. It is actually a client side proxy. Your SVN client points to the bridge, and the bridge points to TFS.

 

I had the good fortune to speak with Ayende recently when he was state-side and working with MS on SvnBridge, and though we talked about the bridge, I misunderstood this. D'oh.


I feel compelled to state that Caleb was right.

SvnBridge - Use TortoiseSVN with Team Foundation Server - Home

2008.04.02

Process Explorer on Vista and Vista x64

I've used Process Explorer from SysInternals for a long time now.  But, on my Vista x64 machine at home I had problems after select the "Replace Task Manager" option.  Task Manager (or ProcExplorer) would no longer start from context menu of the Start bar. 

After installing Vista x64 on my Dell Inspiron 1720 laptop (runs beautifully, BTW), I ran into the exact same problem.  Tonight I decided to finally hunt it down.  This post shows how to edit the registry to run Process Explorer in Vista

However, unlike the instructions within, I just added my ProcExp path (unzipped to "C:\Program Files\SysInternals\Process Explorer\procexp64.exe") directly into the registry setting (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\taskmgr.exe, Debugger) without the SUDO utility.  Apparently without UAC turned on, you don't need to elevate the privileges -- but ProcExp still doesn't know how to update the registry.  Surgery complete and patient up and walking around.

2008.03.04

I'm a Nerd King

<confused>I didn't think I was that nerdy, but then maybe that's part of being a nerd.</confused> 

If you know how to write XML, you're probably pretty nerdy.

 

NerdTests.com says I'm a Nerd King.  What are you?  Click here!

2008.02.18

So, all I really wanted was an IoC for CF

And so I asked the altdotnet group. And so Glenn Block mentioned ObjectBuilder had been ported for the Mobile Client Software Factory. So, I downloaded the The MCSF. And I tried to install it. And it didn't. Requires Windows Mobile 5.0 SDK. So I downloaded it. Requires validation. Genuine Microsoft Software. Click click click. MSCF... "The installation requires the Guidance Automation Extensions, June 2006 CTP or later, which is not present." So I download GAX. oOH, Feb 2008 Update for VS 2008. Installed. Just as it is completing - it dies because there are open VS instances. Argh. So I kill the open instances. Re-download since I ran instead of saved the first time, run again. Done. Ahhhh. now for the MCSF... click click click... "The installation requires the Guidance Automation Extensions, June 2006 CTP or later, which is not present."

Aaaaaaaaannnnnnnd the short attention span kicks in.

Ah... back to a roll-your-own IoC strategy. (argh)

2008.02.04

WCF Extensibility

As I promised in my previous post on Advanced WCF, I'm going to be posting more about WCF extensibility.  Before I get into the real content though, I wanted to drop a note that I picked up the book WCF Unleashed because it promised to have a lot more on WCF Extensibility than other books on WCF.  While it is much better at listing out the concepts and showing some disconnected examples than other books, it doesn't really explain how or why to use some things like the Instance Context Provider.

For those of you in Dallas, you can get more on this topic in person at the Dallas C# SIG meeting this Thursday 2008.02.07 as presented by Jef Newson

2008.01.27

One other way to make files available at runtime

Todd mentions ways to make files available to tests or at runtime in VS. If you happen to be using MS Test, you have one more option that I don't believe was mentioned, the DeploymentItemAttribute. From the MSDN page:

This attribute can be specified on a test class. There can be multiple instances of this attribute to specify more than one item. The item path can be absolute or relative. Relative paths are relative to the RelativePathRoot setting found in the .testrunconfig file.

The following examples demonstrate different usage of the DeploymentItemAttribute:

  • [DeploymentItem("file1.xml")]    Deploys an item named file1.xml located at the RelativeRootPath. The file is deployed to the deployment root directory.

  • [DeploymentItem("file2.xml", "DataFiles")]    Deploys an item named file2.xml located at the RelativeRootPath. The file is deployed to the DataFiles subdirectory of the deployment root directory.

  • [DeploymentItem("C:\\MyDataFiles\\")]    Deploys all items and directories found within the MyDataFiles directory. This does not create the MyDataFiles directory underneath the deployment directory. All files and directories within MyDataFiles will be deployed to the deployment root directory. To copy the entire MyDataFiles directory structure, you must specify MyDataFiles as an output directory.

Of course, the truth of the matter is that I would rather use MBUnit :)

2008.01.23

Making .NET project files available at run-time

One of my clients asked me this morning how to get files into the build output directory so they are available for tests or as resources during run-time.  There are a few answers to this question.

 

1.  You could add a post-build even in your project file to copy the specific file(s) to the output directory.  There is even a variable to help specify the OutDir.  This is the bruit-force method and I don't recommend it.

image

 

2. An easier way is to right-click on the specific file and select Properties from the context menu.  Then, in the Copy to Output Directory option, select Copy if newer.  This is the built in method that provides what my client thought he wanted.

image

 

3. Finally, in ASP.NET it's possible to embed files into an assembly and reference them during run-time.  This is what the client really wanted because it's more secure and easier to ensure all resources are available as an assembly is copied around to various execution environments.  In short, you have to mark the file as an embedded resource, add a WebResource attribute to your code, and then use a special function to open the file.  Here's a post explaining the use of the WebResourceAttribute in .NET and another post giving a little better code example of WebResourceAttribute.

image

Advanced WCF Development

I've recently had the opportunity to join a client's team building an ESB solution using the Windows Communication Foundation (WCF) with requirements for security, logging, load distribution across a managed group of hosts, and more.  As you can see from my list of books here on my site, I spent some free time over the holidays reading up on WCF.  It seems that everything published about WCF so far just covers how to write and host services.

The best organized book I found that presents all the key concepts and somewhat covers extensibility through behaviors is Pro WCF by Chris Peiris and Dennis Mulder.  I've also reviewed Programming WCF Services by Juval Lowy, which has a somewhat shotgun approach development with WCF, great for coding, but doesn't really cover WCF extensibility. 

The best references I've found on extending WCF are Mark Gabarra's blog and this great, detailed MSDN article on WCF extensions by Aaron Skonnard, which gives full examples of extending WCF in a variety of ways, including behaviors.  I'm currently prototyping a WCF service with extensions at a variety of points and will post more as I make progress.

2007.12.17

LINQPad - Dynamically Query SQL Server Databases in LINQ

David Hayden blogged about LinqPad a good while back (Sept). I've been under a rock, so I haven't seen it until now. I downloaded, I used it, and I love it. Very cool. It's free, and well worth the download if you're interested in learning linq, extension methods, etc.

2007.12.11

Data Contracts are Opt-In.

From MSDN:

New complex types that you create must have a data contract defined for them in order to be serializable. This is normally done by applying the DataContractAttribute attribute to the type. This attribute can be applied to classes, structures, and enumerations. The DataMemberAttribute attribute must then be applied to each member of the data contract type to indicate that it is a data member; that is, it should be serialized.

Using Data Contracts

Our old friend, XmlSerializer, uses an opt-out strategy for defining members that are not  to be serialized. WCF's DataContractSerializer, on the other hand, offers an Opt-In approach. What is basically means is that you have to be explicit about exactly what is included in the contract. Properties are no longer "guilty by association," so to speak.

For example:

// Serializable via the DataContractSerializer
[DataContract]
public class Person
{

    [DataMember] private string WorstFear;
    [DataMember] public string Name { get; set; }
    [DataMember] public int Age { get; set; }
}

// Not serializable via DataContractSerializer
public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
}

 

When it comes to Facebook Beacon, I love Opt-In. When it comes to WCF Data Contract, not so much. Now I have to decide "Do I want this stuff to *be* my domain model?" I *really* don't want to duplicate the model, once for the data contract, and once for the problem domain. But in most cases, I feel compelled down the path of DTOs. Most of the time, I am not a fan of DTOs. Linq's extension methods *do* make DTOs a bit more tolerable.

return People.Select(person => new PersonDTO(person));

Now.

My typical response to someone such as myself would be "Look. Just mark up your domain as your data contract. I mean, it's just a few attributes, right?"

Of course, I would reply with, "Yeah, and it's just a few attributes to mark up for object-relational mapping. Geez. When will it end?!?!"

 

(mmmm, cheesecake).

 

And then I would have to take a break from myself for a while. Eat better. Maybe start working out more. Take up a foreign language. Get a hip new haircut. Do some volunteer work. Travel like we always said we would. Re-center.

So.

Now that I have gotten that off my chest, I will tell you that there is at least one thing that I really love about data contracts, which is that you may expose private fields as Data Members for the purpose of serialization. Of course, that opens some surface area for confidentiality violations, but if the hackers are already deep enough that they can use DataContractSerializer, my guess is that that is the least of your worries.

2007.12.10

ASP.NET 3.5 Extensions Preview

I suppose now I have a good reason to upgrade. I am really interested in seeing impressions from the Castle Projects.

 

via Chris. (thx)

2007.11.14

Using WCF with InfoPath and MOSS 2007

On my current project at Improving we are building custom workflows in Windows Workflow Foundation (WF) to be hosted in MOSS 2007.  Each workflow is kicked off by submitting an InfoPath form, hosted in Form Server.  Some of our application data manipulated by the workflow must be accessible to the forms for drop-down selections and the like.  So, we chose to use Windows Communication Foundation (WCF) as the service mechanism to provide information and services to the workflow and forms.  Here are some issues and solutions I came across while making InfoPath forms work with WCF and developing in Visual Studio 2008.

  1. To start off, pick the proper WCF project type.  In VS 2008 you have several different WCF projects to choose from.  I mistakenly chose the WCF Service Library under the WCF project template group instead of the WCF Service Application under the Web template group.  One creates a class library referencing all the WCF assemblies for service development while the other creates a website with a .SVC file, contract files, and service code.  In the end I used a hybrid model with the .SVC file hosted by a website but bound to the service class in a separate assembly.  So I actually used them both!
  2. Next, IIS didn't recognize my .SVC file, so I used this article on registering .SVC files with IIS.  Once the .SVC file is properly registered, you can browse to the service with a browser much like you can to ASMX services.
  3. With my service built and accessible through IIS, I was ready to configure data sources in InfoPath to submit and retrieve information.  While creating a datasource to populate a list, I realized that InfoPath can't see all web services equally.  WCF had created a WsHttpBinding by default, and it wasn't working.  This article helped me change the bindings to BasicHttpBinding for InfoPath consumption. 
  4. At last, with form that bound properly to WCF services and worked completely in preview mode, I was ready to publish.  Publishing wasn't a problem, but I immediately hit another two snags: (1) InfoPath doesn't like webservices accessed via "localhost", not even for testing; and (2) hosting the service on a port other than 80 is considered another site and causes a "cross-domain" connection error from InfoPath and FormServer.  This is a well-known problem for ASMX services, too, but thought I'd provide a link here to InfoPath blog post on Managing Trusted Connections for InfoPath.  I don't like services hosted on port 80 because they become accessible to end-users who hack the URL.  Putting services on another port makes them easier to secure.

C# 3.0 Video

I recently came across this cool 50 minute Introduction to C# 3 video on the new features in C# 3.0 by Tim Rayburn, a Dallas BizTalk MVP.  I hear that it's the same as he presented at the ALT.NET conference in Austin last month.  I definitely learned a couple of things from it and some features I've seen presented before became more clear.  Thanks Tim!

2007.10.30

Visual Studio 2005 or 2008? What's more risk? - <ChristophDotNet

One of my customers is still on Visual Studio 2003 and they are wondering whether to upgrade to VS 2005 or to VS 2008.

Visual Studio 2005 or 2008? What's more risk? -

In response to one of his customer's needs, my friend Christoph over at Microsoft posted a decent decision framework for VS 2005 vs VS 2008. We have three customers where we are using/have used VS 2008, and it has been very stable if you exclude the WPF designer. Most of the instability risk is mitigated assuming you build often, since by default, VS saves everything before build, so we have rarely found the glitch to be problem. Visual Studio starts right back up, and then we're off and going again. That's not to say, of course, that we don't want it fixed. We do. We really, really do. ;) It is to say that I think VS 2008 is largely stable, and because it makes it trivial to target down-level .NET versions like 2.0 and 3.0, that it is worth either a) just using the beta for free, or b) buying Software Assurance for the current version that you likely have. If you happen to be in the south central region, I know several people that would be happy to help you with the latter :)

 

< a>

XmlnsDefinitionAttribute in Silverlight?

If you build a custom or user control in WPF, you can reference it in XAML using a custom xml namespace of

xmlns:your-prefix=

"clr-namespace:Your.Clr.Namespace;assembly=The.Assembly.In.Which.It.Lives.Sans.The.Dll.Extension"

or you can add an assembly attribute

[assembly: XmlnsDefinition("http://yourdomain.com/some/xml/namespace", "Your.Clr.Namespace")]

after which you may simply use xmlns:your-prefix="http://yourdomain.com/some/xml/namespace"

That's pretty cool. Unfortunately for Silverlight, XmlnsDefinition is in that part of the SDK that Silverlight isn't privy to. I would love to be able to experiment with applying XmlnsDefnition to some custom silverlight controls so that I could natively render things like SVG, HTML, and so on using Silverlight. Looking a little closer, there are actually two definitions of XmlnsDefinition, one for workflow:

Name: System.Workflow.ComponentModel.Serialization.XmlnsDefinitionAttribute
Assembly: System.Workflow.ComponentModel, Version=3.0.0.0

and one for WPF:

Name: System.Windows.Markup.XmlnsDefinitionAttribute
Assembly: WindowsBase, Version=3.0.0.0

(thank you reflector).

Architecturally, it seems apparent that there should be a core System.Xaml, and that the XmlnsDefinition should live there. Things are never that simple in an organization as big as MSFT or an SDK as big as .NET, but it sure would be nice.

2007.10.23

Barcode fonts for use with WPF

Does anyone out there know of any good barcode fonts (Code 128C, UPC-A) that you've used natively in WPF?

Thanks in advance.

2007.10.18

Vista Woes

I recently picked up a beautiful new MacBook Pro (17in hi-res mat screen, dual core 2.4GHz, 4G Ram, etc). Mmmm mmm. I love it. It is literally twice the computer of my previous Inspiron 9300 in half the form factor with basically the same screen real estate.

I boot camped it with Mac OSX and Vista. Vista runs *quite nicely*, for what it is worth. On the native hardware. I don't get the Aero glass, but I don't mind that too much. Visual Studio, Office apps, they all open instantaneously.

I'm using VMWare Fusion for virtualization, and I discovered the hard way that I needed to read the release notes more closely. http://www.vmware.com/support/fusion/doc/releasenotes_fusion.html#issues

Basically, Vista sees different hardware in Fusion than it sees running natively, and so it requires reactivation. Net? Vista will live only in a VM on my machine. :(