Archive for July, 2011

How to call a method from assembly without reference it?

public static void ShowMessageBox
string message,
params object[] args
// Skip for non-interactive execution.
if (!IsInteractive)

Type type;
object[] info;

type = Type.GetType(“System.Windows.Forms.MessageBox, ” +
“System.Windows.Forms, ” +
“Version=1.0.5000.0, ” +
“Culture=neutral, ” +
info = new Object[2];
info[0] = String.Format(message, args);
info[1] = Assembly.GetExecutingAssembly().GetName().Name;
/* 280 = */ BindingFlags.Static |
BindingFlags.Public |
null, null, info);
For out Side memory assembly-

Assembly assembly = Assembly.LoadFrom(@”C:\Documents and Settings\Sample.dll”);
Type local_type = assembly.GetType(“GetString”); //Getting Class File Name
Object local_Instance = Activator.CreateInstance(local_type);
string local_string = (string)local_type.InvokeMember(“ReturnString”, BindingFlags.InvokeMethod, null, local_Instance);
//Just invoking return string method,If you are calling any parameterised methods,add params at last parameter here,

Categories: .Net, C#

Find nth record from table + CTE example.

WITH NthRecord_CTE (FilterId,ID)

AS-- Define the CTE query.


    select FilterId,Row_Number() over(order by FilterID) as ID from Filter with (Nolock)


Select * from Filter Where FilterID=(select FilterID from NthRecord_CTE where ID=5)
// here your can define your number of record 
Categories: SQL

What is Finalize ? or Dispose vs Finalization. When they occur?

Finalization is a mechanism offered by the CLR that allows an object to perform some graceful cleanup prior to the garbage collector reclaiming the object’s memory.

The Finalize method is incredibly useful because it ensures that native resources aren’t leaked when managed objects have their memory reclaimed. However, the problem with the Finalize method is there is no guarantee of when it will be called, and because it isn’t a public method, a user of the class can’t call it explicitly.

The capability to deterministically dispose of or close an object is frequently useful when you’re working with managed types that wrap native resources such as files, database connections, and bitmaps. For example, you might want to open a database connection, query some records, and close the database connection—you wouldn’t want the database connection to stay open until the next garbage collection occurs, especially because the next garbage collection could occur hours or even days after you retrieve the database records.

What Causes Finalize Methods to Be Called?

1)Generation 0 is full

2)Code explicitly calls

System.GC’s static Collect method

3)Windows is reporting low memory conditions

4)The CLR is unloading an AppDomain

5)The CLR is shutting down

Categories: .Net, C#