Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb.net winform application and the enterprise library

Status
Not open for further replies.

glyn6

Programmer
Nov 2, 2009
561
GB
I've used the enterprise library in vb and c# in web apps to access a sql server database and that all works nicely :)

I'm trying to use it in a vb.net winform application now however and I'm having nowt but hassle.

I've reference the following .DLLs
Microsoft.Practices.EnterpriseLibrary.Data
Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.ObjectBuilder2
and included them in the bin directory, which is the #1 solution to the problem

I've included the following lines into the app.config
Code:
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </configSections>

I've imported the references too and when the code is executed on the line
Code:
Dim db As Database = DatabaseFactory.CreateDatabase("ConnString")
I get the error message

Code:
An error occurred creating the configuration section handler for enterpriseLibrary.ConfigurationSource: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (C:\dev\prog1\bin\prog.vshost.exe.Config line 7)

Where "ConnString" is also in the app.config and is a connection string that also works in the web app.

Any ideas as to why it's working fine for web apps but not for win apps?
Thanks
 

The public key tokens in app.config and appname.exe.config are case sensitive, and must be in the same case or this error will occur. Make sure that the public key tokens are either upper case in both or lower case in both.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
They match, I double checked and it rebuilds the appname.exe.config file whenever I build the project and it doesn't

It's the line
Code:
    <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
in app.config that seems to be affected, removing this line gives the error message
Code:
Configuration system failed to initialize
So I'm fairly confident in that at least ;-)

I tried using all uppercase instead of lower to make sure that wasn't a problem, so B03F5F7F11D50A3A instead of b03f5f7f11d50a3a and it had the same error though oddly, the error message put it in in lowercase. :-S

 
Turns out, when I added the reference to the DLLs it also added a few lines further down the app.config file.
Code:
  <enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source">
    <sources>
      <add name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null " />
      <add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null" filePath="c:\Shared.config" />
      <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null" />
    </sources>

  </enterpriseLibrary.ConfigurationSource>

I removed all references to the Microsoft.Practices stuff and it works. Makes a change to be over referenced rather than under referenced ;-)

Hope this helps somebody else out
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top