I use this blog to save information/tips-tricks that I keep forgetting and which may be useful to others.
Sunday, July 29, 2012
Tuesday, March 27, 2012
Using the WCF Service Trace Viewer Tool
http://msdn.microsoft.com/en-us/library/ms732023.aspx
tool:
c:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\SvcTraceViewer.exe
config (replace [ with < ):
[system.diagnostics>
[trace autoflush="true" />
[sources>
[source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
[listeners>
[add name="sdt"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "pskbj.e2e" />
[/listeners>
[/source>
[/sources>
[/system.diagnostics>
Tuesday, February 28, 2012
Bat file to make .net assembely (dll or exe) 32 bit only
Rem Klaus Bjørn Jensen 29/01/2010
Rem Marks an assembely (dll or exe) as 32 bit only. Resigns the assembely with the specified key.
Rem The original file is not changed but a copy is made with "32" appended to the filename.
REM param1 : Fully qualified path to assembelyDll to register
REM param2 : Fully qualified path to the key file (*.snk)
SET AssembelyName=%~f1
SET SignKey=%~f2
SET NewFileName=%AssembelyName%32
copy "%AssembelyName%" "%NewFileName%"
call "%ProgramFiles%\Microsoft Visual Studio 8\VC\vcvarsall.bat"
corflags "%NewFileName%" /32BIT+ /force
sn -R "%NewFileName%" "%SignKey%"
Tuesday, January 31, 2012
C# Normal density function utils
///
/// Normal density function - Gaussian function
///
///
///
///
///
static double NormalDensityFunction(double x, double mean, double stdDev)
{
double Z = (x - mean);
Z = Z * Z;
Z = -(Z / (2 * stdDev * stdDev));
double normDist = (1 / Math.Sqrt(2 * Math.PI * stdDev)) * (Math.Exp(Z));
return normDist;
// Or
// return Math.Exp(-(Math.Pow((x - mean) / stdDev, 2) / 2)) / Math.Sqrt(2 * Math.PI) / stdDev;
}
///
/// Standard normal density function - mean = 0 and stdDev=1
///
///
///
static double NormalDensityFunctionStd(double Zscore)
{
double Z = -(Zscore * Zscore) / 2;
double normDist = (1 / Math.Sqrt(2 * Math.PI)) * (Math.Exp(Z));
return normDist;
}
///
/// Cumulative density function of a standard normal (Gaussian) random variable
/// Area under the normal density function from -inf to x
///
///
///
static double NormalCDF(double x)
{
const double a1 = 0.254829592;
const double a2 = -0.284496736;
const double a3 = 1.421413741;
const double a4 = -1.453152027;
const double a5 = 1.061405429;
const double p = 0.3275911;
// Save the sign of x
double sign = 1;
if (x < 0)
{
sign = -1;
x = x * -1;
}
x = x / Math.Sqrt(2.0);
//A&S formula 7.1.26
double t = 1.0 / (1.0 + p * x);
double y = 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * Math.Exp(-x * x);
return 0.5 * (1.0 + sign * y);
}
Monday, January 9, 2012
Enable / Disable Ping on Windows 2008
Ping is disabled by default on Windows 2008
To enable:
netsh firewall set icmpsetting 8
To disable:
netsh firewall set icmpsetting 8 disable
Tuesday, January 3, 2012
Json serializer fails for DateTime.MinValue
The .Net Json serializer ( DataContractJsonSerializer ) fails in certain time zones if you serialize uninitialized DateTime values ie DateTime.MinValue or default(DateTime)
Nice explanation by Nick Martyshchenko here:
http://stackoverflow.com/questions/4025851/why-can-datetime-minvalue-not-be-serialized-in-timezones-ahead-of-utc
You'll probably have the same issue with DateTime.MaxValue in certain time zones.
Workaround: initialize all DateTime values before serialization e.g. to DateTime.MinValue.ToUniversalTime()
Monday, November 7, 2011
Lise-Lotte Orhan - what a wast of time!
Tuesday, September 13, 2011
Wednesday, August 17, 2011
How to code sign strong named assemblies
...[Program Files]\Microsoft SDKs\Windows\v7.0A\Bin
like so:
1) from pfx file:
signtool.exe sign /f c:\temp\myCert.pfx /p myPfxPassword /v /t http://timestamp.comodoca.com/authenticode c:\temp\MyAssembly.dll
2) from certificate in certificate store on local machine:
signtool.exe sign /a /v /u "Code Signing" /n myCertificateName /t http://timestamp.comodoca.com/authenticode c:\temp\MyAssembly.dll
-output-
The following certificate was selected:
Issued to: MyCompany
Issued by: VeriSign Class 3 Code Signing 2010 CA
Expires: Fri Jun 15 00:59:59 2012
SHA1 hash: A8DE1239366767E63A6AF60F7DECAFE5B4A7AF42
Done Adding Additional Store
Successfully signed and timestamped: c:\temp\MyAssembly.dll
Number of files successfully Signed: 1
Number of warnings: 0
Number of errors: 0
Tuesday, November 9, 2010
Shell Command - Remove SVN Folders
The Subversion source control client maintains your local state in hidden folders named .svn inside your project, which can be a problem if you want to copy or share the project directory. This REG file adds "Delete SVN Folders" to the context menu for folders. When you select it, it removes all folders named .svn inside the folder and it's children (it does nothing if the project's not under Subversion source control.
I'm not going to bother explaining reg file installation here - I figure if you're using SVN, you're good with reg files.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
@="Delete SVN Folders"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
@="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""
I got the idea from Wyatt Preul's post comparing Powershell and Command Prompt commands to delete SVN directories, so if you'd like to do this manually take a look at his scripts.
Wednesday, October 27, 2010
How to add a manifest to a legacy application.
(1 for an EXE, 2 for a DLL
mt.exe –manifest MyApp.exe.manifest -outputresource:MyApp.exe;1
or
mt.exe –manifest MyLibrary.dll.manifest -outputresource:MyLibrary.dll;2
See also: http://msdn.microsoft.com/en-us/library/ms235591.aspx
http://msdn.microsoft.com/en-us/library/aa375649(VS.85).aspx )
Wednesday, August 4, 2010
Tuesday, May 19, 2009
Invoke with out param
Here is a trick inspired by Visual C# Forums and C# MVP Mattias Sjögren. In this code snippet int.TryParse() method is called using reflection and get result from out parameter.
int parNum = 0; string parText = "99"; object[] methodParms = new object[] { parText, parNum }; MethodInfo methInfo = parNum.GetType().GetMethod("TryParse", new Type[] { typeof(string), typeof(int).MakeByRefType() }); methInfo.Invoke(null, methodParms); parNum = (int)methodParms[1]; Console.WriteLine("Parsed number:{0}", parNum);
Wednesday, March 25, 2009
List SQL Servers on the lan
Monday, February 23, 2009
Mark a COM object as safe for scripting..
The following illustration shows a snapshot of the registry entry for the TDC, an ActiveX control that ships with Internet Explorer and allows authors to create data-driven Web pages. Because the control is safe for scripting and initialization, it marks itself in the registry as safe for scripting (7DD95801-9882-11CF-9FA9-00AA006C42C4) and safe for initializing from persistent data (7DD95802-9882-11CF-9FA9-00AA006C42C4).
Tuesday, February 17, 2009
Enable asp.net 2.0 in webservice extensions IIS6
Copied from:
http://office.microsoft.com/en-us/winsharepointadmin/HA100598511033.aspx
- Click Start, and then click Run.
- In the Open box, type cmd and then click OK.
- Open the following directory:
%drive%\WINNT\Microsoft.NET\Framework\v2.0.nnnnnwhere %drive% is the drive letter on which you installed Windows Server 2003 and nnnnn is the least significant version number of ASP.NET 2.0.
Note If you are running a 64-bit edition of Windows Server 2003 do not open the 64-bit directory. Windows SharePoint Services requires that IIS be run in 32-bit mode.
Klaus' Note: Personally I had better success using the 64.bit directory. - Run the following command at the command prompt:
aspnet_regiis.exe -iru -enable - Close the command prompt.
- In Internet Information Services (IIS) Manager click Refresh from the Action menu.
- Verify that ASP.NET v2.0.nnnnn is listed in the Web Service Extension column and that the status is Allowed. If the status isProhibited, you can change the status by right-clicking ASP.NET v2.0.nnnnn and then clicking Allow.
- After verifying that ASP.NET is allowed, the next step is to specify which virtual server or virtual servers you want to use ASP.NET 2.0. Proceed to Specifying which virtual servers use ASP.NET 2.0.
Left pad using string.Format()
Maybe you already know this but it took me many years to discover.
You can left pad by adding ,-X to the place holder in the format string.
Eg. the following lines:
Console.WriteLine(string.Format(" IsOK={0,-5} Name: {1,-20} xxx", true, "Klaus"));
Console.WriteLine(string.Format(" IsOK={0,-5} Name: {1,-20} xxx", false, "James"));
Console.WriteLine(string.Format(" IsOK={0,-5} Name: {1,-20} xxx", true, "RAU"));
produce the following output:

Nice isn’t it!
Thursday, July 17, 2008
Finding the .Net Service Pack Version
Klaus Bjørn Jensen 17-07-2008
Check the version of mscorwks.dll.Not every file in the framework/runtime gets patched in a service pack or hotfix, but mscorwks.dll is the core DLL of the CLR/runtime so that gets patched in any CLR hotfix.
Go to C:\WINNT\Microsoft.NET\Framework\Select the corresponding Version (1.0 or 1.1 or 2.0 ...) then find a file with the Name "mscorwks.dll" right click & go for Properties & Version
This is a list the key build numbers for the CLR:
1.0.3705.0 1.0 RTM
1.0.3705.209 1.0 SP1
1.0.3705.288 1.0 SP2
1.0.3705.6018 1.0 SP3
1.0.3705.6060 1.0 + MS07-040
1.1.4322.573 1.1 RTM
1.1.4322.2032 1.1 SP1
1.1.4322.2407 1.1 + MS07-040
1.1.4322.2300 1.1 with Windows Server 2003 SP1
2.0.50727.42 2.0 RTM
2.0.50727.312 2.0 Included with Vista
2.0.50727.832 MS07-040
2.0.50727.1433 2.0 SP1
See also: http://blogs.msdn.com/dougste/archive/2007/09/06/version-history-of-the-clr-2-0.aspx