DarioSantarelli.Blog(this);

<sharing mode=”On” users=”*” />

Archive for the ‘.NET’ Category

Silverlight Spy

Posted by dariosantarelli on May 9, 2008

Silverlight Spy provides detailed XAML inspection of any Silverlight application. It allows you to explore the UI element tree, monitor events, extract XAML, get and set object properties, view statistics and more. Nowadays it supports Silverlight 2.0 (Beta 1).
You can download it here.

Posted in Silverlight | Leave a Comment »

.NET 3.5 Enhancements Training Kit

Posted by dariosantarelli on April 16, 2008

I was looking for some resources in order to learning something more about the .NET 3.5 extensions… after a little search I’ve discovered that just few days ago Microsoft has published the .NET 3.5 Enhancements Training Kit:

The .NET Framework 3.5 Enhancements Training Kit includes presentations, hands-on labs, and demos. This content is designed to help you learn how to utilize the .NET 3.5 Enhancement features including: ASP.NET MVC, ASP.NET Dynamic Data, ASP.NET AJAX History, ASP.NET Silverlight controls, ADO.NET Data Services and ADO.NET Entity Framework.

What can I say… Happy download

Posted in .NET, AJAX, ASP.NET, Microsoft Technology, Web 2.0, Web Development | Leave a Comment »

FluidKit for WPF

Posted by dariosantarelli on March 17, 2008

On CodePlex you can find FluidKit, a WPF library containing a powerhouse of controls, frameworks, helpers, tools, etc. for productive WPF development. Here is the introductory blog post.
Available controls:

  • ImageButton
  • DragDropManager
  • GlassWindow
  • BalloonDecorator
  • ItemSkimmingPanel + SkimmingContextAdorner
  • PennerDoubleAnimation
  • ElementFlow ( Very  powerful ): allows you to display your items in different carousel like modes

Posted in .NET, Microsoft Technology, WPF | Leave a Comment »

Installing Enterprise Library 3.1 in VS2008

Posted by dariosantarelli on March 14, 2008

The patterns & practices Enterprise Library 3.1 is a library of application blocks published for Visual Studio 2005 and designed to assist developers with common enterprise development challenges. Application blocks are a type of guidance, provided as source code that can be used “as is,” extended, or modified by developers to use on enterprise development projects. This release of Enterprise Library includes application blocks for Caching, Cryptography, Data Access, Exception Handling, Logging, Policy Injection, Security and Validation.
In this post you can find how to to get the integrated tool to work in Visual Studio 2008. Simply you have to run a registry script that will change the keys where VS looks to load the integrated tool package. After you run the script, you will need to run devenv /setup from the Visual Studio 2008 command prompt. You can download the file from the EntLibContrib project on CodePlex.

P.S.: If you already have the Enterprise Library 3.0 installed, you must uninstall it before installing the Enterprise Library 3.1.

Posted in .NET, Microsoft Technology, Programming | Leave a Comment »

LINQ to Objects in .NET 2.0/3.0 projects

Posted by dariosantarelli on March 1, 2008

LINQ’s query operators are implemented in .NET Framework 3.5. And here lies a difficulty: you might be unsuccessful in demanding that all your customers install Framework 3.5 right away. So what does this mean if you want to code in C# 3.0 and write LINQ queries?
You can use LINQBridge, a reimplementation of all the standard query operators in Framework 3.5’s Enumerable class by Joseph Albahari.

  • LINQBridge is designed to work with the C# 3.0 compiler, as used by Visual Studio 2008.
  • LINQBridge comprises a “LINQ to Objects” API for running local queries. (It doesn’t include an implementation of LINQ to SQL, nor LINQ to XML).
  • LINQBridge also includes Framework 3.5’s generic Func and Action delegates, as well as ExtensionAttribute, allowing you to use C# 3.0’s extension methods in Framework 2.0. In fact
  • LINQBridge lets you use nearly all of the features in C# 3.0 with Framework 2.0—including extension methods, lambda functions and query comprehensions. The only feature it does not support is compiling lambdas to expression trees (i.e., Expression<TDelegate>).

Posted in .NET, C#, Microsoft Technology, Programming | Leave a Comment »

.NET Reference Source project

Posted by dariosantarelli on January 20, 2008

In his blog, Scott Guthrie announces the ability for .NET developers to download and browse the source code of the .NET Framework libraries, and to easily enable debugging support in them. Specifically, now we can browse and debug the source code for the following libraries:

  • .NET Base Class Libraries (including System, System.CodeDom, System.Collections, System.ComponentModel, System.Diagnostics, System.Drawing, System.Globalization, System.IO, System.Net, System.Reflection, System.Runtime, System.Security, System.Text, System.Threading, etc).
  • ASP.NET (System.Web, System.Web.Extensions)
  • Windows Forms (System.Windows.Forms)
  • Windows Presentation Foundation (System.Windows)
  • ADO.NET and XML (System.Data and System.Xml)

