Archive for the ‘.Net Programming’ Category

Brainbench “C Fundamentals” Certification

Wednesday, April 8th, 2009

Brainbench made some of their certification tests free for April 2009 so I took the C Fundamentals test.

Here’s my latest certification: Brainbench C Certification

Brainbench C Fundamentals Icon


Individual Test Results

Completed Test
Name: C Fundamentals
Score: 4.42 Date: 2009-04-08

View detailed topic results

Scored higher than 90% of all previous test takers.

Demonstrates a clear understanding of many advanced concepts within this topic. Appears capable of mentoring others on most projects in this area.

Strengths
Compiler Operations
Functions
Arrays
Program Statements
C Expressions
Weak Areas
Debugging and Error Handling



I was ding’ed for debugging and error handling, and I’ll look into that, but the score wasn’t too bad considering I took the test on a whim and without preparation.

BrainBench C# Test

Thursday, November 13th, 2008

I took the C# test at BrainBench today. Here’s the result…


Individual Test Results – Actionable Data Just For You

Test: C#
Date: 13-Nov-2008
Score: 3.99
Weights: 100% C#
Elapsed time: 57 min 31 sec
C#
Score: 3.99
Percentile: Scored higher than 89% of previous examinees

Demonstrates a clear understanding of many advanced concepts within this topic. Appears capable of mentoring others on most projects in this area.
Strong Areas
  • Grammar
  • Object-Oriented Programming
  • Value and Reference Types
  • Delegates
  • Developing Data Consumers and Services
  • Properties, Indexers, and Fields
  • Methods
Weak Areas
  • None noted

Your results are now posted to your online account. You can log on to your account anytime via the Brainbench home page.

You can also prove your C# skills to employers, recruiters, or anyone else by pointing them to your online Brainbench public transcript. Just send them this link:

http://www.brainbench.com/transcript.jsp?pid=7924288

A Case Insensitive Hashtable for .Net

Wednesday, September 17th, 2008

