Assembly binding / codebase redirect from GAC

G

Guest

Hi,

I am trying to prevent an assembly being loaded from GAC and instead want it
loaded from the application's base directory. However, the assembly always
gets loaded from GAC. How to have it loaded from the application directory?

I read about the bindingRedirect trick in the NG, however, specifying
bindingRedirect did not work for me. Also, MSDN library states that
"Application configuration files can have a codebase setting without
redirecting the assembly version".

Here's my app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="BindingTestDLL"
publicKeyToken="8662c4c21e8ecd7e"
culture="neutral" />
<codeBase version="1.0.2096.38102"

href="file:///D:/Develop/Test/FusionTest/FusionTest/BindingTest/bin/Debug/BindingTestDLL.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
 
K

Kevin Yu [MSFT]

Hi Ruslan,

As far as I know, .NET app will always look for the assembly in the GAC if
it is a strong named assembly. Does the two assemblies have the same
version number? If so, the app will always use the one in GAC. But if the
version number is different, and you're using binding redirection, you can
redirect it to your local folder.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Hi Kevin,

No, strongly named assemblies can be loaded from any directory. According to
MSDN, looking for an assembly in GAC occurs after version resolution (which
includes examination of app.config), but prior to probing. Accoring to the
following post, binding redirect together with codebase can result in loading
an assembly from the specified path:
http://groups.google.co.uk/group/mi...bindingRedirect&rnum=4&hl=ru#e1c5747a81e6da1c

However, that did not work in my tests. Taking into account the date of the
posting, that can be just an older version of .NET framework.

So, because GAC is checked always first, there can be no way to load an
assembly present in GAC from any other place. Why I want that is because I
have an app misworking because it apparently loads assemblies with the same
name and version number installed to GAC by another application, which
(assemblies) differ from those located in the app base directory.
 
K

Kevin Yu [MSFT]

Hi Ruslan,

As far as I know, binding rediretion can only redirect to a strong named
assembly with different signatures. If you're using a strong named
assembly, try to give a different version number, assembly name or sign
with a different key. You can re-add reference to the assembly in your app.
If the signature is different the original assembly in the GAC is ignored.
If signature is the same, the one in the GAC will always be used.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Hi Kevin,

Thanks. Fortunately, the assemblies in question are our proprietary, so I
have sources for them, so I just changed the version number. (Actually, the
good practice would be to change the version number when sources had changed,
but that was out of my control.) Otherwise, I think I would have trouble.
Because trying to resign an assembly which is already signed (not
delay-signed) by another key appears impossible. If I understand right, this
could result in inability of xcopy-deployment of the app. I'd be happy to
know comments on this from sombody in the Fusion team. Can you bring some of
them here, Kevin?
 
K

Kevin Yu [MSFT]

Hi Ruslan,

Sorry that I don't know anyone in the Fusion team. But as far as I know,
changing the version number to make the assembly signature different from
the original one is enough. We needn't re-sign it.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Hi Kevin,

Sure, that's enough. Re-signing would be only needed if there was no
sources. Thanks for paying attention to this.
 
K

Kevin Yu [MSFT]

You're welcome.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top