Moreover, in this great post, Shawn Burke shows us how to configure Visual Studio 2008 to Debug .NET Framework Source Code…. VERY INTERESTING!

Posted in .NET, Microsoft Technology | 1 Comment »

VS2008: Embedding UAC Manifest Options

Posted by dariosantarelli on November 21, 2007

A very useful feature included in VS2008 concerns the possibility of embedding a manifest resource which specifies UAC options in applications running on Windows Vista. First, you can create a manifest file by adding an “Application Manifest File” Item to your project (default name: app.manifest), then you can set it through the Application Tab in the Project Properties.
If you want to change the Windows User Account Control level in your manifest file, all you need is to set the value of the level attribute of the requestedExecutionLevel node with one of the following:

  • asInvoker (default): the application will run using the current Windows user provileges
  • requireAdministrator: the application requires an Administrator user
  • highestAvailable: highest privileges for the current user will be used

Posted in .NET, Microsoft Technology, Programming | 4 Comments »

Protecting data using ProtectedMemory

Posted by dariosantarelli on November 8, 2007

If you are looking for a smart way to encrypt/decrypt sensitive data in memory in order to make them unreadable even in malicious memory dumps, maybe you need to use the ProtectedMemory class (namespace System.Security.Cryptography). This class is a managed wrapper included in the DPAPI (Data Protection API) and it works in the same way as ProtectedData (a similar class indeed used to persist encrypted strings in file/database): it exposes two static methods, Protect and Unprotect,  which allow you to encrypt/decrypt strings in memory. The only requirement you have to consider in order to avoid a CryptographicException  is about using 16-bytes blocks for computing encrypted/decrypted data. For example, the following code shows how to protect/unprotect a sensitive string in memory during a process execution:

using System.Security.Cryptography;

string OriginalString = “xxxxxxxxxxxxxxxx”;
Console.WriteLine(“Before Protect: “ + OriginalString);
byte[] OriginalBytes = Encoding.UTF8.GetBytes(OriginalString);
ProtectedMemory.Protect(OriginalBytes, MemoryProtectionScope.CrossProcess);
UTF8Encoding enc = new UTF8Encoding();           
Console.WriteLine(“After Protect: “ + enc.GetString(OriginalBytes));
ProtectedMemory.Unprotect(OriginalBytes, MemoryProtectionScope.CrossProcess);
OriginalString = Encoding.UTF8.GetString(OriginalBytes);
Console.WriteLine(“After Unprotect: “ + OriginalString);

Here the output:
Before Protect: xxxxxxxxxxxxxxxx
After Protect: 7j??‼8y_??PQ<?¶-
After Unprotect: xxxxxxxxxxxxxxxx

Some further considerations:

  • The Protect()/Unprotect() method works directly on the original data, not on a copy. So, we don’t need to explicitly destroy our sensitive strings after the use.
  • Many people use SecureString, a more intuitive class using ProtectedMemory to automatically encrypt strings. A SecureString can be modified till the MakeReadOnly() method call and can be programmatically disposed. Finally, its MemoryProtectionScope is SameProcess: a SecureString can’t be used in CrossProcess and SameLogon scenarios, in which there’re multiple applications running in different processes (CrossProcess) and allowing data encryption/decryption to the same Windows user (in particular cases, consider the impersonation technique).
  • I’ve noticed some strange behaviours by randomly analyzing the memory dump file after invoking the Protect() method on a string: sometimes the text I’d like to protect appears as clear text…mmmm…. Does Windows operate a swap on file system before data encryption? If this is a possibility, are my efforts unuseful?

Posted in .NET, C#, Programming | 1 Comment »

Some more visualizers for LINQ

Posted by dariosantarelli on October 19, 2007

Today I’ve installed LINQ samples for Visual Studio 2008 Beta 2 and immediately noticed two folders containing two visualizers named ExpressionTreeVisualizer and SqlServerQueryVisualizer. In this post you can find an explanation about using them in debugging LINQ code. Just a question: why don’t they have been included in the Orcas default installation? 

Posted in .NET, Microsoft Technology | Leave a Comment »

Visual Studio .NET 2003 on Windows Vista Issue List

Posted by dariosantarelli on October 15, 2007

