1

私のテクニカルサポートの経歴により、この投稿にあまりにも多くの情報を入れてしまい、誰もそれを読むことに興味がなくなった可能性がありますが、私見では、情報が多いほど良いです。

アセンブリのバインドとリダイレクトについて、私が見逃している非常に基本的で基本的なものがあります。古いバージョンのアセンブリに対してコンパイルされたアプリケーションを最新バージョンにリダイレクトするポリシーDLLを作成しようとしています。私がすることは何もうまくいかないようです。以下に、実行する手順の概要を示します。Visual Studioを使用していませんが、.NETFrameworkとWindowsSDKに含まれているコマンドラインツールのみを使用しています。ステップ11で、アセンブリのv1.0.0バージョンに対してコンパイルされたアプリケーションを実行すると、アプリケーションがGACに登録されているv2.0.0アセンブリにリダイレクトされない理由を誰かに教えてもらえますか?

私が行ったことを実行するとき、コマンドを実行したディレクトリに注意する必要があります。

私が読むことになっているTFMを指摘するほど親切にしていただければ、RTFMの回答に満足しています。

よろしくお願いします、Reg

ステップ1:キーペアを作成して、アセンブリに厳密な名前を付けます。

c:\stackexchangetest> sn -k stackTest.snk
Microsoft (R) .NET Framework Strong Name Utility  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Key pair written to stackTest.snk

c:\stackexchangetest> sn -p stackTest.snk publicStackTest.snk
Microsoft (R) .NET Framework Strong Name Utility  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Public key written to publicStackTest.snk

c:\stackexchangetest> sn -tp publicStackTest.snk
Microsoft (R) .NET Framework Strong Name Utility  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Public key is
002400000480000094000000060200000024000052534131000400000100010079ba0ab991ceda
d7ba4a767d55889a6cd0eafc9bc15c394620b61c02f4c1112dd9e348cbb4826775c72164ac8552
f9b751b1a1dd71874c04b24221f00f4ee8c2971f3ac8b6b381b26d39cbd3347e773bf08e9af838
6d7f317592951a4985e2c187288d037d5af2f62cce2e4dc700d0d00feb4c095df5d12c9a0908dc
8606cdad

Public key token is 6dfd37060fccec62

ステップ2:バージョンがv1.0.0のアセンブリを作成します

c:\stackexchangetest\1.0.0> type StackTest.cs
using System;

namespace stack.exchange.rdomarat
{
    public class stackTest
    {
        public static String getVersion()
        {
            return( "1.0.0" );
        }
    }
}

c:\stackexchangetest\1.0.0> type AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("stack.exchange.rdomarat")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("StackExchange")]
[assembly: AssemblyProduct("rdomarat")]
[assembly: AssemblyCopyright("Copyright 2012")]
[assembly: AssemblyTrademark("rdomarat")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("a3d17815-97f5-4e56-803c-06f652a23369")]
[assembly: AssemblyVersion( "1.0.0" )]

c:\stackexchangetest\1.0.0> csc /out:stack.exchange.rdomarat.dll /keyfile:../stackTest.snk /debug /w:4 /t:library AssemblyInfo.cs StackTest.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.5420
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

ステップ3:v1.0.0アセンブリのポリシーDLLを作成する

c:\stackexchangetest\1.0.0> type stack.exchange.rdomarat.config
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="stack.exchange.rdomarat"
                        publicKeyToken="6dfd37060fccec62"
                        culture=neutral
                    />
                <bindingRedirect oldVersion="1.0.0-1.0.0"
                        newVersion="1.0.0"
                    />
            </dependentAssembly>
        </assemblyBinding>
    </runtime> 
</configuration>

c:\stackexchangetest\1.0.0> al.exe /version:1.0.0 /link:stack.exchange.rdomarat.config /out:policy.1.0.stack.exchange.rdomarat.dll /keyfile:../stackTest.snk /description:"Policy file" /title:"Policy file" /company:"StackExchange" /copyright:"Copyright 2012" /trademark:"rdomarat" /product:"rdomarat"
Microsoft (R) Assembly Linker version 9.0.30729.1
Copyright (C) Microsoft Corporation. All rights reserved.

ステップ4:2つのアセンブリをGACに登録します

c:\stackexchangetest\1.0.0> gacutil -u stack.exchange.rdomarat
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

No assemblies found matching: stack.exchange.rdomarat
Number of assemblies uninstalled = 0
Number of failures = 0

c:\stackexchangetest\1.0.0> gacutil -u policy.1.0.stack.exchange.rdomarat
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

No assemblies found matching: policy.1.0.stack.exchange.rdomarat
Number of assemblies uninstalled = 0
Number of failures = 0

c:\stackexchangetest\1.0.0> gacutil -i stack.exchange.rdomarat.dll
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly successfully added to the cache

c:\stackexchangetest\1.0.0> gacutil -i policy.1.0.stack.exchange.rdomarat.dll
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly successfully added to the cache

