Monday, November 9, 2009

TIPS & TRICKS :-)

Want to see GAC in its naked view?

http://blogs.msdn.com/jigarme/archive/2007/06/20/want-to-see-assembly-in-its-naked-view.aspx

You can simply go to,HKLM\Software\Microsoft\Fusion
and create a DWORD value named "DisableCacheViewer" and set it to value 1.

Monday, October 19, 2009

CLR and Framework Loading...

  1. Very Good notes:http://social.msdn.microsoft.com/forums/en-US/clr/thread/e392129d-33fa-46e6-a518-2e971ce37d82
  2. What CLR version am I or me or this? http://www.devfish.net/articles/clrver/article_CLRVer.htm
  3. Determining Which Version of the Runtime to Load http://msdn.microsoft.com/en-us/library/w671swch.aspx
  4. Runtime Initialization from a COM Application http://msdn.microsoft.com/en-us/library/hz1www0a(VS.80).aspx
  5. Very Good Article:http://msmvps.com/blogs/carlosq/archive/2008/11/14/net-frameworks-clrs-and-visual-studio-add-ins.aspx

    snippet:
    We have two kinds of .NET Frameworks: -
    Side-by-side model:
    the .NET Framework is installed independently of other .NET Frameworks (it coexists with them). It uses its own CLR and it is complete. This is the case of .NET Framework 1.0 (VS.NET 2002), .NET Framework 1.1 (VS.NET 2003) and .NET Framework 2.0 (VS 2005).-
    Layer cake model:
    The .NET Framework is installed on top of other .NET Framework. It uses an existing CLR (not providing a new one) and it just supplies additional libraries. This is the case of the .NET Framework 3.0 (which introduced WPF, WF and WCF, but used CLR 2.0) and the .NET Framework 3.5 (VS 2008, it uses CLR 2.0 too). Notice that there is no CLR 3.0 or CLR 3.5.Only VS 2008 can target several .NET Frameworks (2.0, 3.0 or 3.5). Previous VS versions can only target the .NET Framework they introduced.An assembly compiled against a .NET Framework can run on ulterior .NET Frameworks (and CLRs) without problems (at least in theory, more on this later). For example, a .NET 1.0 assembly can run on a .NET 1.1 Framework. The opposite is not true for two reasons:- An assembly compiled against a given CLR can not run on a previous CLR. For example, an assembly compiled against CLR 2.0 can not run on CLR 1.0 or 1.1 (they know nothing about generics, for example).- An assembly compiled against a .NET Framework can not run on a previous .NET Framework, even if it shares the same CLR, because of missing libraries. For example, an assembly compiled against the .NET Framework 3.5 using WPF cannot run on the .NET Framework 2.0 despite both use the CLR 2.0 because a machine with only the .NET Framework 2.0 would lack the WPF libraries.

    There is an tool called clrver.exe which is shipped with the SDK for .Net 2.0 , you can find the tool under C:\Programme\Microsoft Visual Studio 8\SDK\v2.0\Bin
    If you use the clrver.exe tool without arguments you get the following output:C:\Programme\Microsoft Visual Studio 8\VC>clrver.exeVersions installed on the machine:v2.0.50727You can use all / argument to get more detailed information.-all - Displays all processes on the machine using the CLR. - Displays the version of the CLR used by the specified process.
    Thus you can get detail information about the running processes.
    3920 devenv.exe v2.0.507272084 WebDev.WebServer.EXE v2.0.507272944 Obab.UI.ProfessorenClientCab.vshost.exe v2.0.50727
    Unfortunatley, you can only get the information from running applications. There is no way to let clrver.exe determine the required/used framework version from the application file itself.
    =============Most applications will never need this config file entry. With the way the runtime version is chosen for most apps, the application gets the version of the runtime it was built against (if available on the machine). If the exe is managed it gets the described behavior. If the exe that launches the process is native but has a config file it gets the runtime specified in the config file. If the exe that launches the process is native and there is no config file then we are forced to choose the latest runtime version.
    Console.WriteLine(System.Reflection.Assembly.LoadFile(@"C:\Program Files\ Microsoft BizTalk Server 2006\ Microsoft.XLANGs.BizTalk.Engine.dll").ImageRuntimeVersion);
    The exception is being caused by the .NET framework because key parts of the framework contain version 2.0 specific code. When Visual Studio 2005 is used to create an application, the default CLR target is version 2.0. Previous versions of the framework cannot be loaded. See the More Info section on how to reproduce the issue. Visual Studio 2003 works without issue for versions previous to CLR 1.1. Visual Studio 2005 and Visual Studio 2008 fail consistently when the CLR target is less than version 2.0 of the CLR. CLR targets including 2.0 and later work as intended.
    CLR /Framework Versionshttp://blogs.msdn.com/davbr/archive/2007/12/06/versions-of-microsoft-net-framework-clr-and-your-profiler.aspx
    if your add-in is intended for VB.NET/C# a single binary can target VS.NET 2002/2003 and a different binary can target VS 2005/2008 (a single binary can't target all because VS 2005 introduced a new DLL for commandbars). First, some clarifications about .NET Framework and Common Language Runtimes (CLRs):