While Visual Studio 2003 is not supported on Windows Vista if you choose to run it then, Microsoft advise you to follow these issues:
http://msdn2.microsoft.com/en-us/vstudio/bb188244.aspx

Posted in .NET, Microsoft Technology | 1 Comment »

WCF: Service Hosting in WAS

Posted by dariosantarelli on September 29, 2007

A WCF service is a program and  can run as a stand-alone executable (like Console and Windows Forms applications) . This scenario is known as a self-hosted service.  Moreover, WCF services can also be hosted  in external agents, such as IIS or Windows Activation Service (WAS ),  implemented as a Windows service in Windows Vista.
Alternatively, a service can also be run automatically as a Windows service.  Finally, COM+ components can also be hosted as WCF services.
For more info about WCF architecture go to this link : http://msdn2.microsoft.com/en-us/library/ms733128.aspx
Above all, the WAS hosting is the real new feature because it provides a concept that extends the ASP.NET HTTP hosting concept (ASMX Web Services).  As a standalone Windows component, WAS  it’s completely separated from the IIS hosting environment and provides a protocol-agnostic activation mechanism, so you aren’t limited only to HTTP.
WAS allows you to choose the most appropriate protocol for your needs:

  • for the HTTP protocol, data transfer relies on the ASP.NET HTTP
  • for non-HTTP protocols such as TCP and Named Pipes, WAS leverages the extensibility points of ASP.NET for transferring data. 

 These capabilities are implemented in the form of protocol handlers which manage communication between the worker process and the Windows service . There are two types of protocol handlers loaded when the WAS activates a worker process instance: Process Protocol Handler (PPH) and App Domain Protocol Handler (ADPH).
If you are interested in practice hosting WCF services, you can find a great tutorial in this article: Hosting WCF Services in Windows Activation Service.

Posted in WCF | Tagged: , , | 1 Comment »

Sql Server 2005 Management: How to programmatically find the original logical DataBase name from a backup file

Posted by dariosantarelli on September 14, 2007

To retrieve the original logical DB Name from a Backup file (es. .bak), you just have to call the RestoreFileList(…) method from a Restore class instance, naturally after adding a file Device. This method returns a DataTable containing a row for each added device. So, each datarow contains some metadata, including the original logical DB name, which can be found on the first column:

using System.Data;
using Microsoft.SqlServer.Management.Smo;

Server SQLServerInstance = new Server(“MyServer\\MyInstance”);
Restore restore = new Restore();                                               
restore.Devices.AddDevice(“BackupFile.bak”, DeviceType.File);
DataTable RestoreInfoDT = restore.ReadFileList(SQLServerInstance);
DataRow drow = RestoreInfoDT.Rows[0];               
restore.Database = RestoreInfoDT.Rows[0][0].ToString();  // Retrieves the original logical DB name   
restore.SqlRestore(SQLServerInstance);

Posted in .NET, C#, Microsoft Technology | 1 Comment »

C# Language Specifications 3.0

Posted by dariosantarelli on September 10, 2007

I’d like to advice this page (MSDN) where you can find the unified C# Language Specification which covers all the features of the C# language through version 3.0 (just 500 pages!!!)… In this document there are a lot of interesting and not so broadly known features (e.g. atomic operations on integral types like ulong). I think just a quick look will be fine in order to discover some curiosities ;) .

P.S.: To people thinking C# as a not standard language, please read the Introduction:

… C# is standardized by ECMA International as the ECMA-334 standard and by ISO/IEC as the ISO/IEC 23270 standard. Microsoft’s C# compiler for the .NET Framework is a conforming implementation of both of these standards…

Posted in .NET, C#, Microsoft Technology | 1 Comment »

LINQPad (Beta)

Posted by dariosantarelli on September 5, 2007

Oh my God!!!!
Now you can download LINQPad (Beta), a very useful tool for experimenting LINQ technology!!!!
It supports LINQ to objects, LINQ to SQL and LINQ to XML.
GREAT!!!

Posted in .NET, Microsoft Technology | Leave a Comment »

Getting a DataRow from a DataGridViewRow

Posted by dariosantarelli on September 5, 2007

If you want to retrieve a DataRow from a DataGridViewRow (for example starting from a DataGridViewSelectedRowCollection), you simply need to get the Row property of the DataRowView obtained by converting the DataBoundItem object of the DataGridViewRow :

DataGridViewSelectedRowCollection rows = MyDataGridView.SelectedRows;               
foreach (DataGridViewRow row in rows)
{
 
DataRow myRow = (row.DataBoundItem as DataRowView).Row;
 
// do something with your DataRow…
}

Hope it helps ;)

Posted in .NET, C#, Programming | 12 Comments »