14
Vote

Data and Validation Blocks don't work from the GAC

description

<p>If Entlib 5 is installed in the GAC, then the Data and Validation blocks don&#39;t properly read their configuration sections. This results in &quot;cannot Resolve Database&quot; style errors. It works if you copy these assemblies local.</p> <p>&nbsp;</p> <p>Why: Under the hood the type registration providers are loaded by name, and the name is not fully assembly qualified. Without the full name, these assemblies cannot be located in the GAC.</p>

file attachments

comments

ctavares wrote Apr 28, 2010 at 5:10 AM

Found a workaround. Add this section to your configuration file:
<configSections>
<section name="typeRegistrationProvidersConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.TypeRegistrationProvidersConfigurationSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</configSections>

And the contents of the section:

<typeRegistrationProvidersConfiguration>
<remove name="Data Access" />
<add name="Data Access" providerType="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

<remove name="Validation" />
<add name="Validation" providerType="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationTypeRegistrationProvider, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</typeRegistrationProvidersConfiguration>

aggallentes wrote Apr 30, 2010 at 4:12 AM

Hi,

First of all, Thank you very much for having effort to mention this workaround.

I tried to test it but unfortunately as of now for my case it's not working.

below is the sample of my configuration.
<configuration>
<configSections>
<section name="typeregistrationprovidersconfiguration" type="microsoft.Practices.EnterpriseLibrary.Common.Configuration.TypeRegistrationProvidersConfigurationSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<dataConfiguration defaultDatabase="OptimDB">
<providerMappings>
<clear />
</providerMappings>
</dataConfiguration>
<connectionStrings>
<add name="TestDB" connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TESTTable;Data Source=TESTSERVER"
providerName="System.Data.SqlClient" />
</connectionStrings>

<typeRegistrationProvidersConfiguration>
<remove name="Data Access" />
<add name="Data Access" providerType="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

<remove name="Validation" />
<add name="Validation" providerType="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationTypeRegistrationProvider, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</typeRegistrationProvidersConfiguration>

</configuration>

Please advice.

Thanks

ctavares wrote Apr 30, 2010 at 4:57 AM

Is that your exact config file? XML is case sensitive - you've got the section name in the tag in all lower case. It has to match exactly, case and all.

aggallentes wrote Apr 30, 2010 at 6:32 AM

Hi ctavares,

Thanks for the prompt reply..

I tried to changed it but still the same.

one more thing coz I'm a bit confuse, when I install entlib5 from msi I have noticed that it's not installed in the GAC. is it expected?

Thanks a lot.

ctavares wrote Apr 30, 2010 at 3:31 PM

We deliberately do not install into the GAC. The GAC is generally more of a problem than a solution, and unless you have a specific reason to put assemblies there, we recommend using local copies instead.

I don't know what to say at this point, it worked for us everywhere we tried it. Can you reproduce the issue with a small sample project and post it?

ionutcalin wrote Aug 25, 2010 at 6:27 AM

I believe that this workaround with the typeRegistration configuration MUST be included in the DAAB and Validation help sections and on the EntLib project home page.

Many thanks for the soultion

zzweber wrote Feb 14, 2011 at 2:17 PM

I have been hacking away at this for days before i came across this workaround. Thanks ctavares!!
This really should be documented somewhere.

FatihTheScorpio wrote Jun 22, 2011 at 2:29 PM

It works perfect.

Thanks....

tobiashatt wrote Jul 13, 2011 at 12:47 PM

Is it possible to do this typeRegistrationProvidersConfiguration via code? Because we are using the SqlConfigurationSource [0] and while trying to add this section to the database we are getting an error ("The entry 'Data Access' has already been added.")

[0] http://entlib.codeplex.com/releases/view/56812

tobiashatt wrote Jul 13, 2011 at 3:11 PM

OK my issue ("The entry 'Data Access' has already been added.") is fixed now! If you have the same problem using the SqlConfigurationSource add the following item to your config table:

INSERT INTO [Entlib_ConfigurationSection] ([SectionName],[SectionTypeName],[SectionXml]) VALUES ('typeRegistrationProvidersConfiguration','Microsoft.Practices.EnterpriseLibrary.Common.Configuration.TypeRegistrationProvidersConfigurationSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35','');

Philippe wrote Sep 29, 2011 at 6:17 PM

There is a built-in mechanism in .NET to "translate" partial assembly binding to fully qualified names. Simply enter this in your configuration file:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Microsoft.Practices.EnterpriseLibrary.Data" 
fullName="Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblyBinding>
</runtime>

It works great! In fact, this same issue exists with a number of the EntLib assemblies so I included all of them in the section above. Hope it helps others who may have struggled with this.

Philippe wrote Sep 29, 2011 at 6:20 PM

There is a built-in mechanism in .NET to "translate" partial assembly binding to fully qualified names. Simply enter this in your configuration file:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Microsoft.Practices.EnterpriseLibrary.Data" 
fullName="Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblyBinding>
</runtime>

It works great! In fact, this same issue exists with a number of the EntLib assemblies so I included all of them in the section above. Hope it helps others who may have struggled with this.

Philippe wrote Sep 29, 2011 at 6:28 PM

There is a built-in mechanism in .NET to "translate" partial assembly binding to fully qualified names. Simply enter this in your configuration file:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Microsoft.Practices.EnterpriseLibrary.Data" 
fullName="Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblyBinding>
</runtime>

It works great! In fact, this same issue exists with a number of the EntLib assemblies so I included all of them in the section above. Hope it helps others who may have struggled with this.

singhal_sunil065 wrote Aug 13, 2012 at 2:31 PM

Thanks very much.

santosh89 wrote Nov 22, 2012 at 1:23 AM

Hi,

I am using the "Microsoft.Practices.EnterpriseLibrary.Data" version "5.0.414.0". I am using VS 2010.
I have added connectionstring entry in the web.config, and I am able to access the database using SQL Server 2008 R2.
I have added the below line in my code to use the database:
Database db = null;
db = DatabaseFactory.CreateDatabase("NeniRS.RetailData");
where NeniRS is a resource file to get RetailData instance.

and app.config like:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Microsoft.Practices.EnterpriseLibrary.Data" fullName="Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblyBinding>
</runtime>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<!--<section name="typeRegistrationProvider" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.TypeRegistrationProvidersConfigurationSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35" />-->
</configSections>

<dataConfiguration defaultDatabase="RetailData" />
<connectionStrings>
<add name="RetailData" connectionString="Data Source=.;Initial Catalog=RetailData;Integrated Security=True" providerName="System.Data.SqlClient" />

</connectionStrings>

</configuration>

However, I am getting an error as:

"Activation error occured while trying to get instance of type Database, key".RetailData
How to fix this?

here i attached my code
Thank you

rspiet wrote Apr 24, 2014 at 4:20 PM

Thank you Phillipe. The runtime additions to the Web and App.Config files worked for me. You solved a two year for me and my company of why we could not run our application without having to include Microsoft.Practices.EnterpriseLibrary.Data in our bin folders instead of referencing it from the GAC.

I only wish that I understood what the issue really is.