Error adding policy file to GAC

这一生的挚爱 提交于 2019-12-13 03:49:44

问题


I'm trying to add a publisher policy file to the gac as per this thread but I'm having problems when I try and add the file on my test server.

I get "A module specified in the manifest of assembly 'policy.3.0.assemblyname.dll' could not be found"

My policy file looks like this:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="*assemblyname*"
                          publicKeyToken="7a19eec6f55e2f84"
                          culture="neutral" />
        <bindingRedirect oldVersion="3.0.0.0"
                         newVersion="3.0.0.1"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Please help!

Thanks

Ben


I've recreated the problem from scratch with a new assembly that has no dependancies (apart from the defaults) itself - all works fine on my local development machine (and redirects fine too) but gives the same error adding the policy file to the GAC on the server!

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="TestAsm"
                          publicKeyToken="5f55456fdcc9b528"
                          culture="neutral" />
        <bindingRedirect oldVersion="3.0.0.0"
                         newVersion="3.0.0.1"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

linked in the following way

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\al.exe /link:PublisherPolicy.xml /out:policy.3.0.TestAsm.dll /keyfile:..\..\key.snk /version:3.0.0.0
pause

Please help!


回答1:


Wow - ok got it.

I should have paid more attention to exactly what this meant

(MSDN) How to: Create a Publisher Policy

Important Note: The publisher policy assembly cannot be added to the global assembly cache unless the original publisher policy file is located in the same directory as the assembly .

That requirement is, frankly, so bizarre that it didn't register. The original policy file, that was compiled into the assembly i'm trying to add to the gac, has to be in the same folder as the policy assembly as you add the policy assembly.




回答2:


Ok...just want to check some basics....

You definitely have got both versions of the dependent assembly installed to GAC?

And have you verified that the version numbers in the [assembly: AssemblyVersion()] attribute are correct.

And you did use [assembly: AssemblyVersion()] and NOT [assembly: AssemblyFileVersion("1.0.0.1")].

Update: My mistake, you only need the latest version of the assembly in the GAC. I just tried that here and it works. My only other thoughts are to check that the public key tokens are the same and that you've not misspelled the assembly name.

Also when you generate the policy file make sure you use the /version switch in the assembly linker to explicitly set the version number to 3.0.0.0 AND don't specify the /platform switch. e.g.

al.exe /link:assembly.config /out:policy.3.0.assembly.dll 
         /keyfile:mykey.snk /version:3.0.0.0



回答3:


To add policy assemblies to the GAC using Wise, you do the same thing as you do to add the assembly the policy is for. So you add the policy assembly to the "Global Assembly Cache" in Wise, and as long as you have the policy file (.config) in the same location on the machine, Wise will automatically add it to GAC as well.



来源:https://stackoverflow.com/questions/302239/error-adding-policy-file-to-gac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!