none
.Net 4.0 Binding Redirect C# RRS feed

  • Question

  • Hi, I have an application which places a dll in the GAC.

    The dll references certain system files related to Media Center, the referenced version is on Windows 7 which is 6.1 and has a strong name. When I install the application on Windows 8.1 the dll still works although I know the file version is 6.3 and I have no redirects in place.

    So my question, is the dll automatically choosing the newer version and ignoring the referenced version number. I should also mention that Specific Version is set to false, although with strong named assemblies I didn't think this had any affect.

    Also if this shouldn't choose the newer version how do I set redirects for a dll so I don't have to create a new application for each version.

    Thanks in advance



    Sunday, October 12, 2014 11:59 AM

Answers

  • >>So my question, is the dll automatically choosing the newer version and ignoring the referenced version number

    Yes, since SpecificVersion is set to false, the latest available DLL will be used.

    Please refer to the following page on MSDN for more information about how to redirect compile-time binding references to .NET Framework assemblies, third-party assemblies, or your own app's assemblies: http://msdn.microsoft.com/en-us/library/7wd6ex19(v=vs.110).aspx

    Please remember to mark any helpful posts as answer and/or helpful.

    • Marked as answer by Kevin-Andrews Sunday, October 12, 2014 1:24 PM
    Sunday, October 12, 2014 12:14 PM
  • So the fact that the referenced assembly has a strong name wouldn't make any difference?

    Not if the SpecificVersion is set to false. The 6.1 and 6.3 assemblies will both have the same public key but just different version numbers and, as I said, the latest available DLL with that public key token will be used when the SpecificVersion property of the reference is set to false.
    • Marked as answer by Kevin-Andrews Sunday, October 12, 2014 1:34 PM
    Sunday, October 12, 2014 1:26 PM

All replies

  • >>So my question, is the dll automatically choosing the newer version and ignoring the referenced version number

    Yes, since SpecificVersion is set to false, the latest available DLL will be used.

    Please refer to the following page on MSDN for more information about how to redirect compile-time binding references to .NET Framework assemblies, third-party assemblies, or your own app's assemblies: http://msdn.microsoft.com/en-us/library/7wd6ex19(v=vs.110).aspx

    Please remember to mark any helpful posts as answer and/or helpful.

    • Marked as answer by Kevin-Andrews Sunday, October 12, 2014 1:24 PM
    Sunday, October 12, 2014 12:14 PM
  • Yes, since SpecificVersion is set to false, the latest available DLL will be used.

    Thanks

    So the fact that the referenced assembly has a strong name wouldn't make any difference?

    Thanks for the link, I have used the app.config method on desktop apps but unsure as to method used for class libraries. Having said that, as its choosing the newer version I guess its not needed.

    Thanks again.


    Sunday, October 12, 2014 1:23 PM
  • So the fact that the referenced assembly has a strong name wouldn't make any difference?

    Not if the SpecificVersion is set to false. The 6.1 and 6.3 assemblies will both have the same public key but just different version numbers and, as I said, the latest available DLL with that public key token will be used when the SpecificVersion property of the reference is set to false.
    • Marked as answer by Kevin-Andrews Sunday, October 12, 2014 1:34 PM
    Sunday, October 12, 2014 1:26 PM
  • That's excellent, saves a lot of headaches.

    Thanks

    Sunday, October 12, 2014 1:35 PM
  • Not if the SpecificVersion is set to false. The 6.1 and 6.3 assemblies will both have the same public key but just different version numbers and, as I said, the latest available DLL with that public key token will be used when the SpecificVersion property of the reference is set to false.

    Just out of interest, the dll which is part of a larger application uses the newer version of the referenced dll. However the main wpf application which runs separately also references the system dll's but this doesn't use the newer version instead this requires the redirects in the app.config or it errors stating file not found.

    Is there a reason why the application doesn't use the newer version but the dll does.?

    The main application also has SpecificVersion set to false.

    Thanks

    Sunday, October 12, 2014 4:04 PM
  • Did you recompile the WPF application? SpecificVersion=false simply means "ignore the version of the assembly" when building, i.e. it is telling Visual Studio that it should accept a different version of the same DLL when the the dll reference is not available. It has no effect on the runtime version resolution of the referenced assembly.

    If you want to "change" the reference without rebuilding your application, you should use redirects in app.config.

    But please remember to post any new question you may have in a new thread.

    Sunday, October 12, 2014 7:37 PM
  • Thanks, I've removed the reference to vs2012 as it actually relates to the application after installation.

    OK here's the scenario, I've installed the application on Windows 8.1. I run Media Center and select an item on the menu, this activates the dll in the GAC and the dll runs perfectly without an app.config although it was built against reference 6.1 it uses 6.3.

    The main application also references 6.1 with the redirects in the app.config it uses 6.3 without any issues. If I remove the app.config it fails.

    So how is the dll using a newer version of the reference but the main application won't without the redirects in the app.config.

    The problem is I don't want to release the application if the behaviour of the dll is not as it should be.

    Sunday, October 12, 2014 9:44 PM