Thursday, June 18, 2009

.Net Remoting

  • Use to access objects in other processes on the same computer or on any other computer that is reachable over its network. Can also be used to communicate with other application domains in the same process.
  • NET remoting provides an abstract approach to interprocess communication that separates the remotable object from a specific client or server application domain and from a specific mechanism of communication. As a result, it is flexible and easily customizable. You can replace one communication protocol with another, or one serialization format with another without recompiling the client or the server.
  • So remoting is stands on :
  • Communication protocol
  • Serialization format.
  • Remoting require following components:
  • A remotable object.
  • A host application domain to listen for requests for that object.
  • A client application domain that makes requests for that object.
  • How .net Remoting helps in distributed architecture:
  • Passing object by value or by ref is donet by RF (remoting framewordk) we
    just need to configure it.
  • Processing different protocols.
  • Creating proxies and directing proxies call to actual objects.
  • Whole process requires very litttle code for complete cycle which includes: crating proxy at client end, Handling calls from client to that proxy object, open a channel to send the request, listining channel pics the request and sent the information to server remoting system which locates the actual object and call it's method and the whole process is rversed from server to client to send response.
  • By Value doesn't make sense in case of :
  • Large objects with lot of methods. as it will consume the memorey or client
    and network traffic.
  • Any object working on private data as it will be security breach.
  • Any server resource object like passing file instead of it's adderss.
  • Activation URLs: From the world outside the server application domain, a URL locates the object. The URLs that represent unique types to the outside world are activation URLs, which ensure that your remote call is made to the proper type. For more details, see Activation URLs.
  • Application Boundary: Remoting is only across boundary.
  • Process for windows operating system
  • Appdomains for managed code
  • NonRemotable object - Didn't have method defined for serialization.
  • Remotable object - http://msdn.microsoft.com/en-us/library/aa720494(VS.71).aspx
  • http://msdn.microsoft.com/en-us/library/kwdt6w2k(VS.71).aspx
  • http://www.codeproject.com/KB/IP/Net_Remoting.aspx
  • http://www.csharphelp.com/archives/archive157.html

Sunday, February 8, 2009

Generics