ステップ5:新しいv1.0.0アセンブリを使用するアプリケーションを作成します

c:\stackexchangetest\stackapp\1.0.0> type stackApp.cs
using System;
using stack.exchange.rdomarat;

public class StackApp
{
   public static void Main()
   {
       String s1;
       s1 = stackTest.getVersion();
       Console.WriteLine("Hello " + s1);
   }
}

c:\stackexchangetest\stackapp\1.0.0> csc /out:StackApp.exe /target:exe /reference:..\..\1.0.0\stack.exchange.rdomarat.dll StackApp.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.5420
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

c:\stackexchangetest\stackapp\1.0.0> stackapp
Hello 1.0.0

ステップ6:v2.0.0stack.exchange.rdomarat.dllアセンブリを作成します

c:\stackexchangetest\2.0.0> type StackTest.cs
using System;

namespace stack.exchange.rdomarat
{
    public class stackTest
    {
        public static String getVersion()
        {
            return( "2.0.0" );
        }
    }
}

c:\stackexchangetest\2.0.0> type AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("stack.exchange.rdomarat")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("StackExchange")]
[assembly: AssemblyProduct("rdomarat")]
[assembly: AssemblyCopyright("Copyright 2012")]
[assembly: AssemblyTrademark("rdomarat")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("a3d17815-97f5-4e56-803c-06f652a23369")]
[assembly: AssemblyVersion( "2.0.0" )]

c:\stackexchangetest\2.0.0> csc /out:stack.exchange.rdomarat.dll /keyfile:../stackTest.snk /debug /w:4 /t:library AssemblyInfo.cs StackTest.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.5420
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

ステップ7:v2.0.0アセンブリのポリシーDLLを作成する

c:\stackexchangetest\2.0.0> type stack.exchange.rdomarat.config
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="stack.exchange.rdomarat"
                        publicKeyToken="6dfd37060fccec62"
                        culture=neutral
                    />
                <bindingRedirect oldVersion="1.0.0-2.0.0"
                        newVersion="2.0.0"
                    />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

c:\stackexchangetest\2.0.0> al.exe /version:2.0.0 /link:stack.exchange.rdomarat.config /out:policy.2.0.stack.exchange.rdomarat.dll /keyfile:../stackTest.snk /description:"Policy file" /title:"Policy file" /company:"StackExchange" /copyright:"Copyright 2012" /trademark:"rdomarat" /product:"rdomarat"
Microsoft (R) Assembly Linker version 9.0.30729.1
Copyright (C) Microsoft Corporation. All rights reserved.

ステップ8:2つのv2.0.0アセンブリをGACに登録します

c:\stackexchangetest\2.0.0> gacutil -u policy.2.0.stack.exchange.rdomarat
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

No assemblies found matching: policy.2.0.stack.exchange.rdomarat
Number of assemblies uninstalled = 0
Number of failures = 0

c:\stackexchangetest\2.0.0> gacutil -i stack.exchange.rdomarat.dll
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly successfully added to the cache

c:\stackexchangetest\2.0.0> gacutil -i policy.2.0.stack.exchange.rdomarat.dll
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly successfully added to the cache

ステップ9:新しいv2.0.0アセンブリを使用するアプリケーションを作成します

c:\stackexchangetest\stackapp\2.0.0> type stackApp.cs
using System;
using stack.exchange.rdomarat;

public class StackApp
{
   public static void Main()
   {
       String s1;
       s1 = stackTest.getVersion();
       Console.WriteLine("Hello " + s1);
   }
}

c:\stackexchangetest\stackapp\2.0.0> csc /out:StackApp.exe /target:exe /reference:..\..\2.0.0\stack.exchange.rdomarat.dll StackApp.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.5420
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

c:\stackexchangetest\stackapp\2.0.0> StackApp.exe
Hello 2.0.0

ステップ10:GACからすべての登録を解除し、どちらのアプリも機能しないことを確認します

c:\stackexchangetest\stackapp\2.0.0> gacutil -u policy.2.0.stack.exchange.rdomarat
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly: policy.2.0.stack.exchange.rdomarat, Version=2.0.0.0, Culture=neutral,PublicKeyToken=6dfd37060fccec62, processorArchitecture=MSIL
Uninstalled: policy.2.0.stack.exchange.rdomarat, Version=2.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62, processorArchitecture=MSIL
Number of assemblies uninstalled = 1
Number of failures = 0

c:\stackexchangetest\stackapp\2.0.0> gacutil -u policy.1.0.stack.exchange.rdomarat
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly: policy.1.0.stack.exchange.rdomarat, Version=1.0.0.0, Culture=neutral,PublicKeyToken=6dfd37060fccec62, processorArchitecture=MSIL
Uninstalled: policy.1.0.stack.exchange.rdomarat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62, processorArchitecture=MSIL
Number of assemblies uninstalled = 1
Number of failures = 0

c:\stackexchangetest\stackapp\2.0.0> gacutil -u stack.exchange.rdomarat
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly: stack.exchange.rdomarat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62, processorArchitecture=MSIL
Uninstalled: stack.exchange.rdomarat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62, processorArchitecture=MSIL

