何となく Blog by Jitta
Microsoft .NET 考

目次

Blog 利用状況
  • 投稿数 - 761
  • 記事 - 18
  • コメント - 35955
  • トラックバック - 222
ニュース
  • IE7以前では、表示がおかしい。div の解釈に問題があるようだ。
    IE8の場合は、「互換」表示を OFF にしてください。
  • 検索エンジンで来られた方へ:
    お望みの情報は見つかりましたか? よろしければ、コメント欄にどのような情報を探していたのか、ご記入ください。
It's ME!
  • はなおか じった
  • 世界遺産の近くに住んでます。
  • Microsoft MVP for Visual Developer ASP/ASP.NET 10, 2004 - 9, 2011
広告

記事カテゴリ

書庫

日記カテゴリ

ギャラリ

その他

わんくま同盟

同郷

 

元ネタ:dllの参照方法

xuexueさん (2006/12/28(Thu) 17:53:59):

なんでローカルにdllがおりてきちゃうのか疑問でなりません。
だって、dllがバージョンアップしたら、いちいち配置してあげないと・・ですよね。

はぁ。。。

「DLL Hell」という言葉を、ご存じでしょうか。こいつを回避するため、.NET Framework では、複数のアプリケーションで共通して使う DLL は、Global Assembly Cache に登録するか、アプリケーションの実行ファイルがあるところにコピーするように、強く推奨されています。

では、DLL Hell とは、どんなものでしょうか。私の体験を、書きます。

1997年でしたか。あるプロジェクトで、DateTimePicker を使うことになりました。テキスト ボックスに年月日が出ていて、クリックするとカレンダーが出てくるヤツです。

これを使ってアプリを作り、「出来ました!」と、品質保証部へ回したところ、「カレンダーで、なんにも選ばずにカレンダーの外をクリックすると、アプリケーションが落ちるんだけど?」

いや、あの、その。。。それって、Borland から提供してもらっている部品なんで。。。早速 Borland へ問い合わせる。返事有り。「マイクロソフトが提供している部品なので、弊社では修正いたしかねます」・・・が~~~~ん!!

というわけで、元になる DLL を特定し、その DLL の、他のバージョンがないか、探す。

あった。「一太郎」についてきたものが、バージョンが新しい。

早速テスト。良好良好。

「修正しました!!」と、渡す。「この、日付のあるところで、IME をオンにして、キーボードの上に手を置く(複数のキーを同時に押す)と、アプリケーションが落ちるんだけど?」

え゛?!そんなテスト、するですか?

ってことで、さらに他のバージョンがないか、探す。あった。MS Office と共にインストールされるものが、さらに新しい。

早速入れ替えてテスト。同時押しは直っている。が。カレンダー外クリックが復活しているorz

結局。テキスト ボックスを3つ並べましたよ。UI の悪さより、安定性を選んだわけです。

数ヶ月後。Borland のサイトで、カレンダー外クリックの対処方法が書かれているのを発見。さらにへこむ。

・・・・・

まぁ、このときは、結局直らなかったわけですが。

一太郎バージョンで不具合が出ず、その状態で出荷したとします。後で顧客が MS Office をインストールしたら?また、不具合が発生するわけです。

このように、DLL のバージョンによって、あるアプリケーションの挙動が左右されるような状態。そんな状態に、好きこのんでなりたいですか?

このような状態を回避するため、.NET Framework では、DLL を実行ファイルがあるのと同じディレクトリにコピーするようにしました。こうして、アプリケーションと DLL が同時に更新されるようにすることで、あるアプリケーションのための変更が、他のアプリケーションへ害を及ぼすことを阻止できます。

そもそも、DLL とは、Dynamic Link Library、実行時結合型のライブラリです。コンパイル時に結合されるライブラリは、LIB という拡張子が付けられています。

静的にリンクすると、ローカルにコピーしたモノを使うのと同じで、特定のバージョンを使い続けることが出来ます。しかし、なぜ、動的に結合するものが必要なのか。

ディスク資源の節約です。共通のものは外に追い出し、都度都度参照することで、配布するときにその分の容量を減らすことが出来ます。