Generics - one of the mechanism of code reuse:algorithm reuse.
Generics allow you to define type-safe data structures, without committing to actual data types.
  • some one creates a an algorithm with generic data type and everyone can use it for their own data types.
  • CLR allow the creation of generic: Reference type, Value Type, Interfaces, Delegates, Methods but not of Enum type.
  • Advantages:
    • Compile time Type Safety
    • Cleaner Code as fewer casts are required.
    • Better perormance: before generics generic algo are made based on object data type so for any value type it require boxing which hurts performance. Now algo is defined for specific data type.
  • While performance improvement using generics are not much but it offers other benefits as like compile time type safety and cleaner code.
  • If actual datatype is passed in for all of the type arguments, the type is called closed type e.x.Dictionary. Instance of closed type can be created.
  • If some generic type argument left unspecified - it is open type object in CLR e.x. Dictionary. Instance of open type can not be created.
  • Code Explosion: Each time a generic method is called for a type it's native code is generated for that type so CLR will generate native for every method/type combination i.e. there will be two native code for List, List - code explosion. To avoid this CLR has some optimizations like: All reference type are considered identical, Two assemblies referring generic of same datat type will share same native code. But for value type code will explode as they have diff sizes or diff cpu instructions.
  • Generic type aliasing : wrting too many brackets in code <> make it un readable so u can use "using" for cleaner code - using listOfString = List; listOfString lss = new listOfString();
  • Arity: Number of Type parameters required by the Type. Dictionary arity -2, DictionaryStringKey - arity 1.
  • Generic Examples:
  • private static T Min ( T 01,T02) { if(o1.CompareTo(o2)<0>
  • Primary Constraints or Reference/Value type constraints.
    • Reference type specify that argument type is a class that is not sealed and arg type is of specified type or it's dervied type.
    • Value type specify that type arg will be a value type.
    • Ex: interanl sealed class PrConstr where T:class{} (in this T can be set to null inside the class as it is sure to be of reference type.)
    • Ex: interanl sealed class PrConstr where T:struct{} - it actually means that T will have a paramerter less default constr ( as all value type has it).
    • Type param can specify zero or one primary constraints.

  • Secondary Constraints or Derivation constraints.
    • A derivation constraint indicates to the compiler that the generic type parameter derives from a base type such an interface or a particular base class.
    • Can have zero or more sec constraints.
    • Ex in previous example of min:
    • T Min ( T 01,T02) where T:Icomparable { if(o1.CompareTo(o2)<0> - now this will make sure that type parameter T will have compareTo method.

  • Constructor Constraints: Suppose you want to instantiate a new generic object inside a generic class. The problem is the C# compiler does not know whether the type argument the client will use has a matching constructor, and it will refuse to compile the instantiation line. is done using the new() constraint.
    • A default constructor constraint indicates to the compiler that the generic type parameter exposes a default public constructor (a public constructor with no parameters).
    • Ex: internal sealed Class contrConst where T: new() {}
    • can have zero or one constructor constraints.

  • CLR doesn't allow overloading based on type parameter name or constraints. Overloading is based only on arity.
  • In Overriding number of type parameter must be same and overriding mthd can't define constraints it will inherit from base method.
  • Default Value : default key word allow developers to set a generic type param to default.
  • Ex - T temp = default(T) - this will set T to null if T is ref type or zero if T is value type.
  • Comparing to null is allowed without any constraints.
  • Comparing two variables of same generic type is illegal unless type parameter is known to be reference type.
  • .NET allows you to have serializable generic types:
  • Under .NET 2.0, you cannot define generic Web services.That is, Web methods that use generic type parameters. The reason is that none of the Web service standards support generic services.
  • You also cannot use generic types on a serviced component. The reason is that generics do not meet COM visibility requirements, which are required for serviced components

.Net 1.1 vs 2.0

The following sections of this topic describe changes made in different areas of ASP.NET:

Web Site Management
Web Site Administration Tool(wizard to configure web site)
Reserved Folders for Special Functionality
App_code - any class in this folder compiles automatically.App_Date - for DB.
Precompiling Web Sites for Error Checking and Deployment
Navigation - site map for menu.Treeview and siteMappath control for breadcrumb.

Page Design
Consistent Layout using Master Pages
Themes for Consistent Appearance
New Code-Behind Model for Pages - Partial Classes.(clean code).
User-Customizable Web Pages - Web Parts.
New Caching Features - Configurable thru web.config,Sql server dependent cache.
Enhanced Client-Side Functionality - Ajax and Cross page posting.

Controls
Enhancements: support adaptive rendering,Themes,group validator controls.
New Controls:GridView, Treeview, SiteMappath,Login controls,

Data
Data Source Controls:encapsulate connections, query commands, and parameters into a single control,
Connection String Storage:To enhance Web site security, you can store connection strings in a dedicated section of the configuration file.

Security
support for authenticating and authorizing users using membership.

ASP.NET 2.0 adds quite a few new events to allow you to follow the request-processing more closely and precisely.
-PreInit,InitComplete,Preload,LoadComplete,PrerenderComplete.

---------- Framework 2.0

Application domains : Support is provided for unloading an application domain.
Anonymous methods
Generics
Partial classes
SQL Server integration - now Host CLR.
64-Bit support
Iterators: Iterators enable you to use foreach loops on your own custom types.


http://msdn.microsoft.com/en-us/library/fa1h9d0d(VS.85).aspx
http://www.wrox.com/WileyCDA/Section/What-s-New-in-the-NET-Framework-2-0.id-290323.html