Understanding the Binder – Part 1

Understanding the Binder – Part 1

  • Comments 68

 

This is an introductory post on the internals of CLR Binder.   
 

What does the Binder do?

CLR's Binder is a piece of code that, when given an assembly name, determines where the assembly is and binds to it.

So how does the Binder locate assemblies?

Let's assume that you are loading an assembly (let’s call it Foo.dll for the sake of simplicity and sheer lack of imagination) as follows:

Assembly.Load(“Foo, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”);

(As a side note, please make sure that you always specify the fully specified reference of the assembly that you are trying to load. Avoid partial binds at all costs – unless you really know what you’re doing, partial binds are a recipe for disaster. We’ll cover this in more detail in a future post.)

 

The Binder goes through these steps to determine the desired assembly and it’s location:

1) Applying policy

By 'policy', we are referring to different ways in a user can configure assembly binding – to put it simply, think of this as the ability to substitute an assembly name with another.

Now, why would you want to do this?

By providing an option to specify configure assembly binding, developers and administrators can control which versions of assemblies an application will load and use, and provides more flexibility over the way in which managed applications run on specific machines.

Typically, there are three ways in which assembly binding behavior can be configured – you can specify an app.config file, a publisher policy or a machine configuration file (this is not the complete list of the ways in which policy can be specified, but for the sake of simplicity, we leave it at this for now).

The Binder looks at these config files and evaluates the ‘right assembly’ to go pick up.

2) Has the assembly been loaded before?

If the assembly has been loaded before, the runtime uses the assembly already loaded in the same context (notice how the word ‘context’ sneaked in there – we’ll talk about contexts in detail in a future post). Similarly, if loading the same assembly previously failed, subsequent loads are failed without re-trying to load the assembly.

3) Is it in the GAC?

For strong named assemblies, the Binder then looks into the contents of the Global Assembly Cache or the GAC (which is typically used to store assemblies that are shared by more than one application) and if found, picks this up.

4) Where else could it be?

If the Binder finds no match in the previous steps, it checks if the user has already specified locations to pick up the assembly from. This could be in the form of <codeBase> element in your config file, or using the AssemblyName object,(or using LoadFrom or FoadFile). The Binder gets the path and checks for the assembly at this location.

The Binder then resorts to what is called ‘probing’  - this is the process where the Binder starts looking at a specific set of locations for the assembly, the first location being the ‘appbase’.

'Appbase' is short for 'application base' or which is the root directory where the application to be executed resides in. The Binder examines this directory and it’s subdirectories to find a match for the assembly required to be located.

 

This post does over-simplify the binding process greatly, but covers the basic aspects of assembly binding in the process. We will talk about each section in detail (and also cover common gotchas)  in future posts in this series.

 

Aarthi Ramamurthy

PM, CLR

Leave a Comment
  • Please add 4 and 7 and type the answer here:
  • Post
  • 毎月10万円を最低ラインとする謝礼を得て、セレブ女性に癒しを与える仕事があります。無料登録した後はメールアプローチを待つだけでもOK、あなたもセレブラブで欲求を満たしあう関係を作ってみませんか

  • よーやくプロフ持ちになれました。私の事気になった方がいましたら気軽にメールください。恋バナとか好きなんでよろしくでぇす。zuttozuttoissyodayo@docomo.ne.jp

  • 女性会員様増加につき、当サイトの出張ホストが不足中です。女性の自宅やホテルに出向き、欲望を満たすお手伝いをしてくれる男性アルバイトをただいま募集していますので、興味のある方はTOPページから無料登録をお願いいたします

  • あなたのモテ度数を診断できる、モテる度チェッカー!日頃モテモテでリア充のあなたもそうでないヒキニートの貴方も隠されたモテスキルを測定して今以上にモッテモテになること間違いなし

  • オ○ニーライフのお手伝い、救援部でHな見せたがり女性からエロ写メ、ムービーをゲットしよう!近所の女の子なら実際に合ってHな事ができちゃうかも!?夏で開放的になっている女の子と遊んじゃおう

  • メル友募集のあそび場「ラブフリー」はみんなの出逢いを応援する全国版の逆援助コミュニティーです!女の子と真剣にお付き合いしたい方も、複数の女性と戯れたい方も今すぐ無料登録からどうぞ

  • 簡単にお小遣い稼ぎをしたい方必見、当サイト逆¥倶楽部では無料登録して女性の性の欲求に応えるだけのアルバイトです。初心者でもすぐに高収入の逆¥交際に興味をもたれた方はTOPページまでどうぞ。

  • Typo: FoadFile which should be LoadFile instead.

Page 5 of 5 (68 items) 12345