元々、ディスク資源を有効に使うために作った仕組みなのに、同じディレクトリにコピーしていては元の木阿弥です。なので、GAC に登録して、共通して使うことが出来るようにしてあります。

ところで、UNIX の世界にも静的ライブラリと動的ライブラリはあります。しかし、うろ覚えですが(指摘求む)、UNIX の場合、動的ライブラリには、拡張子の後にバージョン番号が追加されています。コンパイル時に、実行時に結合するライブラリのバージョンを指定することが出来るんですね。

マイクロソフトは、なぜこれをマネしなかったのか。なぜ今頃になって、ようやくマネをしたのか。

簡単です。ディスク資源が足りなかったのです。ファイル名も、8.3の 11文字しか使えなかったし。NTFS でファイル名の制限をなくし、ディスク資源が潤沢になった今になって、既存の Win32 アプリケーションに影響しない .NET Framework という別の基盤を使って、ようやくマネすることが出来るようになったのです。

しかし、GAC に登録するためには、バージョンを明確にしなければなりません。あと、署名も必要。なぜでしょうか。

出所のはっきりしない DLL を使って、本当に大丈夫なんですか?誰かが、同じ名前で、同じ関数を持つ、違う動きをする DLL を作って、こっそり配布したら、どうなりますか?

あるいは。本当に、「修正した」DLL が、他のアプリケーションでも使えるのですか?インターフェイスが変わったりしていませんか?少し古い開発者なら、SUCCESS の定義が変わってあたふたした憶えがないですか(私はこのとき、まだ UNIXer だったので、人ごとでしたが)。0 と定義されていた SUCCESS を、1、つまり true と同じにしたんですね、確か。これ、SUCCESS で見ていれば、コンパイルし直すだけで済みますが、0 や 1 をハードコーディングしていたら・・・

もう一度尋ねます。こんな体験、したいですか?

