Avoiding configuration pitfalls with incompatible copies of Enterprise Library

Source: Internet
Author: User

when you install Enterprise Library 3.0, you actually get two distinct copies of the library. one copy is in the form of pre-compiled binaries-by default these get installed to "C: \ Program Files \ microsoft Enteprise library 3.0-release L 2007 \ bin ". the other copy is in the form of source code, which by default will be compiled and the Assemblies coped to "C: \ entlib3src \ app blocks \ bin ".

while both copies of Enterprise Library contain identical code, there is one critical difference: the pre-compiled binaries are strong-named (with a Microsoft key that we do not ship), and the Assemblies compiled from the source code are not initially strong-named. so as far. net is concerned, these two sets of assemblies are completely different and completely incompatible with one another. this is standard. net behavior, and cocould cause problems with previous versions of entlib (and your own projects) if you keep multiple copies with different strong-name identities around-but since for the first time we are shipping both copies in the same "box ", this is understandably causing some confusion for quite a few people.

the likelihood of issues is compounded by the fact that an application using Enterprise Library will typically contain binary references to entlib assemblies, as well as configuration files that refer to a specific copy of Enterprise Library assemblies. typically you won't edit the configuration files by hand, so the copy of the assemblies referenced in your configuration files will be determined by which copy of the Configuration tool you use. if there is not a perfect match between the Assemblies referenced from the binaries, the ones defined in configuration, and the ones actually located on disk, strange things can happen, such as the following:

  • if you use the configuration tool to load an existing configuration file that references a different copy of the assemblies to the ones the tool knows about, you will receive an error dialog "one or more errors occurred while trying to open the configuration", and a list of configuration errors such as "cocould not load file or assembly 'Microsoft. practices. enterpriselibrary. data, version = 3.0.0.0, culture = neutral, publickeytoken = NULL 'or one of its dependencies. the located assembly's manifest definition does not match the Assembly refernece ".
  • if you use the configuration tool to add a custom provider to a block's configuration, and the provider was compiled against a different copy of the assemblies to the one the tool knows about, you will receive an error when trying to browse for the providers in that Assembly along the lines of "there were no types found in the Assembly 'validationquickstart. customvalidators 'that implement or inherit from the base type 'Microsoft. practices. enterpriselibrary. validation. validator '"
  • if you attempt to run an application that uses Enterprise Library, but the application's configuration file was saved with a copy of the Configuration tool that uses a different copy of the assemblies to the assemblies referenced by the application, you will receive exceptions such as "system. configuration. configurationerrorsexception: An error occurred creating the configuration section handler for processing iselibrary. configurationsource: cocould not load file or assembly 'Microsoft. practices. enterpriselibrary. common, version = 3.0.0.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a 'or one of its dependencies. the located assembly's manifest definition does not match the Assembly reference. "

the good news is that all of these problems can be avoided easily enough if you keep a few things in mind. first, you need to decide which copy of Enterprise Library you want to use in your application. using the precompiled, strong-named binaries usually provides the path of least resistance, although it has a significant limitation in that you do not have the ability to make changes to the Code and recompile it to a compatible version of the Assembly. using a copy compiled from the source code requires you (or your team) to take more responsibility for the code, but also gives you more flexibility since you can make changes more easily. neither option is inherently right or wrong (which is why we give you both), however you shoshould make conscious demo-on which ones make sense for you. it may be a good idea to purge your system of whatever sets of binaries you decided against using to minimize confusion.

once you 've decided which binaries to use, you shoshould obviously always reference these in your projects, including any projects containing enterm enterpirse library extensions. the Enterprise Library assemblies listed on ". net "tab in Visual Studio's references dialog are the strong-named ones, so if you want to use a different version you shoshould navigate to these in the" Browse "tab.

next, you need to make sure you edit configuration files using a copy of the Enterprise Library Configuration tool that knows about the same copy of the assemblies as your app, since it will use these to generate your configuration files. if you are using the external Configuration tool (entlibconfig.exe), You shoshould simply use a copy of the tool compiled against the same set of assemblies (I. e. in the same "bin" directory ). note that the Start Menu shortcut cut that installwith Enterprise Library 3.0 points to the copy in "C: \ Program Files \ microsoft Enteprise library 3.0-release L 2007 \ bin "which uses the strong-named assemblies. if you want to use the non-strong-named one, you'll need to navigate to the "C: \ entlib3src \ app blocks \ bin "folder yourself (or update the Start Menu shortcut cut ).

Things are a little more interesting if you are using the Visual Studio-integrated configuration Editor, since you can't install multiple copies of Visual Studio. by default, the configuration editor will use the strong-named Enterprise Library assemblies. however it is possible to redirect the tool to a different set of assemblies on a per-solution basis. to do this, open a solution, select the solution root node in the Solution Explorer and then look at the Properties window. you shoshould see a property called Enterpriselibraryconfigurationset . By default, this will contain the Options "(machine default)", "Microsoft signed" and "entlib3src ". selecting "entlib3src" will tell the tool to use the assemblies from "C: \ entlib3src \ app blocks \ bin" for editing any configuration files in this solution. note that we set the parameter iselibraryconfigurationset to "entlib3src" for all of our Quickstart applications, since they are compiled against the source code projects. if you want to add, edit or remove the "configuation sets" or change the default, this information is stored in the registry in HKEY_CURRENT_USER \ Software \ Microsoft \ practices \ enterpriselibrary \ configurationeditor (for per-user settings) and HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ visualstudio \ 8.0 \ packages \ {488347a4-630c-4a0e-a6a2-b019cee13bea} \ configurationeditor (for machine-wide settings ).

one final note-if you or your organization has chosen to strong-name enterpirse library with your own key pair (which is a very common scenario ), there are even more opportunities for assembly-Mismatch problems to occur since you may have 3 or more incompatible sets of assemblies. however the priniciples for keeping everything matching are exactly the same as described above.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.