Error Importing Microsoft.Practices.EnterpriseLibrary.Data Namespace

Apr 13, 2011 at 11:58 PM

I am encountering a problem when I attempt to use the Data Access Block in a WPF project. The problem is that I get errors whenever I attempt to run the program. The errors are:

  1. 'ConfigureData' is not a member of 'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceBuilder'; and
  2. Type 'Database' is not defined.

I think that they are caused because the import of the Microsoft.Practices.EnterpriseLibrary.Data namespace fails. The error message is:

 “Namespace or type specified in the Imports ‘Microsoft.Practices.EnterpriseLibrary.Data’ doesn’t contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn’t use aliases”

 I have added the following references to my VB.Net project:

  • Microsoft.Practices.EnterpriseLibrary.Common.dll
  • Microsoft.Practices.EnterpriseLibrary.Data.dll
  • Microsoft.Practices.ServiceLocation.dll
  • Microsoft.Practices.Unity.dll
  • Microsoft.Practices.Unity.Configuration.dll
  • Microsoft.Practices.Unity.Interception.dll

I have tried uninstalling and reinstalling the Enterprise Library 5 but this doesn’t resolve the problem. Any ideas how to correct this problem would be appreciated.

The code for the project is:

Imports Microsoft.Practices.EnterpriseLibrary.Common

Imports Microsoft.Practices.EnterpriseLibrary.Common.Configuration

Imports Microsoft.Practices.EnterpriseLibrary.Data

Imports System.ComponentModel

Imports System.Data.Common

Imports System.Data

 

 Class MainWindow

 

   Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded

       Dim configBuilder As ConfigurationSourceBuilder = New ConfigurationSourceBuilder

       configBuilder.ConfigureData() _

           .ForDatabaseNamed("EntLibQuickStarts") _

           .ThatIs.ASqlDatabase() _

           .WithConnectionString("Server=[Server Name]; Database=EntLibQuickStarts; Trusted_Connection=True") _

           .AsDefault()

 

       Dim configSource = New DictionaryConfigurationSource

       configBuilder.UpdateConfigurationWithReplace(configSource)

       EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource)

       Dim db As Database = EnterpriseLibraryContainer.Current.GetInstance(Of Database)()

 

       Dim count As Integer = CType(db.ExecuteScalar(CommandType.Text, "SELECT COUNT(*) FROM Customers"), Integer)

       Dim message As String = String.Format("There are {0} customers in the database", count.ToString())

       MessageBox.Show(message)

   End Sub

End Class

 

The contents of app.config which I am attempting to modify are:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

   <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" />

   </configSections>

   <dataConfiguration defaultDatabase="EntLibQuickStarts" />

   <connectionStrings>

       <add name=EntLibQuickStarts" connectionString="&quot;Server=[Server Name]; Database=EntLibQuickStarts; Trusted_Connection=True&quot;"

           providerName="System.Data.SqlClient" />

   </connectionStrings>

   <system.diagnostics>

       <sources>

           <!-- This section defines the logging configuration for My.Application.Log -->

           <source name="DefaultSource" switchName="DefaultSwitch">

               <listeners>

                   <add name="FileLog"/>

                   <!-- Uncomment the below section to write to the Application Event Log -->

                   <!--<add name="EventLog"/>-->

               </listeners>

           </source>

       </sources>

       <switches>

           <add name="DefaultSwitch" value="Information" />

       </switches>

       <sharedListeners>

           <add name="FileLog"

                 type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"

                 initializeData="FileLogWriter"/>

           <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->

           <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->

       </sharedListeners>

   </system.diagnostics>

</configuration>

Apr 14, 2011 at 12:50 AM

I'm suspecting that you are targeting a .NET client profile.  When using the Microsoft.Practices.EnterpriseLibrary.Data assembly of EntLib 5.0, you are required to target the full .NET framework.  Right click on your project, select Properties, and in the Applciation tab, select either .NET Framework 3.5 or .NET Framework 4.0 as value of the Target Framework property.  This is a known issue in EntLib 5.0

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Apr 14, 2011 at 1:59 AM

Thank you very much Sarah for such a prompt response. That has fixed my problem.

Clinton

From: AvanadeSupport [email removed]
Sent: Thursday, 14 April 2011 10:50 AM
To: clinton@hicklings.com
Subject: Re: Error Importing Microsoft.Practices.EnterpriseLibrary.Data Namespace [entlib:253801]

From: AvanadeSupport

I'm suspecting that you are targeting a .NET client profile. When using the Microsoft.Practices.EnterpriseLibrary.Data assembly of EntLib 5.0, you are required to target the full .NET framework. Right click on your project, select Properties, and in the Applciation tab, select either .NET Framework 3.5 or .NET Framework 4.0 as value of the Target Framework property. This is a known issue in EntLib 5.0

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 6, 2011 at 9:33 AM

I hope someone might have a pointer for me:  I have targeted the 4.0 Framework but still have the same problem clintonH had:

  1. 'ConfigureData' is not a member of 'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceBuilder'; and
  2. Type 'Database' is not defined.

 

Any suggestions would be greatly appreciated,

Brent

Aug 8, 2011 at 8:37 AM

What version of Enterprise Library are you using? Have you just upgraded your version?

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 8, 2011 at 11:12 AM

Hi Brent,

My problem was fixed by following the advice I received from Sarah Urmenet, Global Technologies and Solutions, Avanade, Inc. Their advice was:

When using the Microsoft.Practices.EnterpriseLibrary.Data assembly of EntLib 5.0, you are required to target the full .NET framework. Right click on your project, select Properties, and in the Applciation tab, select either .NET Framework 3.5 or .NET Framework 4.0 as value of the Target Framework property. This is a known issue in EntLib 5.0

Hope this helps.

Clinton Hickling

From: Solvix [email removed]
Sent: Saturday, 6 August 2011 7:33 PM
To: clinton@hicklings.com
Subject: Re: Error Importing Microsoft.Practices.EnterpriseLibrary.Data Namespace [entlib:253801]

From: Solvix

I hope someone might have a pointer for me: I have targeted the 4.0 Framework but still have the same problem clintonH had:

1. 'ConfigureData' is not a member of 'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceBuilder'; and

2. Type 'Database' is not defined.

Any suggestions would be greatly appreciated,

Brent

Aug 8, 2011 at 11:14 AM

Thanks for replying but Sarah Urmeneta already provided me with an answer to my problem.

Thanks again for trying to help.

Regards

Clinton Hickling

From: AvanadeSupport [email removed]
Sent: Monday, 8 August 2011 6:37 PM
To: clinton@hicklings.com
Subject: Re: Error Importing Microsoft.Practices.EnterpriseLibrary.Data Namespace [entlib:253801]

From: AvanadeSupport

What version of Enterprise Library are you using? Have you just upgraded your version?

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 8, 2011 at 11:25 PM

Thank you for such a prompt response!  My problem was actually resolved after I learned how I needed to add references for the context in which I was trying to implement (in my case, I had to add references to the Microsoft.Practices.EnterpriseLbirary.Logging DLL (from the EntLib 5\bin directory).  Once I added this DLL, the additinal members showed in my dropdownlist. 

If I can explain to anyone else in greater detail, feel free to call on me.

 

Regards,
Brent