投稿日時 : 2006年12月29日 19:08
コメント
  • # re: なぜみんな、地獄を見たがるの?
    hirotow@霧島
    Posted @ 2006/12/29 21:02
    UNIXの共有ライブラリの説明をhttp://www.linux.or.jp/JF/JFdocs/Program-Library-HOWTO/shared-libraries.htmlで見つけました
    あとご存知かもしれませんが、UNIXだと依存関係地獄というものがあります。
    最近はaptとかyumとか便利なものがありますが…
  • # Side-by-side を使う理由,Windows 2000 が死すべき理由,Web が既に死んでいる理由
    NyaRuRuの日記
    Posted @ 2006/12/29 21:31
    『何となく Blog by Jitta』より.DLL Hell へ向かうありがちな質問への回答. ところで、UNIX の世界にも静的ライブラリと動的ライブラリはあります。しかし、うろ覚えですが(指摘求む)、UNIX の場合、動的ライブラリには、拡張子の後にバージョン番号が追加されています
  • # re: なぜみんな、地獄を見たがるの?
    Jitta
    Posted @ 2006/12/31 21:10
    hirotow@霧島さん、コメントありがとうございます。
    NyaRuRuさん、トラックバックありがとうございます。

    > UNIXだと依存関係地獄というものがあります。
    これは、知りません。
     おそらく、今まで関わってきたシステムが、そのシステムのためにしか、コンピュータを使わないから、、、だと思います。
     今、お世話になっているところは、パッケージとも言えるソフトなので、DLL Hell にしろ、依存性地獄にしろ、気をつけないといけない・・・んだろうな。。。あまり実感無い(__;


    > DLL の Side-by-side (SxS) は別に .NET の専売特許というわけでもないですけどねぇ
    あれ?そういうふうに書いたつもりは、無いのですが。。。

    > Windows XP 以降の,manifest ファイルによる DLL のバージョン制御
    え!?出来るんですか?XP 用の、Win32 アプリは作っていないので。あ、C++ で MFC アプリを作るときになんか聞いてくるヤツ?あれか。
    今のプロジェクト、静的リンクしているので、全然、気にしてなかった(__;
  • # re: なぜみんな、地獄を見たがるの?
    NyaRuRu
    Posted @ 2007/01/01 12:09
    >> DLL の Side-by-side (SxS) は別に .NET の専売特許というわけでもないですけどねぇ
    >あれ?そういうふうに書いたつもりは、無いのですが。。。

    ああすみません.これは,

    >>>既存の Win32 アプリケーションに影響しない .NET Framework という別の基盤を使って、ようやくマネすることが出来るようになったのです。

    と書かれていた部分を受けてのものです..NET Framework は確かに SxS を意識して作られたフレームワークではありますが,かといって Win32 で SxS が利用できない / Microsoft に利用する気がないというわけでもないと.
    .manifest や Reg-Free COM はれっきとした .NET 以外の SxS テクノロジです.

    http://blogs.msdn.com/mgrier/archive/2005/06/18/430402.aspx
    にあるように,LoadLibrary の動作も XP 以前と以後で違うので,結構注意しないと嵌ります.
    以前日記で書いたものです.ご参考までに.
    http://d.hatena.ne.jp/NyaRuRu/20060715#p2
  • # re: なぜみんな、地獄を見たがるの?
    Jitta
    Posted @ 2007/01/02 13:57
    NyaRuRuさん:
    > Win32 で SxS が利用できない
     この部分は、これができたころには MS 製品を使っていなかったので、できないものだと思っていました。
     .manifest ファイルがあるので、「これ、なんに使うんだろう?」と思っていたのですが(中を見て、おおよそ見当はつけていましたが)、そのためのものだったのですね。
  • # re: なぜみんな、地獄を見たがるの?
    がる
    Posted @ 2007/01/09 1:51
    がるです。
    依存関連は、UNIXだとrpmが有名ですねぇ…多分(笑
    それはもぉ「蜘蛛の巣に絡めとられるような」素敵な感覚が味わえます。
    …だからrpm嫌いなのですが(苦笑

    ちなみに。知っている限りでは。UNIXだと、静的だろうが動的だろうが、ライブラリは全部、めぢゃぁまいなぁメンテナンスの各バージョン番号までがついてる実ファイルがあって。
    それをシンボリックリンクで…ってのが多いです。
    なので、最悪のケースでもそんなに苦労はしないですね。gccでコンパイルしなおせばいいだけなので。

    ただ…本気こいて基本的なもの以外は、ぶっちゃけ「コンパイル時に静的に縛るほうが」楽ではあるんですよね。
  • # re: なぜみんな、地獄を見たがるの?
    Jitta
    Posted @ 2007/01/10 19:45
    がるさん、コメントありがとうございます。

    > ぶっちゃけ「コンパイル時に静的に縛るほうが」楽ではある
    その為だと思うのですが、今関わっているものでは、静的にリンクしています。
    なんにしても、「他のアプリをインストールしたら動作がおかしくなった」とか、「アプリをインストールする順番によって動作が異なる」とかいうのは、避けたいわけで。
  • # re: なぜみんな、地獄を見たがるの?
    ちびまほうつかい
    Posted @ 2007/03/07 4:14
    最近プログラミングを始めた者です。

    すいませんがコマンドライン一発でマニフェストファイルを
    埋め込むような技は無いんでしょうか?

    たとえば、MyProg.exeとMyProg.exe.manifest
    にたいして

    > foo MyProg.exe MyProg.exe.manifest
    などと操作することにより統合できるなんていうことは
    無いんでしょうか?
  • # re: なぜみんな、地獄を見たがるの?
    Jitta
    Posted @ 2007/03/07 22:07
    ちびまほうつかいさん、こんにちは。

     ご質問は、「コンパイル(リンク)後の実行ファイルと、マニフェストの統合(埋め込み)」でしょうか。

     残念ながら、私は .NET から VisualStudio を触りだしたので、その辺は詳しくないのです。
     で、MSDN を「manifest 埋め込」(送りがなをつけないのがコツ)で検索して、ここを見つけました。
    http://www.atmarkit.co.jp/fdotnet/dotnettips/235embmanifest/embmanifest.html

     これは、コンパイル時に埋め込みます。そのほかのリソースもざっと目を通しましたが、リンク時に埋め込むようです。MSDN ではここ。
    http://msdn2.microsoft.com/ja-jp/library/ms235591(VS.80).aspx
  • # re: なぜみんな、地獄を見たがるの?
    ちびまほうつかい
    Posted @ 2007/03/08 23:43
    情報どうもありがとうございました。
  • # re: なぜみんな、地獄を見たがるの?
    凪瀬
    Posted @ 2008/06/16 14:13
    フェンスの存在を知っていても、フェンスが建てられている理由を知らなければ「邪魔だからなければいいのに」と思うだけなんですよね…。
    別に好き好んで地雷原を歩きたいわけではないと思うけども。
  • # re: なぜみんな、地獄を見たがるの?
    カオス
    Posted @ 2011/03/19 13:40
    Webアプリケーションについては、似たような問題として、ブラウザ非互換がありますよね。
    今まで問題の無かったものが、ブラウザのバージョンが変わった事により、表示や動作が変わってしまうというものです。
    やりたいことは変わらないのに、今なおアホ供が永遠に続く地獄を量産してますね。(笑)
  • # re: なぜみんな、地獄を見たがるの?
    Jitta
    Posted @ 2011/03/20 16:10
    > ブラウザのバージョンが変わった事により、表示や動作が変わってしまうというものです。

    ああ、目が痛い目が痛い。
    いや、IE6, 7 だけ、動作が違う困った問題に、組み込み Linux の大元が変更できない(期間的、スキル的問題)ので、蓋をしたところですねんorz orz orz
  • # My brother recommended I might like this blog. He was entirely right. This publish truly made my day. You cann't imagine simply how a lot time I had spent for this info! Thanks!
    My brother recommended I might like this blog. He
    Posted @ 2021/08/30 5:28
    My brother recommended I might like this blog. He was entirely right.
    This publish truly made my day. You cann't imagine
    simply how a lot time I had spent for this info! Thanks!
  • # My brother recommended I might like this blog. He was entirely right. This publish truly made my day. You cann't imagine simply how a lot time I had spent for this info! Thanks!
    My brother recommended I might like this blog. He
    Posted @ 2021/08/30 5:30
    My brother recommended I might like this blog. He was entirely right.
    This publish truly made my day. You cann't imagine
    simply how a lot time I had spent for this info! Thanks!
  • # My brother recommended I might like this blog. He was entirely right. This publish truly made my day. You cann't imagine simply how a lot time I had spent for this info! Thanks!
    My brother recommended I might like this blog. He
    Posted @ 2021/08/30 5:31
    My brother recommended I might like this blog. He was entirely right.
    This publish truly made my day. You cann't imagine
    simply how a lot time I had spent for this info! Thanks!
  • # My brother recommended I might like this blog. He was entirely right. This publish truly made my day. You cann't imagine simply how a lot time I had spent for this info! Thanks!
    My brother recommended I might like this blog. He
    Posted @ 2021/08/30 5:32
    My brother recommended I might like this blog. He was entirely right.
    This publish truly made my day. You cann't imagine
    simply how a lot time I had spent for this info! Thanks!
  • # Good web site you've got here.. It's difficult to find high-quality writing like yours nowadays. I seriously appreciate individuals like you! Take care!!
    Good web site you've got here.. It's difficult to
    Posted @ 2021/09/02 21:19
    Good web site you've got here.. It's difficult to find high-quality writing like yours
    nowadays. I seriously appreciate individuals like you!
    Take care!!
  • # This is my first time pay a visit at here and i am truly impressed to read all at single place.
    This is my first time pay a visit at here and i am
    Posted @ 2021/09/05 21:25
    This is my first time pay a visit at here and i am truly impressed to read
    all at single place.
  • # This is my first time pay a visit at here and i am truly impressed to read all at single place.
    This is my first time pay a visit at here and i am
    Posted @ 2021/09/05 21:26
    This is my first time pay a visit at here and i am truly impressed to read
    all at single place.
  • # This is my first time pay a visit at here and i am truly impressed to read all at single place.
    This is my first time pay a visit at here and i am
    Posted @ 2021/09/05 21:27
    This is my first time pay a visit at here and i am truly impressed to read
    all at single place.
  • # This is my first time pay a visit at here and i am truly impressed to read all at single place.
    This is my first time pay a visit at here and i am
    Posted @ 2021/09/05 21:28
    This is my first time pay a visit at here and i am truly impressed to read
    all at single place.
  • # Hey there! This is kind of off topic but I need some guidance from an established blog. Is it difficult to set up your own blog? I'm not very techincal but I can figure things out pretty quick. I'm thinking about making my own but I'm not sure where t
    Hey there! This is kind of off topic but I need so
    Posted @ 2021/10/26 1:45
    Hey there! This is kind of off topic but I need some guidance from an established blog.
    Is it difficult to set up your own blog? I'm not very techincal but I can figure things out pretty quick.
    I'm thinking about making my own but I'm not sure where to start.
    Do you have any points or suggestions? Appreciate it
  • # It's nearly impossible to find educated people in this particular topic, but you sound like you know what you're talking about! Thanks
    It's nearly impossible to find educated people in
    Posted @ 2021/12/15 4:45
    It's nearly impossible to find educated people
    in this particular topic, but you sound like you know what you're talking about!
    Thanks
  • # cheap essay papers q48rhx
    Charlosmox
    Posted @ 2022/09/03 18:16

    Nicely put, Appreciate it! https://definitionessays.com/ research paper buy online
  • # how to write an essay to get into college e31kcj
    Charlosmox
    Posted @ 2022/09/08 18:11

    Awesome information, Cheers. https://definitionessays.com/ how to write a formal essay
  • # college common application essay s89bpp
    Albertosed
    Posted @ 2023/02/10 18:12

    Wow quite a lot of excellent tips.
    https://essaywritingservicelinked.com/ alfie kohn homework myth
  • # phd writer i90vus
    Robertsaids
    Posted @ 2023/02/27 8:36

    Great knowledge. Cheers!
    buy a dissertation online https://dissertationwritingtops.com/ write my dissertation cheap
  • # english dissertations v310dy
    EugeneSib
    Posted @ 2023/03/06 11:53

    Awesome posts, Thanks.
    essay writing courses https://writingresearchtermpaperservice.com how to write an essay for college application https://ouressays.com
  • # buy essay online for cheap m11zlf
    Gregorysaipt
    Posted @ 2023/03/08 8:19

    Regards, I like this.
    help write an essay online https://helpwritingdissertation.com expert essay writers https://custompaperwritingservices.com
  • # trusted essay writing service l12gbw
    EugeneSib
    Posted @ 2023/03/10 22:31

    Nicely put. Thanks a lot!
    dissertation write up https://writingpaperforme.com dissertation topic https://helptowriteanessay.com
  • # phd thesis library r30xhe
    Gregorysaipt
    Posted @ 2023/03/11 1:31

    Amazing postings. Thanks a lot.
    best online essay writing service https://custompaperwritersservices.com how to write contrast essay https://dissertationwritingtops.com
  • # university thesis z264uh
    Gregorysaipt
    Posted @ 2023/03/11 23:14

    You've made your point quite effectively!.
    how to write a good transfer essay https://bestonlinepaperwritingservices.com essay help toronto https://dissertationwritingtops.com
  • # finance dissertations b229xw
    EugeneSib
    Posted @ 2023/03/12 19:05

    Excellent postings. Kudos.
    who will write my essay for me https://phdthesisdissertation.com writing a expository essay https://buyanessayscheaponline.com
  • # college essay cover page r65lyg
    Gregorysaipt
    Posted @ 2023/03/12 20:57

    Really tons of amazing facts!
    college common application essay https://service-essay.com buy a dissertation online https://domycollegehomeworkforme.com
  • # best custom essay d63dqe
    Gregorysaipt
    Posted @ 2023/03/13 18:44

    Valuable posts. Cheers.
    online essay writing https://homeworkcourseworkhelps.com write persuasive essay https://essaypromaster.com
  • # why college essay v217mg
    EugeneSib
    Posted @ 2023/03/14 0:31

    With thanks, An abundance of forum posts.
    college essay editing services https://helpmedomyxyzhomework.com analysis dissertation https://quality-essays.com
  • # The plugins developed for WordPress
    Justas
    Posted @ 2023/05/09 23:16
    The plugins developed for WordPress serve to enhance the features and functions of a WordPress website, allowing you to build your awesome and functional site https://t.me/wpigaming/648 Customise WordPress with powerful, professional and intuitive fields.
タイトル
名前
Url
コメント