Can';无法获取.NET策略DLL以将应用程序重定向到较新的程序集

Can';无法获取.NET策略DLL以将应用程序重定向到较新的程序集,.net,binding,gac,policyfiles,.net,Binding,Gac,Policyfiles,我在技术支持方面的背景很可能导致我在这篇文章中放了太多的信息,导致没有人对阅读感兴趣,但是我知道,信息越多越好 关于程序集绑定和重定向,我缺少一些非常基本的东西。我正在尝试创建一个策略DLL,以将根据我的程序集的旧版本编译的应用程序重定向到最新版本。我所做的一切似乎都不管用。我在下面概述了我采取的步骤。我使用的不是Visual Studio,而是.NET Framework和Windows SDK附带的命令行工具。有人能告诉我,在步骤11中,当我运行针对我的程序集v1.0.0版本编译的应用程序时

我在技术支持方面的背景很可能导致我在这篇文章中放了太多的信息,导致没有人对阅读感兴趣,但是我知道,信息越多越好

关于程序集绑定和重定向,我缺少一些非常基本的东西。我正在尝试创建一个策略DLL,以将根据我的程序集的旧版本编译的应用程序重定向到最新版本。我所做的一切似乎都不管用。我在下面概述了我采取的步骤。我使用的不是Visual Studio,而是.NET Framework和Windows SDK附带的命令行工具。有人能告诉我,在步骤11中,当我运行针对我的程序集v1.0.0版本编译的应用程序时,为什么应用程序没有重定向到GAC中注册的v2.0.0程序集

当您按照我所做的操作进行操作时,您通常需要注意我在其中执行命令的目录

如果你能指点一下我应该读的TFM,我会非常乐意得到一个RTFM的答案

提前感谢,, 注册

第一步:创建一个密钥对来强命名我的程序集。 第二步:创建版本为v1.0.0的程序集 步骤三:为v1.0.0程序集创建策略DLL 步骤五:创建使用新v1.0.0程序集的应用程序 步骤六:创建v2.0.0 stack.exchange.rdomarat.dll程序集 步骤七:为v2.0.0程序集创建策略DLL 步骤九:创建使用新v2.0.0程序集的应用程序 第十步:从GAC注销所有内容,并确认两个应用都不起作用 第十一步:重新注册v2.0.0程序集,两个应用程序现在都可以工作了
我认为这个问题可以短得多

针对强命名程序集进行编译时,需要在GAC中注册程序集的确切版本。根据V1.0.0.0程序集编译的应用程序要求注册/安装程序集V1.0.0.0。根据V2.0.0.0程序集编译的应用程序需要注册/安装V2.0.0.0。如果你想运行这两个应用程序,那么你需要安装和注册这两个版本-据我所知,没有异常或替换强名称程序集

这一点的关键在于,如果在将来某个时候更新程序集版本(即:),那么为一个版本编写的代码可以继续运行,而不必担心会中断—它将继续与较旧版本的程序集一起运行,直到开发人员开始更新基础应用程序以针对较新版本运行

在重定向程序集时:


我认为这个问题本可以短得多

针对强命名程序集进行编译时,需要在GAC中注册程序集的确切版本。根据V1.0.0.0程序集编译的应用程序要求注册/安装程序集V1.0.0.0。根据V2.0.0.0程序集编译的应用程序需要注册/安装V2.0.0.0。如果你想运行这两个应用程序,那么你需要安装和注册这两个版本-据我所知,没有异常或替换强名称程序集

这一点的关键在于,如果在将来某个时候更新程序集版本(即:),那么为一个版本编写的代码可以继续运行,而不必担心会中断—它将继续与较旧版本的程序集一起运行,直到开发人员开始更新基础应用程序以针对较新版本运行

在重定向程序集时:


从第一天开始,我的整个问题就是缺少双引号:

文化=中性

我将.config文件更改为

文化=“中立”


每件事都很有魅力。程序集绑定调试输出日志中的一个错误表明配置文件的XML中存在解析错误,这将非常方便,可能会节省我两天的时间。哦,好吧。

从第一天开始,我的整个问题就是缺少双引号:

文化=中性

我将.config文件更改为

文化=“中立”


每件事都很有魅力。程序集绑定调试输出日志中的一个错误表明配置文件的XML中存在解析错误,这将非常方便,可能会节省我两天的时间。哦,好吧。

-1:只有有人阅读了更多的信息才会更好。-1:只有有人阅读了更多的信息才会更好。MSDN上标题为的页面似乎与您在第二段中的评论不一致。如果有人根据我的程序集的v1.0.0.0编译了他们的应用程序,我应该能够部署我的程序集的v2.0.0.0和发布者策略,并告诉根据v1.0.0.0编译的应用程序使用新的v2.0.0.0程序集。与我上面提到的页面上的其他示例相比,我看不出我在示例中做的有什么不同。您似乎与修订号不一致。。。也许问题就在那里?(即:1.0.0对1.0.0.0)很好。Gacutil告诉我它正在从GAC中删除文件,GAC的版本是1.0.0.0,而不是像我在配置文件和assemblyInfo.cs文件中指定的1.0.0。唉,我从1.0.0->1.0.0.0和2.0.0->2.0.0.0更改了所有文件中的引用,并且存在相同的症状。从MSDN:程序集的每个主版本和次版本都有自己的发布者策略文件。例如,从版本1.1.2.222到1.1.3.000以及从版本1.1.2.321到版本1.1.3.000的重定向都会进入同一个文件。但是,从版本2.0.0.999重定向到版本3.0.0.000会进入另一个文件。我的意思是,我不认为您可以指定跨越主版本和次版本的“旧版本”。您可以执行“1.0.0.0-1.0.9999.9999”,但对于其他主版本和次版本,您需要单独重定向。也许…爸爸
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
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.
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.
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
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
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.
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.
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
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
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.
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.