Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
491 views
in Technique[技术] by (71.8m points)

.net - How to make Publisher Policy file redirect assembly request

I have created a common library at work, and it is installed in the GAC on our test server. I've recently updated it and I want all of our applications to be using the update. I created a publisher policy assembly and installed it in the GAC along with the update, but when a web app loads Leggett.Common, 1.0.0.0, it isn't redirected to Leggett.Common, 1.1.0.0.

I have the common assembly (there are actually five, but lets keep it simple) on a network drive, I created the publisher policy xml file there next to it and then used al.exe to create the publisher policy assembly in the same folder. After that I put the updated assembly in the GAC and then put the publisher policy assembly in the GAC.

The common assembly is 'Leggett.Common.dll', the publisher policy file is '1.1.Leggett.Common.policy', and the publisher policy assembly is 'policy.1.1.Leggett.Common.dll'.

The XML for the publisher policy file looks like the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Leggett.Common"
                                  publicKeyToken="32cd8f1a53a4c744"
                                  culture="neutral" />
                <bindingRedirect oldVersion="1.0.0.0"
                                 newVersion="1.1.0.0"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

What am I doing wrong?

Clarification
I'm testing this on my local dev machine since developers don't have access to the test server.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ok...at a stab...

1 - have you tried using the Assembly Binding Log Viewer (Fuslogvw.exe) to see what assembly binding is taking place?

You can find it in:

C:Program FilesMicrosoft SDKsWindowsv6.0ABinFUSLOGVW.exe (with VS2008 installed).

2 - "I have the common assembly (there are actually five, but lets keep it simple) on a network drive," - Are both assemblies resident on the network drive?

Update: Ok...if the new assembly is on a network drive there are probably some trust issues. Can you deploy the new assemblies to a local drive on the server then re-install to the GAC?

Update2: I know..stupid stuff....you have definitely got the publicKeyToken and version number correct? i.e. Your AssemblyVersion attribute for the new assembly is definitely 1.1.0.0 and the public key token is identical (in the GAC)?

Have you tried removing the culture attribue?

Update3: Hi Max....Can you paste the exact publisher policy file you used? Also...remember that if you are redirecting from a 1.0 to a higher versioned assembly, the publisher policy name must be named using the major.minor version of the assembly you're redirecting from. So in your case the publisher policy should be named 'policy.1.0.Leggett.Common.dll'. I notice you've named it 'policy.1.1.Leggett.Common.dll' which may be the reason it's not working.

And finally you must make sure you sign the publisher policy with the same key as used by the 1.0 and 1.1 assemblies.

I built a couple of DLL's and dropped them in the GAC then used a console app in VS to test and it does work :)

Update4: Hi Max, something I never thought about. When you created the publisher policy file, did you specify the platform? Try building it with:

al /link:1.1.Leggett.Common.policy /out:policy.1.0.Leggett.Common.dll /keyfile: /version:1.0.0.0

Leave out the /platform switch and explicitly specify the version number.

Cheers
Kev


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...