I recently needed a case insensitive hashtable to store various types of values so I created one by wrapping the .Net hashtable. This hashtable works with any “object” type, but when the key is a string the value is not case sensitive. This is useful for:

  • Reading profile settings from multiple sources.
  • Reading XML elements where the attributes are not case sensitive.Here’s a link: CIHash.vbIn composer free nokia ringtones | 24 free ringtones | nextel ringtones | yahoo ringtones free download | 3g for free ringtones | 24 theme ringtones | music ringtones | 3g for free ringtones | free hindi ringtones | cell cingular free phone ringtones | 24 fox ringtones | ringtones converter | download new ringtones free | boost free ringtones | real tone ringtones | make your own free ringtones | yahoo ringtones | free mobile phone ringtones | samsung polyphonic ringtones | christian music ringtones | ???????? ????? ???????? addition to the .Net hashtable methods, I added some new methods.
  • The Overlay method adds one hashtable to another and if a key already exists it’s value is updated.
  • The Swap method (as it’s name implies).
  • Why Visual Studio 2005 debugger is broken

    Wednesday, September 17th, 2008

    Visual Studio 2005 is a pretty big improvement over Visual Studio 2003. So what’s wrong with it? The debugger is broken, that’s what! And that’s no small thing either!

    I suppose that I should be more precise. The debugger is broken for all the code that I work on, and those projects are all mixed mode (managed / unmanaged) projects. I have many projects that I work on that predate the emergence of .Net when it came out in 2002 with Visual Studio. That’s why I have written so much about porting legacy (unmanaged) code to .Net.

    I was eager to use VS2K5 so I downloaded it a week before the official release date in November 2005. Right away I could see that the debugger was broken for my mixed mode project so I created a bug report on the MS website. Here’s a link:
    VB File locked while Debugging Mixed Mode project
    (You might need an MSDN license to view this link)

    The gist of this report is this:

    In VS2K5 it is not possible to both edit and debug a source file while debugging a program. That is, you can either:

  • Set a breakpoint in your project and the debugger will stop there, but you cannot modify the code while you are stopped.
  • Or change the VS2K5 options and the breakpoint will never be hit, but you can edit your code at any time.Changing modes requires going to the “Tools > Options” menu and changing the debug mode.
  • I want to be clear, I am not talking about that truly marvelous feature that MS calls “Edit & Continue” where you can, on the fly, edit and recompile code in a single debug session. I am talking about just editing the code without a recompile.

    The most frustrating thing about communicating this to MS tech support was that EVERYTIME the MS tech support kept saying that E&C is not supported in mixed mode. And EVERYTIME I had to explain that I wasn’t talking about E&C at all!

    So, debugging legacy code with VS2K5 becomes very time consuming and I choose to forgo using it until MS fixes it. However, it looks like they won’t acknowledge that the bug exists, even though at least one MS tech confirmed it for me (I burned one of my MSDN incidents to get at least some traction on it).

    .Net and the falacy of security

    Wednesday, September 17th, 2008

    .Net purports to be a secure platform, but when I create a .Net setup package and used a custom action I found that I could not run the setup package on a network.

    I have a VB.Net installer. The installer program I created
    (System.Configuration.Install) handles the various events
    like MyBase.AfterUninstall, etc. This program works fine
    but when I run the installer on a network resource (a UNC
    path) it generates a System.Security.Security exception
    before the program even starts. The .MSI installer kicks
    off just fine, but throws the exception just when the .EXE
    program starts.

    The installer works fine if the UNC drive is mapped, or if a
    local drive. Any idea on what may be happening?

    The solution may surprise you. It surprised me! The setup package created in VS.Net has to be given permissions to execute from a UNC path, but not from a mapped drive! My users would never go for having to do that. They want to click a link in the email I send or on a web page and have the installer run. Fortunately, there is an easy work around, but it shows just how crummy the .Net security is.

    Here’s the trick: Create a batch file named setup.bat that gives the user all the permissions the setup package needs to run on the network. Here’s the contents of the batch file used to set security on .Net 1.1:

    @GOTO :START
    /******************************************/
    /* $Date: 2006/06/09 17:51:05 $ */
    /* $Revision: 1.1 $ */
    /* $Author: mike $ */
    /******************************************/
    
    :START
    
    IF NOT "%1" == "/?" GOTO :TESTOS
    	ECHO.
    	ECHO CONFIGNET.BAT - Sets up the .NET configuration
    	GOTO :END
    
    :TESTOS
    IF "%OS%" == "Windows_NT" GOTO :SETLOC
    	ECHO.
    	ECHO !!! ERROR: SETUP PACKAGE REQUIRES A WINDOWS NT TYPE OS
    	GOTO :ERROR
    
    :SETLOC
    SETLOCAL ENABLEEXTENSIONS
    	IF ERRORLEVEL 1 GOTO :SETLOCERR
    	GOTO :TRIMCMD
    
    :SETLOCERR
    	ECHO.
    	ECHO !!! ERROR: COMMAND EXTENSIONS NOT AVAILABLE
    	GOTO :ERROR
    
    :TRIMCMD
    rem Trim the command line to be only a drive letter and path only
    SET MYROOTDIR=%~dp0
    IF "%MYROOTDIR%" == "" GOTO :RUNSU
    
    rem Test the SETUP DIR to see if we are on a UNC path. UNC paths start with "\\"
    rem A UNC path requires us to run caspol to give .NET permissions to run the setup
    	IF "%MYROOTDIR:~0,2%" == "\\" GOTO :TESTCAS
    	GOTO :RUNSU
    
    :TESTCAS
    rem At this point we have assumed that the batch file is run from a UNC path
    rem This requires that we SET the .NET permissions using CASPOL.EXE
    rem Verify that CASPOL.EXE is on the system
    	SET CASPOL_EXE=%SystemRoot%\Microsoft.NET\Framework\v1.1.4322\CasPol.exe
    	IF EXIST "%CASPOL_EXE%" GOTO :RUNCAS
    	ECHO.
    	ECHO !!! ERROR: MICROSOFT .NET v1.1.4322 PACKAGE NOT INSTALLED
    	GOTO :ERROR
    
    :RUNCAS
    rem Run CASPOL and see if the permissions are already SET for this UNC.
    rem CASPOL has the nasty habbit of creating permissions each time,
    rem regardless if they are already present or not.
    rem Change the "\" to "/" which is what caspol likes to see
    ECHO Testing .NET security: "%MYROOTDIR%"
    "%CASPOL_EXE%" -lg 2>NUL | findstr /I /C:"%MYROOTDIR:\=/%" >NUL
    	IF ERRORLEVEL 1 GOTO :NEEDCAS
    	GOTO :CASOK
    
    :NEEDCAS
    rem CASPOL is required for this UNC Path. Add it to the .NET configuration
    ECHO Setting .NET security
    "%CASPOL_EXE%" -q -machine -addgroup 1 -url "file:%MYROOTDIR%*" FullTrust -n "mmGrasp" >NUL
    	IF ERRORLEVEL 1 GOTO :CASERR
    	GOTO :RUNSU
    
    :CASERR
    	ECHO.
    	ECHO !!! ERROR: Setting .NET for "%MYROOTDIR%"
    	GOTO :ERROR
    
    :CASOK
    	ECHO.NET security OK
    	GOTO :RUNSU
    
    :RUNSU
    	GOTO :END
    
    :END
    
    

    So there it is- one of the ways that .Net security falls short and an easy way to beat it.

    .Net and Legacy Code

    Wednesday, September 17th, 2008

    As you can see from my previous post I am interested in recycling my old “C” code for use in .Net. I don’t want to rewrite the code in C# or VB so I am wrapping it with a C# DLL. The good thing about .Net is that it already has much of the functionality that I put into some of these old C libraries. However, there is a lot that I didn’t write that I would like to wrap, in particular: GSL gets wrapped here: Gnu.dll.

    One of the big problems I have had with wrapping old DLLs is with arrays. .Net managed arrays are quite different from C arrays. Consider the following from GSL:
    // double gsl_stats_mean (const double data[]
    // , const size_t stride
    // , const size_t n);
    [DllImport("libgsl.dll"
    exact spelling=true,
    CharSet = CharSet.Ansi,
    CallingConvention=CallingConvention.Cdecl,
    EntryPoint="gsl_stats_mean"]
    public static extern double mean
    ( [In] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=3)]
    double [] data
    , [In] int stride
    , [In] int n);

    It seems to work OK, so what’s the problem? Try using this on a bunch of 1,000,000 element arrays and see what happens to the resources on your PC and you’ll soon see!

    The MarshalAs class copies the data in the .Net array into a new C array. Here is a better implementation that uses the GCHandle:

    public class gsl_stats {
    internal static unsafe GCHandle _gch_pinned_ptr(double[] data, ref double *p)
    {
    	GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned);
    	IntPtr ip = gch.AddrOfPinnedObject();
    	p = (double*)ip.ToPointer();
    	return gch;
    }
    public unsafe static double mean (double [] data
    	, int stride, int n)
    {
    double *p = null;
    	GCHandle gch = _gsl._gch_pinned_ptr(data, ref p);
    	double d = gsl_stats_DLL.mean(p, stride, n);
    	gch.Free();
    	return d;
    } // mean()
    } // gsl_stats
    public class gsl_stats_Dll
    {
    	[DllImport("libgsl.dll"
    	, ExactSpelling=true
    	, CharSet = CharSet.Ansi
    	, CallingConvention=CallingConvention.Cdecl
    	, EntryPoint="gsl_stats_mean")]
    	public static extern unsafe double mean
    		( [In] double *data, [In] int stride, [In] int n);
    } // gsl_stats_DLL