Enterprise Library DLL not found from COM Wrapper

Topics: Cryptography Application Block
Jan 24, 2009 at 9:59 PM
I wrote an application to handle some encryption using Enterprise Library and it works great.  I compile it and use it as a stand alone exe and it functions fully.  My end need was to access this class within a classic ASP application using vbscript.  When I wrap it in a com wrapper and try to run it from within an MS Access application for testing, all the methods work fine except for ones using the Library.  Specifically encryption.   When i try anything using my AES encryption routines.  I get the following error:

Error -2146232062
An error occurred creating the configuration section handler for securityCryptographyConfiguration:
Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Security.Cryptography,
Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
The system cannot find the file specified. (C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE.config line 5)

I have tried re-regiestring all the ELibrary dll's.  No help.  I am using the Elib configuration tool to setup the encryption and using a key stored in a file using DPAPI.  All i have to do is have the code do something like.             byte[] bytes = CryptographyUtility.GetRandomBytes(30);  And Access stops being able to create an instance of my COM object. 

any ideas?

Jan 25, 2009 at 9:56 PM
Update...  I forgot to mention that I jumped through hoops to figure out where to place the app.config file for the com wrapper (DLL).  It turns out that because of COM, it is expected to be in the directory of the hosting application.  In this case...  Offices (more precisely msAccess.exe) installation directory with a name of MSACCESS.EXE.Config.  It turns out that if i place the Enterprise Library DLLs into the same directory, it works fine.

Sooooo  2 questions... someone... please??

1. How can I get the COM Wrapped DLL to find the Enterprise Library DLLs in their installed directory, rather than having to put them into every/any host I happen to use the com object in?

2. I tried loading another app.config and always got an error regarding the protection level of the app.config.  Is there a way to force the use of a different app.config?  Mine is encrypted and the core of the setup for doing encryption/decryption is embedded in it, so i don't believe just opening another one after app load will trigger the proper use of the library encryption...

Jan 26, 2009 at 11:37 AM

You can deploy entlib to GAC if copying them to the installed directory is not an option.

I remember using an encrypted app.config to encrypt the connectionString of the dataconfiguration also in a COM scenario. It ran with ent lib deployed to the GAC and I used FileConfigurationSource as the ConfigurationSource of the DbProviderFactory class. The location of the config file was not the same as the location of the host.

I might be able to replicate your issue if you can provide a sample solution.If not, can you provide mo details on the approach you used in loading the encrypted app.config and the specific encrypted section.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
Jan 26, 2009 at 2:58 PM
Edited Jan 26, 2009 at 3:36 PM
I believe you are quite right about deploying to the GAC.  Thanks for the input.  I will read up on the whole strong-naming and deploying steps in the help files and let you know if this solves the problem....  thanks