Enterprise Library 2006 Error when referenced from GAC |
|
Author |
Message |
jpasman

|
Posted: .NET Base Class Library, Enterprise Library 2006 Error when referenced from GAC |
Top |
I get an error when trying to execute this code referencing Microsoft.Practices.EnterpriseLibrary.Data from the GAC, but it works if I reference the assembly locally from the bin directory:
Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetStoredProcCommand("storedproc");
db.AddInParameter(dbCommand,
, DbType.Int32, "2");
DataSet ds = db.ExecuteDataSet(dbCommand);
The following is in my app.config file:
< xml version="1.0" encoding="utf-8" >
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />
</configSections>
<connectionStrings>
<add name="ConsoleApplication1" providerName="System.Data.SqlClient" connectionString="server=SERVERNAME;user id=USER;Password=PASSWORD;initial catalog=DATABASE;" />
</connectionStrings>
<dataConfiguration defaultDatabase="ConsoleApplication1"/>
</configuration>
The code errors out on the first line with the following error:
System.Configuration.ConfigurationErrorsException was unhandled by user code Message="An error occurred creating the configuration section handler for dataConfiguration: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data' or one of its dependencies. The system cannot find the file specified. (C:\\Documents and Settings\\USERNAME\\My Documents\\Visual Studio 2005\\Projects\\ConsoleApplication1\\ConsoleApplication1\\bin\\Debug\\ConsoleApplication1.vshost.exe.config line 4)" Source="System.Configuration" BareMessage="An error occurred creating the configuration section handler for dataConfiguration: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data' or one of its dependencies. The system cannot find the file specified." Filename="C:\\Documents and Settings\\USERNAME\\My Documents\\Visual Studio 2005\\Projects\\ConsoleApplication1\\ConsoleApplication1\\bin\\Debug\\ConsoleApplication1.vshost.exe.config" Line=4 StackTrace: at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSourceImplementation.GetSection(String sectionName) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource.GetSection(String sectionName) at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView.get_DatabaseSettings() at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseMapper.MapName(String name, IConfigurationSource configSource) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp[TTypeToBuild](IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IReadWriteLocator locator, IConfigurationSource configurationSource) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IConfigurationSource configurationSource) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.NameTypeFactoryBase`1.CreateDefault() at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase()
.NET Development1
|
|
|
|
 |
JocularJoe

|
Posted: .NET Base Class Library, Enterprise Library 2006 Error when referenced from GAC |
Top |
If you want to reference an assembly in the GAC, you need to use a fully-qualified reference, with Version, Culture and PublicKeyToken:
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=x.x.x.x, Culture=neutral, PublicKeyToken=..." />
|
|
|
|
 |
jpasman

|
Posted: .NET Base Class Library, Enterprise Library 2006 Error when referenced from GAC |
Top |
Wow, I can't believe I forgot that. That was it. Thanks.
|
|
|
|
 |
Meaning Of Lights

|
Posted: .NET Base Class Library, Enterprise Library 2006 Error when referenced from GAC |
Top |
I had the same problem, it was killing me!!
In the end, troubleshooting the problem was quiet easy.... I knew the problem stemmed from this:
"Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data' or one of its dependencies. The system cannot find the file specified."
So I was tempted to run a FileMon/Regmon (a.k.a ProcessMonitor) but before I did this I had a look at the DataAccess example in the Ent. Library 2006 and saw there was a DLL in the bin folder that I wasn't referencing in my solution:
Microsoft.Practices.ObjectBuilder.dll
|
|
|
|
 |
Makarand_Keer

|
Posted: .NET Base Class Library, Enterprise Library 2006 Error when referenced from GAC |
Top |
Hi
I am facing same problem , this is the Error that I get
System.Configuration.ConfigurationErrorsException was unhandled by user code Message="The type Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null from configuration could not be created." Source="Microsoft.Practices.EnterpriseLibrary.Common" BareMessage="The type Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null from configuration could not be created." Line=0 StackTrace: at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.NameTypeConfigurationElementCollection`1.RetrieveConfigurationElementType(XmlReader reader) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.PolymorphicConfigurationElementCollection`1.OnDeserializeUnrecognizedElement(String elementName, XmlReader reader) at System.Configuration.ConfigurationElement.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
I don't have any of Microsoft.Enterprise patterns libraries in GAC and I have build my app.config file by using Enterprise Library Configuration Tool.
Since I use dlls from bin only (and not from GAC) should I have to remove Version, Culture and PublicKey settings from my config file
Please help
Makarand
|
|
|
|
 |
Meaning Of Lights

|
Posted: .NET Base Class Library, Enterprise Library 2006 Error when referenced from GAC |
Top |
Hi Makarand,
Your issue doesn't appear to be caused from "finding" or "loading" a file, but we'll try and help you out anyway since the error looks the same. In future always log a new thread for a new question/problem.
When you use the Enterprise Library Configuration Tool it doesn't add it the Version, Culture and PublicKey settings when referencing the Data Application block of the Ent Library in your config file... check it out... you may want to remove those settings, particularly if the DLLs aren't in the GAC and are just in a bin folder.
Is there only three calls in the full stacktrace I mean the error didn't originally stem from the below call, did it
System.Configuration.ConfigurationElement.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
I managed to overcome this issue by starting off with a really basic "bare bones" example. Then I stepped through each line of code.. ruling out everything and x-referencing clues with the www.
hth,
Jeremy
|
|
|
|
 |
vinnisharma

|
Posted: .NET Base Class Library, Enterprise Library 2006 Error when referenced from GAC |
Top |
Thanks so much. I added the reference again and it worked.
|
|
|
|
 |
|
|