January 17, 2008
.NET Framework Library Source Code Available
An interesting move by Microsoft, the .NET Framework Library has been made open source. Here are the libraries available:
* .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)
http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-source-code-now-available.aspx
Posted by 0xFF3300 at 08:00 AM | Comments (0)
January 11, 2005
HTTP.sys and HTTP Server Sample Application
It's interesting how unbeleivably vague the HTTP.sys (HTTP API) documentation is. There is a single sample application with no documentation other than some very minimal comments. Sorry folks, but I can't wait until .NET 2.0 finally comes out to utilize this new kernel mode driver, but I can find hardly any info on it even to use it in C++ application. I'm also sick of all the Microsft folks who have been tauting and using the new .NET 2.0 Beta as if it is already released. I know .NET 2.0 is nifty, I'll be the first one to use it, but until it comes out officially it's off limits for work projects.
Posted by 0xFF3300 at 02:37 PM | Comments (0) | TrackBack
January 10, 2005
Using Nunit and Cassini to Test a Server
This is a truly great article on scott hanselman's site: NUnit Unit Testing of ASP.NET Pages, Base Classes, Controls and other widgetry using Cassini. Very nice idea.
:Link:
Posted by 0xFF3300 at 02:55 PM | Comments (0) | TrackBack
January 06, 2005
Microsoft Windows AntiSpyware (Beta) Availaible
"Windows AntiSpyware (Beta) is a security technology that helps protect Windows users from spyware and other potentially unwanted software. Known spyware on your PC can be detected and removed. This helps reduce negative effects caused by spyware including slow PC performance, annoying pop-up ads, unwanted changes to Internet settings, and unauthorized use of your private information. Continuous protection improves Internet browsing safety by guarding over 50 ways spyware can enter your PC."
The worldwide SpyNet™ community plays a key role in determining which suspicious programs are classified as spyware. Microsoft researchers quickly develop methods to counteract these threats, which are automatically downloaded to your PC, so you stay up-to-date.
Posted by 0xFF3300 at 09:19 AM | Comments (0) | TrackBack
January 03, 2005
.NET 2.0 Provides Interface to HTTP.sys
System.Net contains several new classes for interfacing with http.sys. HttpListener is the focal point of these classes. Using it, you can create a simple Web server (or listener) that responds to incoming HTTP requests. The listener remains active for the lifetime of the HttpListener object, although you can tell it to start and stop listening on command.
Only one HttpListener can be listening for a specific URI prefix. You'll get a Win32Exception exception if you attempt to add a duplicate. When you specify a port, you can replace the host name with "*" to indicate that this listener should handle all URIs with this port unless they're matched by another HttpListener.
Posted by 0xFF3300 at 03:17 PM | Comments (0) | TrackBack
December 20, 2004
Microsoft Anti-Spyware Preview
SuperSite details a preview of Microsofts new anti-spyware software.
"On December 17, 2004, Microsoft announced the acquisition of an anti-spyware company, Giant Software Company, surprising many in the industry. The acquisition is notable for two reasons. First, Microsoft had already revealed its intention to get into the anti-spyware market. Second, the company it purchased, Giant Software Company, was largely an unknown in the industry. Largely, that is, except for me. In a rare moment of luck, I'd actually been a fan, customer, and advocate of Giant AntiSpyware, as their anti-spyware solution is logically named, for several months. In fact, I've found it to be far more effective than the industry darlings, Ad-aware and Spybot Search & Destroy. And I've been recommending it to friends and family ever since."
Posted by 0xFF3300 at 11:42 AM | Comments (0) | TrackBack
December 11, 2004
.NET XP Themes Framework
Lately I have been doing a bit of .NET UI development, I've been honing my skills on XP Themes. I found this article by Matt to be highly useful. Part of his framework pulls the images from the ShellStyle.dll, and you can also load pluggable themes such as panther.dll (my favorite).
Windows XP style Explorer Bars/Task Bars/Web Views - call them what you will - are all the rage at the moment. There are many great free Explorer Bar controls available on the net such as Derek Lakin's Collapsible Panel Bar, Darren May's Collapsing Group Control, and Tom Guinther's Full-featured XP Style Collapsible Panel. Most of them don't support Windows XP themes, or if they do, they "fake" it by drawing the gradient/arrows themselves, or by including the necessary images in the assembly.
Posted by 0xFF3300 at 10:30 AM | Comments (0) | TrackBack
November 24, 2004
The SQL Server Timestamp Type
Ahhh. The dreaded TIMESTAMP datatype. Unfortunately you really can't use TIMESTAMP for any type of comparison. Or really for much of anything. To quote from SQL Server Books Online:
"The SQL Server timestamp data type has nothing to do with times or dates. SQL Server timestamps are binary numbers that indicate the relative sequence in which data modifications took place in a database. The timestamp data type was originally implemented to support the SQL Server recovery algorithms."
It further states Never use timestamp columns in keys, especially primary keys, because the timestamp value changes every time the row is modified.
I'd suggest using a DATETIME or SMALLDATETIME column in this case. DATETIME columns can store dates from January 1st, 1753 through December 31st, 9999 (there's that Y10K problem) and are accurate to roughly 3 milliseconds. They use 8 bytes of storage. SMALLDATETIME columns can store dates from January 1st, 1900 through June 6th, 2079 and are accurate to the minute. SMALLDATETIME columns only use 4 bytes of storage.
You can insert values into DATETIME columns (or SMALLDATETIME) columns by enclosing them in quotes.
INSERT Table1 (DateTimeColumn)
VALUES ('6/3/2021')
This will insert the date part with the time set to midnight (12:00:00 AM). You can insert the current system date and time using the GETDATE() function:
INSERT Table1 (DateTimeColumn)
VALUES ( GETDATE() )
Your SELECT statement from above might look something like this:
SELECT * FROM links WHERE gdate = '2000-11-05'
This will run fine if you are putting dates in with no times. If you are adding times and want all the records for a particular day you can do something like this:
SELECT * FROM links WHERE LEFT( CONVERT(varchar, gdate, 120), 10) = '2000-11-05'
Using the CONVERT function makes SQL Server very picky about formats though (since that's what CONVERT does).
Posted by 0xFF3300 at 09:46 AM | Comments (0) | TrackBack
November 22, 2004
Google Makes Deskbar API Public
This seems to be good news direct from Google PR:
Today, Google announced the availability of the Google Deskbar API (application programming interface). This technology makes it possible for software developers to build their own features, or plug-ins, for the popular Google Deskbar.
For instance, a developer could use Google Deskbar APIs to create a movie search command that enables users to search their favorite movie site by entering a movie name into the Deskbar search field and typing a special command such as "Ctrl'M." Other examples include:
- Locate and play a music play list on your hard drive
- Solve algebraic equations
- Send instant messages from the Deskbar (example: type "AIM
- [screen name] [message text]")
Results will be displayed within the Google Deskbar mini-browser which appears to the bottom right of the user's computer. New features developed with the Google Deskbar API will be displayed as an option in the Deskbar main menu.
The Google Deskbar API is in the experimental, beta phase. We invite developers to use the service and encourage them to send us their input and feedback. Plug-ins can be written in any .NET language, such as C# or Visual Basic.NET. More information about the Google Deskbar API can be found here:
http://deskbar.google.com/help/api/index.html
Posted by 0xFF3300 at 09:35 AM | Comments (0) | TrackBack
November 15, 2004
TryEnterCriticalSection vs EnterCriticalSection
I have always wondered about the advantages of TryEnterCriticalSection vs EnterCriticalSection.
To enable mutually exclusive access to a shared resource, each thread calls the EnterCriticalSection or TryEnterCriticalSection function to request ownership of the critical section before executing any section of code that accesses the protected resource. The difference is that TryEnterCriticalSection returns immediately, regardless of whether it obtained ownership of the critical section, while EnterCriticalSection blocks until the thread can take ownership of the critical section. When it has finished executing the protected code, the thread uses the LeaveCriticalSection function to relinquish ownership, enabling another thread to become owner and access the protected resource. The thread must call LeaveCriticalSection once for each time that it entered the critical section. The thread enters the critical section each time EnterCriticalSection and TryEnterCriticalSection succeed.
After a thread has ownership of a critical section, it can make additional calls to EnterCriticalSection or TryEnterCriticalSection without blocking its execution. This prevents a thread from deadlocking itself while waiting for a critical section that it already owns.
Posted by 0xFF3300 at 04:04 PM | Comments (0) | TrackBack
October 27, 2004
Migrating ATL Apps to Visual C++.NET
I am in the process of migrating an application from VC++ 6.0 to Visual C++.NET. This article has extremely useful:
"This article presents steps required to migrate Windows service applications (also called NT services) written using Visual C++ 6.0 and ATL to Visual C++.NET. Most of ATL and MFC code requires only recompilation when upgrading Visual Studio from version 6.0 to .NET. Unfortunately, this is not the case with ATL service applications. Part of ATL7 that handles Windows services has been rewritten, so most of the code that ATL Wizard generated in Visual C++ 6.0 is no longer needed – actually, the code is still in use, but it has been moved to ATL classes rather than being copied by Wizard to every service application you create. The downside of this improvement is that it breaks applications that were written using ATL3 (the version that came with Visual C++ 6.0)."
Posted by 0xFF3300 at 10:05 AM | Comments (0) | TrackBack
October 20, 2004
High Performance MySQL Book
Being that MySQL is my primary data store for applications running on my FreeBSD server, I thought I would check this book out.
Author Jeremy Zawodny has managed large numbers of MySQL servers for mission-critical work at Yahoo!, maintained years of contacts with the MySQL AB team, and presents regularly at conferences. Jeremy and Derek have spent months experimenting, interviewing major users of MySQL, talking to MySQL AB, benchmarking, and writing some of their own tools in order to produce the information in this book.
Posted by 0xFF3300 at 03:48 PM | Comments (0) | TrackBack
Coding for Security
Check out the Nov 2004 MSDN Magazine, good security articles. It just so happens I'm working on a project to reduce the attack surface of an application. Thanks!

Posted by 0xFF3300 at 10:05 AM | Comments (0) | TrackBack
October 15, 2004
IIS ASP.NET Performance Monitors
Probaly the 5 most important IIS 'at-a-glance' setting are the following:
ASP.NET: Requests Current
The number of requests executed per second. This represents the current throughput of the application. Under constant load, this number should remain within a certain range, barring other server work (such as garbage collection, cache cleanup thread, external server tools, and so on).
ASP.NET: Requests Queued
The number of requests waiting for service from the queue. When this number starts to increment linearly with respect to client load, the Web server computer has reached the limit of concurrent requests that it can process. The default maximum for this counter is 5,000. You can change this setting in the computer's Machine.config file.
ASP.NET Application: Pipeline Instance Count
The number of active request pipeline instances for the specified ASP.NET application. Since only one execution thread can run within a pipeline instance, this number gives the maximum number of concurrent requests that are being processed for a given application. In most circumstances it is better for this number to be low when under load, which signifies that the CPU is well utilized.
Web Service: Total Method Requests/sec
The current methods combined (GET, POST, PUT) being executed per second. This number should be lower than Requests Current.
Web Service: Current Connections
Total number of raw HTTP connections to the server.
Posted by 0xFF3300 at 11:45 AM | Comments (0) | TrackBack
October 13, 2004
ASP.NET: ASM to IL compiler
Now this is interesting.
"...so I decided to do something about it - by bringing x86 assembler programming into the .NET age. Well, at least to allow ASP.NET pages to be written in 80386 assembler.
To do just that, I've written a compiler (assembler?) that compiles 80386 assembler code into MSIL. In other words, you get to write assembler programs that compiles into the same IL of the .NET's Common Language Runtime that your fellow VisualBasic.NET and C# developers are using. So basically you can enjoy the thrill of low-level programming and still be compatible with your "oh, so modern" VB.NET friends."
Posted by 0xFF3300 at 10:13 AM | Comments (0) | TrackBack
CherryOS alllows Mac OS X emulation on x86
Looks promising, however no known release is yet available.
"Our solution, CherryOS, is to turn a PC into a Macintosh clone, and to run MacOS and Macintosh applications directly on the PC. You benefit from the lower cost and faster speed of the PC, and still keep the use of your Macintosh applications."
Posted by 0xFF3300 at 09:59 AM | Comments (0) | TrackBack
October 11, 2004
WINCRYPT.H
I am doing some research on how I can efficiently encrypt data .NET 1.1 and decrypt with VC++ 6.0, I found the following links very useful:
* the old and the new? WINCRYPT.H
* Generating a Key from a Password
* CryptDeriveKey
Posted by 0xFF3300 at 06:05 PM | Comments (0) | TrackBack
MSBuild Compatibility Toolkit 1.0 Available
Robert McLaws has released an MSBuild toolkit supporting all versions of the .NET framework from Visual Studio 2005.
Posted by 0xFF3300 at 02:10 PM | Comments (0) | TrackBack
October 08, 2004
ASP.NET Canonicalization Security Flaw
A security vulnerability in ASP.NET has been identified that could allow an attacker to gain access to secured content. This issue centers around how ASP.NET locates files based on file names sent as part of a server request. Microsoft has issued a recommendation to add a check for this attack to your Global.asax file.
What is canonicalization?
Canonicalization is the process by which various equivalent forms of a name can be resolved to a single standard name, or the "canonical" name. For example, on a specific computer, the names c:\dir\test.dat, test.dat, and ..\..\test.dat might all refer to the same file. Canonicalization is the process by which such names are mapped to a name that is similar to c:\dir\test.dat.
Microsoft ASP.NET Security Incident
You may be able to safeguard against this by following the MS recomendation here:
Programmatically check for...
Posted by 0xFF3300 at 09:37 AM | Comments (0) | TrackBack
September 22, 2004
ASP.NET Performance
Since we have had some major issues recently regarding ASP.NET performance, I'll share some of the solutions I found. There are two major settings within the <processModel> node of the .NET machine.config: maxWorkerThreads and maxIoThreads. If you are running a web farm these could be set at the machine.config for easy deployment, or they may be set at a Web.config level. The maxWorkerThreads and maxIoThreads setting are threads per processor. So if the machine has 4 processors and the maxWorkerThreads=100, the following will be true: 4 * maxWorkerThreads will result in 400 max total threads. Microsoft recommeds you set both of the settings to 100. It is unknown if the the runtime will actually use that many threads. I also imagine that theses are logical threads and not physical threads.
The second machine.config node is the <httpRuntime>. The settings that should be changed are: minFreeThreads and minLocalRequestFreeThreads. If there are not minFreeThreads available to ASP.NET, the request will be queued and executed when they become available. MS recomeneds you set these to the following:
* minFreeThreads parameter to 88*N (N=CPUs)
* minLocalRequestFreeThreads parameter to 76*N (N=CPUs)
Another frequently misunderstood setting it the webGarden setting. This implies one aspnet_wp worker process per CPU if the setting is true (IIS 6). Web gardening has some side effects that you should be aware of:
* If your application uses session state, it must choose an out-of-process provider (NT Service or SQL).
* Application state and application statics are per process, not per computer.
* Caching is per process, not per computer.
[1] Contention, poor performance, and deadlocks when you make Web service requests from ASP.NET applications
[2] webGarden setting for multi-processor machine
[3] Using the ASP.NET Process Model
Posted by 0xFF3300 at 09:34 AM | Comments (0) | TrackBack
September 17, 2004
2 Connection Strings = 2 Connection Pools
I always wondered about this situation, if my app has 2 different connection strings will it have 2 different connection pools? The answer is yes, .NET checks if the connection strings are an *exact* match, if not it creates a new connection pool.
"When a connection is opened for the first time a connection pool is created and the pool is determined by the exact match of the connection string in the connection. Each connection pool is associated with a distinct connection string. When a new connection is requested, if the connection string is not an exact match to an existing pool, a new pool is created."
Posted by 0xFF3300 at 01:16 PM | Comments (0) | TrackBack
September 10, 2004
Soap over UDP
Well this spec is interesting, I feel the applications may be a little limited, but nonetheless interesting. UDP is much less expensive than HTTP, however datagrams are not guaranteed to reach their destination. An interesting specification definitely.
Posted by 0xFF3300 at 06:12 PM | Comments (0) | TrackBack
August 19, 2004
Visual C# 2005 Express Edition Beta
I am giving Visual C# 2005 Express Edition a test run, it looks fairly promising. Although it looks more aimed at getting entry or junior developer into C#/.NET programming, it has some very nice features.
Posted by 0xFF3300 at 09:07 PM | Comments (0) | TrackBack
August 15, 2004
Lifetime ILease and InitializeLifetimeService()
When creating a remotable class or handler, your object should most likely have a lifetime lease, unless it is desirable that it should be short-lived. The default lease time for ILease is set to 5 minutes. After that the lease expires and object becomes garbage collector food. The code below is an example of creating a lifetime lease for the class Example.cs.
using System;
using System.Runtime.Remoting.Lifetime;
namespace Remotable.Services
{
///
/// By Default an object lease is provided for 5 minutes. You
/// should create a lifetime ILease, otherwise the garbabge collector
/// will destroy your instantiated class
///
public class Example : MarshalByRefObject
{
public override Object InitializeLifetimeService()
{
ILease lease = (ILease)base.InitializeLifetimeService();
if (lease.CurrentState == LeaseState.Initial)
{
lease.SponsorshipTimeout = TimeSpan.FromSeconds(0);
lease.InitialLeaseTime = TimeSpan.FromSeconds(0);
}
return lease;
}
}
}
Posted by 0xFF3300 at 11:53 AM | Comments (0) | TrackBack
August 07, 2004
Reflection Exception: Strong name validation failed
I have an application that reflects a set of binaries (dll/exe) into HTML documentation. Reflecting the full MS .NET 1.1 framework seems to work fine, but when I reflect the Mono 1.0 binaries I run into a problem with the System.* namespace. The common error I receive: System.IO.FileLoadException "Strong name validation failed for assembly 'System.Xml.dll'". When I take a look the AssemblyInfo.cs file for System.Xml, AssemblyDelaySign is set to 'true'. And the AssemblyKeyFile points to ecma.pub.
I assume this has something to do with the delay signing. Looking for additional insight...
I get the following:
System.IO.FileLoadException: Strong name validation failed for assembly 'System.
Xml.dll'.
File name: "System.Xml.dll"
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, B
oolean isStringized, Evidence assemblySecurity, Boolean throwOnFileNotFound, Ass
embly locationHint, StackCrawlMark& stackMark)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Boolean
stringized, Evidence assemblySecurity, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence security
Evidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Entry.Main(String[] args) in c:\home\reflecta\entry.cs:line 221
So I take a look at the AssemblyInfo.cs file for System.Xml:
using System;
using System.Reflection;
using System.Resources;
using System.Security;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about the system assembly
#if (NET_1_0)
[assembly: AssemblyVersion("1.0.3300.0")]
[assembly: SatelliteContractVersion("1.0.3300.0")]
#elif (NET_2_0)
[assembly: AssemblyVersion ("2.0.3600.0")]
[assembly: SatelliteContractVersion ("2.0.3600.0")]
#elif (NET_1_1)
[assembly: AssemblyVersion("1.0.5000.0")]
[assembly: SatelliteContractVersion("1.0.5000.0")]
#endif
[assembly: AssemblyTitle("System.Xml.dll")]
[assembly: AssemblyDescription("System.Xml.dll")]
[assembly: AssemblyConfiguration("Development version")]
[assembly: AssemblyCompany("MONO development team")]
[assembly: AssemblyProduct("MONO CLI")]
[assembly: AssemblyCopyright("(c) 2003 Various Authors")]
[assembly: AssemblyTrademark("")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDefaultAlias("System.Xml.dll")]
[assembly: AssemblyInformationalVersion("0.0.0.1")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: ComVisible(false)]
[assembly: AllowPartiallyTrustedCallers]
[assembly: AssemblyDelaySign(true)]
[assembly: AssemblyKeyFile("../ecma.pub")]
Posted by 0xFF3300 at 09:09 AM | Comments (0) | TrackBack
July 31, 2004
.NET 1.1 Framework Reflected Documentation
I have created a full set of reflected documentation of the 1.1 .NET Framework here. This included the full ILDASM output if available, just browse around and click on the filter button to get more information. There is also a mono-1.0 version here. Enjoy!
Posted by 0xFF3300 at 03:35 PM | Comments (0) | TrackBack
July 21, 2004
Microsoft Virtual Server 2005
This looks pretty interesting: Virtual Server 2005. It allows for multiple concurrently operating servers on a single box. My first question was: How many Virtual Servers can run per box? Basically it's limited by memory and machine speed. You can can define the maximum amount of memory available to each virtual machine. The CPU resources can also be set by weight and capacity, so you can allow each VM to have different performance capabilities. It won't be available until late 2004, but I'm going to give it a shot and see how it goes.
Posted by 0xFF3300 at 11:26 AM | Comments (0) | TrackBack
June 23, 2004
Build.Net Release 0.6.2.30848
There is a new Build.Net release which not only supports the building of VS.NET csproj files, but vbproj files also.
June 17, 2004 Release: Build.Net MSI Installer (0.6.2.30848)
Build.Net is run from the command line. It recursively searches a directory for VS.NET project files to build. This directory to be searched is passed in via the '-find' parameter. Any *.csproj OR *.vbproj that is found is parsed into an object model and added to the build list. Any *pattern* in the -findexclude parameter will NOT be built. Build.Net will attempt to build any dependcies that does not already exist in the output directory. The dependency is *hopefully* in the build list. Your project files should all have the same
output directory (OutputPath).
Posted by 0xFF3300 at 10:05 PM | Comments (0) | TrackBack
June 17, 2004
Logging? Think Twice...
This is an experiment in the somewhat obvious, but to see how big of problem it can be, let's take a much closer look at a very common and basic feature of most software, logging. When performing smaller functions or operations consider the verbosity and quantity when it comes to logging information. The example below performs some 10,000 Math operations and logs the each result to the log file. As you can see the amount of time between the start and finish is greater than 12 seconds.
06_08 11:53:12.6875 2152 INFO === Log Start === 06_08 11:53:12.6875 2152 INFO Test 2.71828182845905 06_08 11:53:12.7031 2152 INFO Test INDEX=0 ... Performing Work AND Logging ... 06_08 11:53:24.6250 2152 INFO Test Infinity 06_08 11:53:24.6250 2152 INFO Test INDEX=8750 06_08 11:53:24.6250 2152 INFO === Log End ===
When performing the exact same 10,000 Math operations and only writing the first result, to record a start time, the result of course is dramatically different. The time difference is slighly more than 250ms.
06_08 11:53:43.8437 376 INFO === Log Start === 06_08 11:53:43.8437 376 INFO Test 2.71828182845905 06_08 11:53:43.8437 376 INFO Test INDEX=0 ... Performing Work AND *NO* Logging ... 06_08 11:53:43.8750 376 INFO === Log End ===
The moral of the story is log only what you need to. Logging IO can actually be quite expensive. These tests were performed with .NET 1.1 Framework.
Posted by 0xFF3300 at 11:56 AM | Comments (3) | TrackBack
June 14, 2004
Reverse Engineering To Learn .NET Better
Read Brian Long's article here.
Posted by 0xFF3300 at 08:29 PM | TrackBack
June 08, 2004
Reflector.Graph Released
Jonathan de Halleux has made available a 1.0 release of his Reflector.Graph tool, a plugin for Lutz Roeder's Reflector utility, which (as its name implies) provides some graphical views of call flows and such within .NET assemblies.
It consists (at the moment) of three parts:
Download it here.
Posted by 0xFF3300 at 08:26 PM | Comments (0) | TrackBack
June 04, 2004
Reflector for .NET
One of the nicer Assembly class browsers, Reflector for .NET.
"Reflector is a class browser for .NET components. It supports assembly and namespace views, type and member search, C# XML documentation viewer, call and callee graphs, IL, VB and C# disassembler, dependency trees, base type and derived type hierarchies and resource viewers. C#, Visual Basic and Delphi language syntax is supported."
Posted by 0xFF3300 at 08:38 PM | Comments (2) | TrackBack
June 01, 2004
AsyncDelegate VS ThreadPool
There has been some debate about which Threading methodolgy to use when it comes to multi-threaded asynchronous applications. You could use the .NET ThreadPool or maybe use Delegates. It is really a matter of keeping track of threads and coding style.
One thing to keep in mind is wether you use Asynchronous Delegates or the System.Threading.ThreadPool class you are still:
- Relying on the internal .NET Thread Pool.
- Using the BeginInvoke and EndInvoke methods, here the WaitCallback object of QueueUserWorkItem has it's own calls:
- public virtual IAsyncResult BeginInvoke(object state, AsyncCallback callback, object object);
- public virtual void EndInvoke(IAsyncResult result);
- public virtual IAsyncResult BeginInvoke(object state, AsyncCallback callback, object object);
- Using Delegates.
The advantage I see with ThreadPool is basically less coding required. The disadvantage becomes apparent when your application begins to take on some load, also less flexibilty when it comes to the size of the ThreadPool. I am not completely sure about this, but I believe the System.Threading.ThreadPool is capped off at 25 threads. Changing this from the .NET runtime is nearly impossible. Of note, Stephen Toub of Microsoft has created ManagedThreadPool to mainly combat the TheadPool size limit and other limitations ThreadPool. It's rumored that ManagedThreadPool will [0] be included in the .NET Framework 1.2.30506.
QueueUserWorkItem Source:
public static bool QueueUserWorkItem(WaitCallback callBack, object state)
{
StackCrawlMark mark1 = StackCrawlMark.LookForMyCaller;
return ThreadPool.QueueUserWorkItem(callBack, state, ref mark1, true);
}
public static bool QueueUserWorkItem(WaitCallback callBack)
{
StackCrawlMark mark1 = StackCrawlMark.LookForMyCaller;
return ThreadPool.QueueUserWorkItem(callBack, null, ref mark1, true);
}
References:
TO BE CONTINUED...
Posted by 0xFF3300 at 09:17 PM | Comments (0) | TrackBack
April 29, 2004
Build.Net Released
Well, I finally got around to releasing Build.Net, a .NET project-based command line build tool.
Read all about it straight from the README file. Let me know how your build turns out. Yet another tool built out of frustration. ;)
Description ----------- Build.Net is run from the command line. It recursively searches a directory for VS.NET project files to build. This directory to be searched is passed in via the '-find' parameter. Any *.csproj that is found is parsed into an object model and added to the build list. Any *pattern* in the -findexclude parameter will NOT be built. Build.Net will attempt to build any dependcies that does not already exist in the output directory. The dependency is *hopefully* in the build list. Your project files should all have the same output directory (OutputPath).
Posted by 0xFF3300 at 09:08 PM | Comments (2) | TrackBack
April 22, 2004
Microsoft Releases First MSDN Article on MSBuild
I have been waiting for more information on MSBuild, as it's almost identical to Ant. It will be standard as part of MS Visual Studio 2005. The code is basic XML and looks something like this:
<Project MSBuildVersion="1.2">
<Item
Type="FilesToCompile"
Include="HelloWorld.cs"
/>
<Target Name="BuildHelloWorldExecutable">
<Task
Name="csc"
Sources="@(FilesToCompile)"
OutputAssembly="HelloWorld.exe"
targetType="exe"
/>
</Target>
</Project>
[0] Overview of MSBuild, Part 1
Posted by 0xFF3300 at 04:41 PM | Comments (1) | TrackBack
April 20, 2004
Lindows Filing IPO
Lindows, Inc. yes the name sounds familiar enough, it kind of reminds me of the Microsoft OS. Either they have done the research or they are about to get one heck of a lawsuit.
"Lindows, Inc. announced today that it has filed a registration statement with the Securities and Exchange Commission for the initial public offering of its common stock. All of the shares are to be sold by the Company. WR Hambrecht + Co is acting as the lead manager of the offering, which will be made through WR Hambrecht + Co's OpenIPO(R) auction process. Roth Capital Partners is acting as co-manager. The offering will be made only by means of a prospectus. When available, copies of the preliminary prospectus relating to this offering may be obtained from WR Hambrecht + Co at 555 Lancaster Avenue, Berwyn, Pennsylvania 19312, telephone (800) 673-6476, or Roth Capital Partners at 24 Corporate Plaza, Newport Beach, California 92660, telephone (949) 720-5700."
Lindows, Inc. is a developer and vendor of Linux-based operating systems,
application software and services designed specifically for desktop and laptop
computers in homes, schools and businesses.
A registration statement relating to these securities has been filed with
the Securities and Exchange Commission but has not yet become effective. These
securities may not be sold nor may offers to buy be accepted prior to the time
that the registration statement becomes effective. This news release shall not
constitute an offer to sell or the solicitation of an offer to buy nor shall
there be any sale of these securities in any state or jurisdiction in which
such offer, solicitation or sale would be unlawful prior to registration or
qualification under the securities laws of any such state or jurisdiction."
Posted by 0xFF3300 at 03:40 PM | Comments (0) | TrackBack
April 19, 2004
NRobot 0.12 Released
NRobot is an autonomous robot fighting game. By "autonomous" I mean that instead of directly controlling a robot, the human playing the game must write a program that acts as the "brain" of the robot. The robot will then be dumped into the game arena and must attempt to survive on its own. Other similar projects include IBM's RoboCode (written in Java); I've also heard that there was a very old BBC microcomputer game with a similar premise where robots were written in BASIC.
By contrast, NRobot is written for the ECMA CLI. It's been tested on Mono and on Microsoft's .NET framework - there are separate GUI frontends for these two environments due to differences in toolkit maturity, but the backend code is common. The use of the CLI means that (in theory at least) many languages are available for implementing robots in. Currently I believe that C# is the only language with a mature Free Software implementation capable of writing robots in, but this is likely to change as Mono's implementations of VB and EcmaScript improve, and the IKVM Java [0] implementation gets more support for CLI features (currently, it lacks "attributes" which are required for use in NRobot, but support for them is planned for the future).
This is the first public release of NRobot, coinciding with the move to public development at https://www.gna.org/. Currently, NRobot is functional and "playable". It comes with three sample robot implementations, so that "out of the box" you can watch a game. One important missing feature is a security architecture: robot code executes with full privileges. Thus, it's recommended that if you are running any robots from untrusted sources, NRobot is run under a user
account with no privileges over files you care about. It's also short on documentation and the GUI implementations have some rough edges.
NRobot is licensed under the GPL, but also carries an explicit disclaimer that robots written for it are not considered derived works. This is to preserve the competitive aspect of the game - it isn't expected that the robots themselves will have public source code, in most cases. While I strongly believe in both the ethics and practical benefits of Free Software, I don't think they apply to robots developed for NRobot: a robot is specifically designed to compete with other robot implementations and reflect the skill only of its author, rather than being cooperatively developed to achieve the best possible result.
Homepage: http://home.gna.org/nrobot/
Download: http://download.gna.org/nrobot/
Development: https://gna.org/projects/nrobot/
Mailing List: nrobot-list AT gna.org
References:
[0] http://www.ikvm.net
Posted by 0xFF3300 at 05:09 PM | Comments (0) | TrackBack
April 13, 2004
Choosing a TCP Port for Remoting
When designing a Remotable service it's important to choose non-conflicting TCP port. Applications connecting to SQL Server will use just about ANY TCP port between 1200 and 5000. Do a netstat -a on your app server and you'll be able to see what I'm talking about. If your remoting application starts and that port is in use, obviously it will not be able to register itself on that TCP port.Posted by 0xFF3300 at 10:41 AM | Comments (0) | TrackBack
April 10, 2004
C# MIDI Components
I have been looking for some decent C#/.NET MIDI libraries or just plain reference implementations. Here are some:
Posted by 0xFF3300 at 09:14 AM | Comments (0)
March 28, 2004
Netcraft: ASP.NET Overtakes JSP and Java Servlets
This month, March 2004, according to Netcraft [0] ASP.NET has surpassed JSP and Servlets. First off to understand how the results were tallied, the signature was recorded as follows, ASP.NET - local references to ASP.NET file extensions are found on the front page of the site and JSP/Servlets inplmentations were determined by local references to .jhtml, .jsp, .gsp file extensions, or a local url starting "/servlets". Now I'm sure they may have missed quite a few for sites that are using either Java or .NET HTTP handlers, but I guess it's a start. In addition a great deal of Java websites use Struts [1] and frankly I don't know of many people that still use the /servlets prefix.
[0] http://news.netcraft.com/archives/2004/03/23/aspnet_overtakes_jsp_and_java_servlets.html
Posted by 0xFF3300 at 01:42 PM | Comments (0) | TrackBack
March 26, 2004
Eiffel and the .NET Framework
Eiffel for .NET is a full implementation of the Eiffel method and language running on the Microsoft .NET Framework.
Eiffel is a comprehensive software development environment (ISE Eiffel) based on a method that covers the entire software lifecycle—not just implementation but also analysis, design, and maintenance. The environment is based on the Eiffel language, thoroughly applying the principles of object technology and implementing the concepts of Design by Contract™ to produce highly reliable, extendible, and reusable applications.
ISE Eiffel is particularly geared towards large and complex systems and is used by major organizations in the financial industry, defense, real-time and other industries for mission-critical developments. Universities worldwide also use Eiffel to teach programming and software engineering at all levels.
The .NET Framework is Microsoft's new programming model for building Web applications, smart client applications, and XML Web services—applications that expose their functionality programmatically over a network using standard protocols such as SOAP, XML, and HTTP. The specification of the .NET Framework is now an international standard, thanks to Microsoft's successful submission of the common language infrastructure (CLI) to the ECMA standards organization, which adopted it in December of 2001. (One of the authors, Emmanuel Stapf from ISE, is a member of the corresponding ECMA Technical Committee.) Although a detailed presentation of the .NET Framework is beyond the scope of this article, we may note the following highlights, of special interest to application developers:
- The architecture relies on a virtual machine, so that compilers for any language always generate the same code, MSIL (Microsoft Intermediate Language).
- The code that gets executed on any actual computer is native (binary) code for that computer, translated incrementally or not, through a process known as just-in-time (JIT) compilation
- The virtual machine's equivalent of an operating system is the common language runtime (CLR), providing a number of crucial facilities—memory management, garbage collection, security, exception handling—to programs regardless of their language or origin (hence the word "common").
- The memory model used by the virtual machine and the CLR does not rely on addresses, bytes, and words; instead, it is an object-oriented model based on the notions of type, class, object, inheritance, polymorphism, typing, and dynamically bound calls.
- The language interoperability mechanisms of the .NET Framework, including the common language runtime, MSIL, the object model, and the Common Language Specification (CLS), enable the various parts of an application to use different programming languages—each chosen to be the best for the job at hand—and to achieve a degree of inter-language cooperation unprecedented in the software world. Not only may a module call a routine written in another module, a class in an object-oriented language may inherit from a class in another, exceptions cross language boundaries, as do debugging sessions—and all this is achieved without any special effort on the programmer's part and without any need for languages to know about each other.
- A new development environment, Visual Studio .NET, provides advanced development facilities—compilation, browsing, debugging, user interface development—and is, like the rest of the technology, open to many languages.
- .NET provides thousands of reusable components extending across many application areas, from localization to networking and language analysis.
- Among the most important component libraries are Microsoft® ASP.NET, an innovative framework for building Web applications and XML Web services; Microsoft® ADO.NET, an object-relational interface library; and Microsoft Windows® Forms for building Windows-based smart client applications.
- These mechanisms are potentially available to developers using any programming language, provided the implementers of that language offer a compiler that's compatible with .NET Framework—not only by generating IL but also by observing the .NET Framework rules of language interoperability.
The .NET Framework is attractive to Eiffel users since it follows many of the same ideas that they have accepted as essential to quality software development: use of an object model, automatic garbage collection, and exception handling. It also offers an integrated platform with direct access to thousands of reusable components, the prospect of full interoperability with software elements written in both Eiffel and other languages, and the power of XML Web services and other Internet applications.
For .NET Framework users, Eiffel provides the added value of an advanced object-oriented method and language that covers the entire lifecycle—not just programming, but the whole process starting with analysis and design and continuing with implementation, reuse, extension, and maintenance. Eiffel also offers unique reliability mechanisms such as Design by Contract™, advanced language features such as genericity and multiple inheritance, and the extensive body of reusable components developed by ISE and other parties, including the EiffelBase library of data structures and algorithms and the EiffelVision library for multi-platform graphics.
Eiffel on the .NET Framework provides an ideal combination for companies wishing to take advantage of best-of-breed technologies in operating systems, Internet and Web infrastructure, software development methods, and development environments. In particular, the openness of Eiffel to other languages and environments combined with the .NET Framework's emphasis on language neutrality makes the resulting product an ideal vehicle for building applications containing components in many different languages, Eiffel serving as the glue between them. In the rest of this article, we describe this combination and the challenges we faced when integrating ISE Eiffel into .NET.
Posted by 0xFF3300 at 05:16 PM | Comments (2) | TrackBack
March 24, 2004
OpenGL Libraries for C#
Here are a couple of useful C# libraries for working with OpenGL.
Tao Framework - Misc C# wrappers for OpenGL (used by Axiom)
http://www.randyridge.com/Tao/Default.aspx
Axiom - C# 3D game engine for .Net
http://axiomengine.sourceforge.net/
ExoEngine - A C# OpenGL and Cg 3D Game Engine for .NET
http://www.exocortex.org/3dengine/
Posted by 0xFF3300 at 09:12 AM | Comments (0) | TrackBack
March 18, 2004
MyXAML: Open Source XAML
After searching the web to find any usable XAML parser pre-release .NET Framework 1.2, I came across MyXAML. MyXaml is a general class instantiator capable of initializing properties, wiring up events to event handlers, and drilling down into property collections, customizable with inline or code-behind, language non-specific, JIT assembling at runtime. Very cool...
Posted by 0xFF3300 at 09:55 AM | Comments (1) | TrackBack
February 29, 2004
.NET Remoting VS ASP.NET Web Services
Here is an excellent article on MSDN that came out in September '02, it compares .NET Remoting VS ASP.NET Web Services. The quote that interested me was: ".NET Remoting is more versatile and extensible in terms of enabling communication between objects using different transport protocols and serialization formats. TCP, HTTP, and custom protocols are supported as are Binary, SOAP, and custom formats...", yet in Longhorn, the next release of the .NET framework, we are encouraged to use Web Services over .NET Remoting. Go figure. [0] REF: Building Distributed Applications with Microsoft .NETPosted by 0xFF3300 at 04:35 PM | Comments (0) | TrackBack
February 24, 2004
Free UML Design Tools for .NET
I was browsing for some free UML tools that can actually do .NET, here is what I came up with:
VP-UML (Visual Paradigm for UML Community Edition) pretty decent tool with great VS.NET integration. Being as it's free, I would say hands down, this is the one of the best .NET UML design tools out there.
RE.NET is a reverse engineering utility that builds a UML representation of the classes in any .NET assembly, including third-party assemblies and COM wrappers for which the source code is not available.
ArgoUML doesn't do .NET, as it's geared toward Java developers, but will do great for downright quick design, great user interface, you'll need the Java Runtime 1.2 or higher.
Dia is good, but rather basic. It kind of works like Visio, which I am not a fan of. It's target at gtk+ Linux users, and I don't believe there are any plans to run it on windows.
Posted by 0xFF3300 at 01:25 PM | Comments (1) | TrackBack
February 19, 2004
machine.config W2k Security Issue
I had a recent problem with reading the custom setting section from machine.config. It turned out to be a security issue. The user the application is running as, should be allowed to 'Act as part of the operating system' or you may set the appropriate read access to the user to read machine.config.Posted by 0xFF3300 at 11:49 AM | Comments (1) | TrackBack
February 17, 2004
.NET User Interface Components
I was looking for some .NET UI components/libraries to use in a new app I've been developing, as the .NET framework comes with barely enought to get by. Although I wouldn't call my new application a 'killer app' by any means, but it could certainly use some help in the GUI area. It's funny most of them have an implementation of VS.NET or an Outlook example. Here is what I have so far:
* http://www.dotnetmagic.com/
* http://www.componentsource.com/
Posted by 0xFF3300 at 10:55 PM | Comments (2) | TrackBack
February 13, 2004
Visual SourceSafe Frequently Asked Questions
MichaelIs.Net has put together one of the most comprehensive FAQs for Microsoft Visual Source Safe yet. I came across it while searching for a fix to corrupted VSS file, as this is commonplace with VSS. Since my company insists on using VSS for reasons that are confidential, it looks like we will be sticking with it for the time being. View the VSS FAQ here.Posted by 0xFF3300 at 08:15 AM | Comments (4) | TrackBack
February 08, 2004
NVelocity the .NET Port of Velocity
As I may have mentioned earlier Velocity is hands down one of my favorite MVC framework tools. It allows logic to be executed within a Web page, by it's own scripting language known as Velocity Template Language (VTL). To truly understand the power of this concept is to divide the work into roles, it allows Web Designers to easily work with component developers due to the very straightforward VTL. The language is simple but for a reason, the things you can do in a web page SHOULD be limited. It practically forces component development. Recently, I have played around with NVelocity, the .NET port of Velocity and have found it to be excellent.Posted by 0xFF3300 at 05:48 PM | Comments (0) | TrackBack
January 29, 2004
Forcing .ASPX Compilation
John Lam wrote an article about Forcing Compilation of ASPX Pages without executing them within the server context. Since ASPX pages are a necassary evil in our current software architecture, I would love to be able to precompile them before they are deployed. Apparently PageParser.GetCompiledPageInstance(), can help accomplish this. Also interesting is this article about Hosting ASP.NET Outside of IIS.
Posted by 0xFF3300 at 03:48 PM | Comments (2) | TrackBack
January 21, 2004
FireDaemon
Here's a good replacement to SRVANY.EXE, if you don't have access to the Windows Resource Kit.
FireDaemon :: Install and run Win32 applications as Windows NT/2K/XP/2K3 services
Posted by 0xFF3300 at 11:54 AM | Comments (1) | TrackBack
January 19, 2004
Microsoft Offers Linux-Interoperability Software For Free
Microsoft has decided to drop the $99 licensing fee previously required for its Services For Unix software and plans to make a new version of the interoperability product available this week at no cost on its Web site.
Services For Unix is a subsystem of Unix APIs and development and administration tools intended to help businesses migrate Unix or Linux applications to Windows computers or create heterogeneous environments where the operating systems coexist. SFU version 3.5, to be available Thursday, will come with performance improvements and new features that make it better at both of those functions, yet Microsoft officials say the price change represents a strategy shift that's equally important.
"The big news on this release, we think, is that it's free," says Dennis Oldroyd, a director with Microsoft's Windows server group.
Microsoft had developed a reputation among some customers for not doing enough to help them deal with the growing number of mixed computing environments. In a survey last fall by InformationWeek Research, more than half of the 400 business-technology professionals who responded said Windows-Linux interoperability was a problem, and 87% were of the opinion that Microsoft was leaving the interoperability work to others.
"The real driver behind this [pricing] change is this interoperability issue," Oldroyd says. "We want Windows to be the best platform for interoperability."
The three main components of SFU--Unix's Network File System and Network Identity Service and Microsoft's Interix layer of Posix APIs--have all been tuned for better performance, with some commands running 50% faster, Oldroyd says. SFU 3.5 also features first-time support for P-Threads (for Posix-compliant multithreaded applications), a broader set of Posix APIs, and updated utilities and libraries.
Posted by 0xFF3300 at 03:58 PM | Comments (1) | TrackBack
January 16, 2004
Integration of NAnt with NUnit Bug
I have placed the following lines in my build.xml.
<nunit2>
<test assemblyname="bin/debug/WebDAOI.dll" outfile="results.xml"/>
</nunit2>
When I run NAnt, it gives the following error:
The located assembly's manifest definition with name 'nunit.framework' does not match the assembly reference.
If I remove the <nunit2> line from the build.xml, NAnt is able to create the assembly perfectly, and I am able to test the same in NUnit from the GUI.
Moreover, while building the assembly using NAnt, I have included the reference for nunit.framework.dll. Seems like I am missing some other reference.
NAnt uses precompiled NUnit using some particular version of nunit.framework.dll. Most likely this version is not what you've compiled
your assembly against.
Try recompiling your dll, but instead of using nunit.framework.dll that comes with NUnit, use the one from NAnt.
Hope it helps,
Jarek
[0] [Nant-users] Integration of NAnt with NUnit
Posted by 0xFF3300 at 05:04 PM | Comments (1) | TrackBack
More Nant Complaints About
For God's sakes the Nant team considers the <record> task part of NAnt.Contrib.Tasks, why in the worlkd is it not a core task like Apache Ant!? It just makes it a pain to build. Can you ever think of time that you would not want the results logged in an AUTOMATED build environment?
<record>
A task that records the build's output to a file. Loosely based on Ant's Record task.
This task allows you to record the build's output, or parts of it to a file. You can start and stop recording at any place in the build process.
Posted by 0xFF3300 at 01:45 PM | Comments (0) | TrackBack
.NET Shared Source CLI Documentation
I have posted the .NET Shared Source CLI documentation here. Enjoy.
The Common Language Infrastructure (CLI) is the ECMA standard that describes the core of the .NET Framework world. The Shared Source CLI Beta Refresh is a compressed archive of the source code to a working implementation of the ECMA CLI and the ECMA C# language specification.
This implementation builds and runs on Windows XP and the FreeBSD operating system. It is released under a shared source initiative. Please see the accompanying license.
The Shared Source CLI Beta Refresh goes beyond the printed specification of the ECMA standards, providing a working implementation for CLI developers to explore and understand. It will be of interest to academics and researchers wishing to teach and explore modern programming language concepts, and to .NET developers interested in how the technology works.
Posted by 0xFF3300 at 10:21 AM | Comments (0) | TrackBack
January 15, 2004
Registry: Register .soap files as XML
Not too much to see here folks. All this registry change does, is register any .soap file on Windows as text/xml. When clicking on any .soap file, the it will cause the file to be opened in the Internet Explorer.
Download file, just click Open to install.
Posted by 0xFF3300 at 05:18 PM | Comments (2) | TrackBack
January 14, 2004
Parse Error, No Assembly Associated with Xml Key a1
When deserializing an oject from the FileSystem, I receive the following error:
An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in system.runtime.serialization.formatters.soap.dll: Parse Error, no assembly associated with Xml key a1.
The code basicallly looks like this:
string path = System.IO.Path.GetFullPath(testCasePath+"StatusTest-RV10.xml");
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
SoapFormatter formatter = new SoapFormatter();
ValueObject value = (ValueObject) formatter.Deserialize(fs);
The problem is I can deserialize a similar object without Exception. I have also tried using the full namespace of my ValueObject, but to no avail. The solution I finally ended up with was this:
Yes, actually I love it when I answer my own questions. If you look at the 'a1' value, it carries additional Assembly information; especially Version information. If the serialized file was created with a DIFFERENT Assembly version other than the one that is trying to read in right back in, the Soap Serializer will be unable to Deserialize. This is merely a safety measure to ensure that what you serialized out is what your are serializing back in.
<SOAP-ENV:Body>
<a1:ValueObject id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/N6k.Types/N6k.Types%2C%20Version%3D2.6.17.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D6377e9412c0f826e">
</a1:ValueObject>
...
</SOAP-ENV:Body>
Posted by 0xFF3300 at 10:56 AM | Comments (3) | TrackBack
January 12, 2004
Executing ASMX files without a Web Server
This console application from Jim Klopfenstein's Weblog, takes a SOAP message (on stdin) and an ASMX filename and a SOAPAction header (as command-line parameters) and returns the resulting SOAP message on stdout.
The ASMX file should be in the same directory as the executable; full paths are not supported.
Posted by 0xFF3300 at 04:06 PM | Comments (0) | TrackBack
SoapFormatter
Use of IFormatter is highly encouraged when Serializing/Deserializing objects to XML. There's a good reason for this, take a look at this example.
public class BankAccount
{
private System.Collections.ArrayList m_Mappings;
[XmlElement(typeof(AccountTypeMapping))]
public System.Collections.ArrayList Mappings
{
get{return m_Mappings;} set{m_Mappings = value;}
}
}
When the class is Serialized out, using just the XmlSerializer, it looks fine, but when Deserialized, the m_Mappings member is a zero-length array. But when it was Serialized it had 3 items inside of it. That's because the XmlSerializer does not Serialize private members, but won't it 'set' members loaded from XML that have public methods? No. So using the code below we get our desired result:
///
/// Simple Serialized
///
public static void toXML(object output)
{
FileStream fs =null;
try
{
string filename = output.GetType().FullName+".xml";
fs = new FileStream(filename, FileMode.Create);
SoapFormatter formatter = new SoapFormatter();
formatter.Serialize(fs, output);
fs.Close();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
finally
{
fs.Close();
}
}
From the .NET Framework Documentation:
System.Runtime.Serialization.Formatters.Soap.SoapFormatter
The SoapFormatter and BinaryFormatter classes implement the IRemotingFormatter interface to support remote procedure calls (RPCs), and the IFormatter interface (inherited by the IRemotingFormatter) to support serialization of a graph of objects. The SoapFormatter class also supports RPCs with ISoapMessage objects, without using the IRemotingFormatter functionality.
During RPCs, the IRemotingFormatter interface allows the specification of two separate object graphs: the graph of objects to serialize, and an additional graph containing an array of header objects that convey information about the remote function call (for example, transaction ID or a method signature). For proper serialization, the root object of the first graph must be an object that implements either the IMethodCallMessage interface or the IMethodReturnMessage interface.
During deserialization of an RPC, a HeaderHandler delegate is specified to the Deserialize method of the formatter. The remoting infrastructure uses the HeaderHandler delegate to produce an object that supports the ISerializable interface. This object contains the information stored in the headers, and becomes the root of the graph returned by the deserializer.
The SoapFormatter can also handle RPCs that are produced with objects implementing the ISoapMessage interface. To create an RPC without using the IRemotingFormatter functionality, place an object that supports the ISoapMessage interface at the root of a graph being serialized. To deserialize an RPC created in this manner the TopObject property must be set to another object that supports the ISoapMessage interface, and contains the relevant remote call information.
Posted by 0xFF3300 at 10:38 AM | Comments (0) | TrackBack
January 07, 2004
Building a Challenge/Response Spam Blocking System
Interesting approach to Stopping Spam
Posted by 0xFF3300 at 03:13 PM | Comments (2) | TrackBack
January 06, 2004
Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad
Rico Mariani, performance architect for the Microsoft® .NET runtime and longtime Microsoft developer, mentioned to Dr. GUI in an e-mail conversation recently that a fairly common practice (and one that's, unfortunately, described in some of our documentation right now, although we'll be fixing that) is actually quite problematic. He asked if Dr. GUI could help get the word out that programmers shouldn't do this. The good doctor was delighted to oblige.
What is this fairly common practice? Well, it's getting a lock on a type object. In C#, it's lock(typeof(ClassName)) where ClassName is the name of some class; in Microsoft® Visual Basic® .NET, it's SyncLock GetType(ClassName).
A bit of background: The lock/SyncLock statement is used in multithreaded programming to create critical sections, or brief sections of your code where only one thread can execute at a time. (You might need this if you had to update more than one field in your object simultaneously—you'd want to make sure that another thread didn't try to update the object at the same time!) This statement locks the unique monitor object associated with the object you specify, waiting if another thread has the monitor already. Once it locks the monitor, no other thread can lock it until your thread releases the lock, which happens automatically at the end of enclosed block. A common usage is to lock the this/Me reference so that only your thread can modify the object you're using—or better yet, to lock the specific object you're about to modify. Locking the smallest possible object is good because it helps to avoid needless waiting.
So the type object is pretty handy. But some programmers have taken to using it as a "cheap" way of getting a proxy for a static/Shared object you can put a lock on. (And, unfortunately, we document this in both the C# and Visual Basic .NET documentation, implying that it's a recommended practice.) In this case, the docs are wrong (and we'll be correcting them). This practice is not acceptable, let alone recommended.
Here's why: Since there's one type object for all instances of a class, it would appear that locking it would provide a lock equivalent to locking a static object contained in your class. You would lock all instances of the class, wait until other threads were done accessing any part of any instance, then lock access so you could access static members safely and without another thread interfering.
And it does work, at least most of the time. But there are problems with it: First, getting the type object is actually a fairly slow process (although most programmers would guess that it's extremely fast); second, other threads in ANY CLASS and even different programs running in the same application domain have access to the type object, so it's possible that they'll lock the type object on you, blocking your execution entirely and causing you to hang.
The basic problem here is that you don't own the type object, and you don't know who else could access it. In general, it's a very bad idea to rely on locking an object you didn't create and don't know who else might be accessing. Doing so invites deadlock. The safest way is to only lock private objects.
But wait; it's even worse than all that. As it turns out, type objects are sometimes shared across application domains (but not across processes) in current versions of the .NET runtime. (This is generally okay since they're immutable.) That means that it's possible for ANOTHER APPLICATION running even in a different application domain (but in the same process) to deadlock your application by getting a lock on a type object you want to lock and never releasing it. And it would be easy to get access to that type object because the object has a name—the fully qualified name of the type! Remember that lock/SyncLock blocks (that's a polite word for hangs) until it can obtain a lock. It's obviously really quite bad to rely on a lock that another program or component can lock and cause you to deadlock.
Even if the type objects were unique to your application domain, this would still be a bad practice because any code could get access to the type object for a public type and cause a deadlock. This is especially a problem when you use components in your application that you didn't write. (Even lock(this)/SyncLock Me can have this problem, since someone else can lock you. Although if that happens, it's likely to be easier to find than the deadlock caused by locking a type object, since your object isn't globally available across application domains.)
So what should you do instead? Well, it's pretty easy: just declare and create an object to use as a lock, then use it, not the type object, to do your locking. Usually, to duplicate the intended semantics of the bad code, you'll want this object to be static/Shared—and it really, of course, should be private! In general, you could change the following bad code:
// C#
lock(typeof(Foo)) { // BAD CODE! NO! NO! NO!
// statements;
}
' VB .NET
SyncLock GetType(MyClass) ' BAD CODE! NO! NO! NO!
' statements
End SyncLock
…into the following good code:
// C#
lock(somePrivateStaticObject) { // Good code!
// statements;
}
' VB .NET
SyncLock GetType(somePrivateStaticObject) ' Good code!
' statements
End SyncLock
Of course, you'll have to either have a private static object to lock already (if you're using the lock to modify static objects, you may in fact already have one!) or you'll have to create one. (Make it private to keep other classes from locking your object.) Do NOT attempt to lock a field that's not a reference (object) type, such as int/Integer. You'll get a compiler error. If you don't have a private static object to lock, you may need to create a dummy object:
// C#
Class MyClass {
private static Object somePrivateStaticObject = new Object();
// methods of class go here--can lock somePrivateStaticObject
}
' VB .NET
Class MyClass
Private Shared somePrivateStaticObject As New Object
' methods of class go here--can lock somePrivateStaticObject
End Class
You'll want to analyze each case separately to make sure you've got it right, but in general, the above technique should work.
Note a couple of things: First, no code outside of your class can lock MyClass.somePrivateStaticObject, so you've eliminated many opportunities for deadlock. And deadlocks are among the nastiest bugs to find, so eliminating opportunities for them is a very good thing.
Second, you know that there's exactly one copy of MyClass.somePrivateStaticObject for your application and exactly one for each other application on the system that is running, so there's no interplay across applications in the same application domain. Dr. GUI hopes you can see why this code is much more reliable and robust than the bad code.
To summarize, don't lock type objects. You don't know where they've been. Doing so is slow and can expose you to possible deadlock situations. It's a bad programming practice. Instead, lock a static object in your object.
This article came from Dr. GUI and was reprinted on serial.n6k.com.
Posted by 0xFF3300 at 10:45 AM | Comments (0)
January 02, 2004
Exception accessing custom section in Web.config
When attempting to access the custom section of a .NET Web.config file I received the following exception.
Parser Error Message: Could not load type System.Configuration.SingleTagSectionHandler from assembly System.Web, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
This is due to the fact that System.Web cannot access the System namespace. The full information about the Assembly System.Web is trying to load, including the PublicKeyToken, must be provided. Since I recently has this problem, I will share the solution I found. It works, but it clearly something that Microsoft should work on there Security model.
You need to add the assembly details to the type. When trying to load the
type, because the assembly name is not in there, the framework is looking
in the System.Web namespace. So, you need to modify it to the following:
<configSections>
<section name="sampleSection"
type="System.Configuration.SingleTagSectionHandler,System,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<sampleSection setting1="Value1" setting2="value two" setting3="third
value" />
I tried this and this works. Please be sure that you have used the correct lower/upper case for the assembly names. I had this problem initially.
Posted by 0xFF3300 at 12:53 PM | Comments (1)
January 01, 2004
.Net Support For Apache
In July of 2003 Microsoft announced .Net support for Apache. Covalent had developed an Apache plugin-in to allow .NET support in Apache, but I haven't heard to much about it since then. I imagine it works similar to the mod_jk module.
"In a move designed to expand choices for Web developers, Covalent Technologies announced Wednesday that Apache 2.0, as available in Covalent's Enterprise Ready Server, is now compatible with Microsoft's ASP.NET."
References:
http://www.newsfactor.com/story.xhtml?story_id=18740
http://www.covalent.com/
Posted by 0xFF3300 at 07:53 PM | Comments (0)
December 30, 2003
Build.Net Project
Ok, so I have started a new build tool project (Build.Net) that does the following:
This was based on the previous article I wrote here.
Posted by 0xFF3300 at 11:31 AM | Comments (0) | TrackBack
December 22, 2003
Creating an ASP.NET HTTP Handler with C#
This step-by-step article demonstrates how to use Visual C# .NET to create a simple, custom HTTP handler. This article demonstrates how to create, deploy, and configure the handler.
Implement the Handler
- Open Microsoft Visual Studio .NET. In Visual C# .NET, create a new Class Library project named MyHandler.
- Set a reference to the System.Web.dll assembly.
- Add the following directive to the class:
using System.Web;
- Rename the class SyncHandler.cs, and then change the class definition to reflect this.
- Implement the IHttpHandler interface. Your class definition should appear as follows:
public class SyncHandler : IHttpHandler
- Implement the IsReusable property and the ProcessRequest method of the IHttpHandler interface. Because this is a synchronous handler, return False for the IsReusable property so that the handler is not pooled.
public bool IsReusable
{
get {return false;}
}public void ProcessRequest(HttpContext context)
{
context.Response.Write("Hello from custom handler.");
}
- Compile the project.
Deploy the Handler
- Create a new directory named Handler under the C:\Inetpub\Wwwroot directory.
- Create a subdirectory named Bin in the newly created Handler directory. The resultant path is C:\Inetpub\Wwwroot\Handler\Bin.
- Copy MyHandler.dll from your project's Bin\Debug directory to the C:\Inetpub\Wwwroot\Handler\Bin directory.
- Follow these steps to mark the new Handler directory as a Web application:
- Open Internet Services Manager.
- Right-click the Handler directory, and then click Properties.
- On the Directory tab, click Create.
- Follow these steps to create an application mapping for the handler. For this handler, create a mapping to the Aspnet_isapi.dll file for the *.sync extension. Whenever a .sync file is requested, the request is routed to ASP.NET, and ASP.NET executes the code in the handler.
- Right-click on the Handler Web application, and then click Properties.
- On the Directory tab, click Configuration.
- Click Add to add a new mapping.
- In the Executable text box, type the following path:
Microsoft Windows 2000:
C:\WINNT\Microsoft.NET\Framework\<version#>\Aspnet_isapi.dll
Microsoft Windows XP:
C:\WINDOWS\Microsoft.NET\Framework\<version#>\Aspnet_isapi.dll
- In the Extension text box, type .sync.
- Make sure that the Check that file exists check box is cleared, and then click OK to close the Add/Edit Application Extension Mapping dialog box.
- Click OK to close the Application Configuration and the Handler Properties dialog boxes.
- Close Internet Services Manager.
Configure the System
- In the C:\Inetpub\Wwwroot\Handler directory, create a new file named Web.config.
- Add the following code to Web.config:
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="*.sync" type="MyHandler.SyncHandler, MyHandler" />
</httpHandlers>
</system.web>
</configuration>
In the verb="*" attribute, we instruct the handler to process a request that uses any verb (for example, POST, HEAD, GET, and so on). If you want this handler to process only the POST request, change this to verb="POST".
In the path="*.sync" attribute, we instruct the handler to process any incoming requests for files with the .sync extension.
In the type="MyHandler.SyncHandler, MyHandler" attribute, we instruct the handler that processes the request to implement in the MyHandler.SyncHandler namespace, and this class resides in the MyHandler assembly.
Test the Module
To test a handler, a page does not need to exist in the file system. For example, request the Default.sync file in the Handler Web application (http://<ComputerName>/Handler/Default.sync). You should receive the following results:
back to the top
Hello from custom handler.