Assembly: stack.exchange.rdomarat, Version=2.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62, processorArchitecture=MSIL
Uninstalled: stack.exchange.rdomarat, Version=2.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62, processorArchitecture=MSIL
Number of assemblies uninstalled = 2
Number of failures = 0

c:\stackexchangetest\stackapp\1.0.0> StackApp.exe
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'stack.exchange.rdomarat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62' or one of its dependencies. The system cannot find the file specified.
File name: 'stack.exchange.rdomarat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62' at StackApp.Main()

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Running under executable  c:\StackExchangeTest\StackApp\1.0.0\StackApp.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = SYBASE\rdomarat
LOG: DisplayName = stack.exchange.rdomarat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62 (Fully-specified)
LOG: Appbase = file:///C:/Users/rdomarat/Documents/Issues/111205_mlclient_policy/StackExchangeTest/StackApp/1.0.0/
LOG: Initial PrivatePath = NULL 
Calling assembly : StackApp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config.
LOG: Post-policy reference: stack.exchange.rdomarat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62
LOG: The same bind was seen before, and was failed with hr = 0x80070002.

c:\stackexchangetest\stackapp\2.0.0> StackApp.exe
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'stack.exchange.rdomarat, Version=2.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62' or one of its dependencies. The system cannot find the file specified.
File name: 'stack.exchange.rdomarat, Version=2.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62' at StackApp.Main()

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Running under executable  c:\StackExchangeTest\StackApp\2.0.0\StackApp.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = SYBASE\rdomarat
LOG: DisplayName = stack.exchange.rdomarat, Version=2.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62 (Fully-specified)
LOG: Appbase = file:///C:/Users/rdomarat/Documents/Issues/111205_mlclient_policy/StackExchangeTest/StackApp/2.0.0/
LOG: Initial PrivatePath = NULL
Calling assembly : StackApp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config.
LOG: Post-policy reference: stack.exchange.rdomarat, Version=2.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62
LOG: The same bind was seen before, and was failed with hr = 0x80070002.

ステップ11:v2.0.0アセンブリを再登録します。これで、両方のアプリケーションが機能するはずです。

c:\stackexchangetest\2.0.0> gacutil -i stack.exchange.rdomarat.dll
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly successfully added to the cache

c:\stackexchangetest\2.0.0> gacutil -i policy.2.0.stack.exchange.rdomarat.dll
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly successfully added to the cache

c:\stackexchangetest\stackapp\2.0.0> StackApp.exe
Hello 2.0.0

c:\stackexchangetest\stackapp\1.0.0> StackApp.exe
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'stack.exchange.rdomarat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62' or one of its dependencies. The system cannot find the file specified.
File name: 'stack.exchange.rdomarat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62' at StackApp.Main()

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Running under executable  c:\StackExchangeTest\StackApp\1.0.0\StackApp.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = SYBASE\rdomarat
LOG: DisplayName = stack.exchange.rdomarat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62 (Fully-specified)
LOG: Appbase = file:///C:/Users/rdomarat/Documents/Issues/111205_mlclient_policy/StackExchangeTest/StackApp/1.0.0/
LOG: Initial PrivatePath = NULL
Calling assembly : StackApp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config.
LOG: Post-policy reference: stack.exchange.rdomarat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6dfd37060fccec62
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
4

2 に答える 2

1

初日からの私の全体的な問題は、周りに二重引用符がないことでした:

文化=中立

.configファイルを次のように変更します

culture = "neutral"

そして、すべてが魅力のように機能しました。構成ファイルのXMLの解析エラーを示すアセンブリバインディングデバッグアウトログログのエラーは便利であり、2日節約できた可能性があります。しかたがない。

于 2012-02-10T20:12:14.717 に答える
0

この質問はもっと短いかもしれないと思います。

厳密に名前が付けられたアセンブリに対してコンパイルする場合は、アセンブリの正確なバージョンをGACに登録する必要があります。V1.0.0.0アセンブリに対してコンパイルされたアプリでは、アセンブリV1.0.0.0を登録/インストールする必要があります。V2.0.0.0アセンブリに対してコンパイルされたアプリでは、V2.0.0.0を登録/インストールする必要があります。両方のアプリを実行する場合は、両方のバージョンをインストールして登録する必要があります。私が知る限り、例外や、厳密に名前が付けられたアセンブリによる置換はありません。

これの要点は、あるバージョン用に記述されたコードは、アセンブリバージョンが将来のある時点で更新された場合(つまり、dll hell)、壊れることを恐れずに実行し続けることができるということです-古いバージョンの開発者が新しいバージョンに対して実行するようにベースアプリケーションを更新するまでのアセンブリ。

アセンブリのリダイレクトについて:

http://msdn.microsoft.com/en-us/library/7wd6ex19%28v=vs.85%29.aspx

于 2012-01-31T19:03:32.880 に答える