Monday, July 7, 2008

Static Classes and Members in ASP.NET Web Applications

Do not use static classes in web applications. They will overwrite each other when different users access the same web pages at the same time. Concurrency issues.

Static methods are ok, along with any parameters passed to them. Any local variables inside the static methods are ok as well.

DO NOT Use public static class or static properties in web application, unless their values should be the same for all users.

Following statics are ok.

static void Main(string[] args)
{
Utils.LogError("aa"); //testing statics
Utils.LogError("bb");
}


class Utils
{
//all these vars get initialized the first time any static method is called from this class
//and used for all other calls
static readonly string _path = GetPathFromRegKey();

public static void LogError(string msg) //testing statics
{
//_path is initialized only once above & is used for all calls to LogError
string logFile = _path + "\\LogFile.txt";
Console.WriteLine(msg + " " + logFile);
}


public static string GetPathFromRegKey()
{
string path = "";

//Get path...

return path;
}


Useful Links:

http://blogs.iis.net/brian-murphy-booth/archive/2007/06/15/static-shared-or-not-who-cares.aspx

http://gbracha.blogspot.com/2008/02/cutting-out-static.html

http://www.yoda.arachsys.com/csharp/singleton.html

http://msdn.microsoft.com/en-us/library/ms954629.aspx

Tuesday, June 24, 2008

TIP: Debugging a MS Dynamics CRM Callout from Visual Studio

If you are getting System.Data.SqlClient.SqlException: Could not find stored procedure 'sp_sdidebug' error (as logged by CRM Trace), make the following settings in your project and Attach to Process.

  1. In project properties: Debug tab – Uncheck 'Enable SQL Server debugging'. Compile the project in debug mode, and copy the dll and pdb files to \Program Files\Microsoft CRM\server\bin\assembly
  2. Run the page that calls the callout so that the assembly is loaded into memory
  3. At VS command prompt enter tasklist /m assemblyname* to get the process id
  4. Open the project in visual studio, add break points
  5. In the Debug menu in visual studio, select Attach to process, select w3wp.exe with ID obtained in step 3. Make the following settings.

  1. Click Attach
  2. Run the page that calls the callout and the process will step into the code.

Remote debugging steps are the same, but you need to create a local admin account on the server with same credentials as yours, start the remote debugger with that user id (By right clicking remote debugger tool & clicking 'Run As')

Sunday, June 22, 2008

Planning for Visual Studio 2008 MCPD certification

I would like to get MCPD certification. Looked at the site http://www.microsoft.com/learning/mcp/mcpd/vstudio/2008/default.mspx
I can either go for 1) MCPD: Windows Developer 3.5 or 2) MCPD: ASP.NET Developer 3.5 or 3) MCPD: Enterprise Application Developer 3.5

One noteworthy resource is the msdn blog of developer certification planner. http://blogs.msdn.com/gerryo/

Now, suppose, I want to go for 2) MCPD: ASP.NET Developer 3.5, I first need to complete MCTS: .NET Framework 3.5, ASP.NET Applications (two exams), which are:
1) Exam 70-536: TS: Microsoft .NET Framework, Application Development Foundation http://www.microsoft.com/learning/en/us/exams/70-536.mspx

2) Exam 70-562: TS: Microsoft .NET Framework 3.5, ASP.NET Application Development http://www.microsoft.com/learning/en/us/exams/70-562.mspx (This exam is in development. It is expected to be released in August 2008)

Please Wish me luck! (to stay motivated to prepare & to actually go for the exam!)

Here goes the study resources...

Exam 70-536 Study Guide http://en.csharp-online.net/Category:Exam_70-536_Study_Guide

Tuesday, January 8, 2008

VS 2008 Here I come

Top 15 Things to love about Visual Studio 2008 Express
http://blogs.msdn.com/danielfe/archive/2007/11/19/top-15-things-to-love-about-visual-studio-2008-express.aspx

Visual Studio 2008 Samples
http://msdn2.microsoft.com/en-us/vcsharp/bb330936.aspx


Friday, November 16, 2007

Useful Object Oriented Links

Some of the useful object oriented and c# links:

http://www.blackwasp.co.uk/CSharpObjectOriented.aspx

http://en.wikipedia.org/wiki/Object-oriented_programming

http://java.sun.com/docs/books/tutorial/java/concepts/

http://aonaware.com/OOP1.htm

http://www.oopweb.com/

More explanations to come later...

Monday, November 12, 2007

Signing the assembly in vs 2005 when assembly have to be in .NET 1.1 version

This applies to .NET 1.1 projects created using Visual Studio 2005.

In the project properties -> signing -> create a strong key with or without password. (mykeyname.pfx -with password, mykeyname.snk - w/o password). If you try to compile now, you will get the following error:

Unrecognized command-line option: '/keyfile:mykeyname.snk'

So, "Uncheck" sign the assembly there, so that .net 1.1 assembly compiles without error. In project properties, go to Application tab and click "Assembly Information". Enter Assembly Information and click OK. This will create "AssemblyInfo.cs" (In Properties folder). In "AssemblyInfo.cs" file, enter-
[assembly: AssemblyKeyFile("mykeyname.snk")]
Now compile the assembly, which will be compiled successfully.

This assembly (dll) can now be used to register in GAC using gacutil.

Tuesday, October 30, 2007

Getting Started with ASP.NET AJAX

Describes how to setup ASP.NET AJAX for the first time and then create a first application. Based on a video at http://www.asp.net
Full Article and Source Code