SourceTypeName

Topics: Building and extending application blocks, Enterprise Library Core, General discussion, Validation Application Block
Jan 28, 2010 at 5:22 PM

Hello,

Does anyone know how to properly set the SourceTypeName for a ValidationProvider when you are using an external configuration file; in this case the SpecificationSource = "Configuration"? Please help, Thanks!

Jan 29, 2010 at 1:12 AM

Using an external config file for the ValidationProvider is not supported in v4.1.

 

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

Jan 29, 2010 at 5:07 PM

Ok. Has anyone figured out a work around for this? Our whole validation process is centered around external configuration files. I thought maybe I could use parameter inspection/validation and use the ValidationFaults in conjuction with Windows ErrorProvider; doing all the work myself, but I wasn't sure if someone may have stumbled across a more efficent means of getting it done. Please let me know. Thanks!

Feb 1, 2010 at 7:40 AM

Hi,

I have tried a workaround that works. What i did is i have this external config, that i was referencing from my config using the configSource keyword. Although i haven't tried using the File coonfiguration source of the ent lib (to reference external config) but probably it will also work. I have created a sample application, if you're interested, i we can send you a copy.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Feb 1, 2010 at 12:58 PM

Yes, I would appreciate if you could send me a copy or post a link to the sampe application. Thanks!

Feb 2, 2010 at 8:23 AM
Edited Feb 2, 2010 at 8:25 AM

I forgot about using the configSource attribute. 

The workaround described by Valiant just needs this in your config:

<validation configSource="externalValidation.config" />

The externalValidation.config is the external file you want to use (and it only works for relative path).  Keep in mind that you will be limitied to using one external configuration file only.  if you use this, all your validation codes will refer to that file for the validation rules.

 

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

Feb 2, 2010 at 12:38 PM

Thanks, I'll try this and see what happens. By the way, is there a specific way you have to specify the SourceTypeName?

Feb 2, 2010 at 1:03 PM

Yes, that is the fullname, assembly name -> namespace.classname, assemblyname.

Oh, and by the way it has no relevance on using external config files.

 

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

Feb 2, 2010 at 1:16 PM

Oh ok, so when using an external config do not specify the SourceTypeName. Alright I tried what you mentioned above and it still didn't work.  The error I get is "No source type has been defined for the validation provider". Here is what I am doing in my app.config that is part of my application.

 

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

<configuration>

  <configSections>

    <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

    <section name="validtion" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

  </configSections>

  <validation configSource="validation.config" />

</configuration>

Is there something I am doing wrong? The only properties I am setting on "ValidationProvider" is the what errorprovider to use, the RuleSet, and the SpecificationSource. Any ideas?

Feb 2, 2010 at 1:19 PM

No, you still need to specify it, it's required.  What I meant was that its value is not affected whether you use the app.config or an external config.

 

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

Feb 2, 2010 at 1:32 PM
Edited Feb 2, 2010 at 1:43 PM

Alright well, it seems that regardless of whether or not if specify the SourceTypeName as the App.config or the external config; validation.config, it is not working. Actually, specifying the SourceTypeName as you mentioned, I get this error "The source type does not represent a valid type for validation provider". Is it possible for you to send me the project where you have the ValidationProvider working with an external config file? Maybe that may clear up my issues I keep having a bit more. Thanks.

Feb 2, 2010 at 1:37 PM

I don't have that in my machine right now, I'll just create a new one.  But didn't you have a working copy that doesn't use an external config?

 

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

Feb 2, 2010 at 1:46 PM

The working copy that I am using as my test is called "WinFormsAdapterVAB", but like I said this application only uses Assembies for the ValidationProvider not a configuration file. I was trying to add a field and validationprovider to this project that called to a config for its validation, but as you can tell I am not having much luck. Do you need my email address to send me the project?

Feb 2, 2010 at 1:48 PM

Yes, you can just email me so you won't have to post it here.

Feb 2, 2010 at 1:49 PM

dawsona0526@hotmail.com

Feb 2, 2010 at 1:59 PM

Sent...

Feb 2, 2010 at 2:12 PM

Thanks. Ok, I noticed a couple things that are different in apps that may be causing the issues I am having. For one, my "validation.config" does not show up in my solution at all. I am not sure if this matters or not at the moment, but it is preferred if it is not seen in the solution at all. Secondly, I see by looking at the properties of your validationprovider you are still defaulting the SpecificationSource to "Both". Is this on purpose? On mine I am using "Configuration", also, I see your still your assemblies for the SourceTypeName, this must be due to the fact the SourceTypeName only recognizes assembly name. I am guessing right? Thirdly, my business class; "Customer" does not live in my solution either. It is in its own assembly all together. The only entities that exist in the solution are the Form, App.config, errorprovider, and the validationprovider. I am going to try and separate yours out and see if it still works. I will get back to you soon with the results. Fingers crossed.

Feb 2, 2010 at 2:20 PM

As long as your validation.config is in the path you specified in the configSource attribute, it doesn't matter if it's part of the solution or not.  On the SpecificationSource, I just forgot to set it to Configuration, it would work either way. 

"I see your still your assemblies for the SourceTypeName, this must be due to the fact the SourceTypeName only recognizes assembly name." - I really don't get this.  As I said, the SourceTypeName is in the format of fullname, assemblyname.  And that assembly should be referenced in your project.  Thus, your "Customer" class need not be in your solution.

 

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

Feb 2, 2010 at 2:35 PM

My validation.config is at the same level as my app.config, so it is in the path I specified, but just not part of the solution. If you exclude the validation.config from the solution you get this error "Unable to open configSource file 'validation.config'. (C:\Documents and Settings\dawsoad\Desktop\SampleWinForm\SampleWinFormsValidation\SampleWinFormsValidation\bin\Debug\SampleWinFormsValidation.vshost.exe.config line 7)"

Next thing I am going to try is putting Customer.cs in its own assembly and see what happens.

 

 

Feb 2, 2010 at 2:56 PM

Ok, the error I mentioned above seems to come from not specifying the full path to the config. Now the error I am getting says, "Configuration system failed to initialize". Any thoughts?

Feb 2, 2010 at 4:10 PM

It seems I was almost able to accomplish everything I set out to do. I say almost because for some reason I cannot get this to work with a relative path for some reason or another; I am going to continue to investigate this issue and post my findings. Also, instead of using cofigSource I am using enterpriseLibrary.ConfigurationSource, which seems to be working just fine for me.

Feb 3, 2010 at 12:33 AM

Dawsoad, the error you're getting is probably because your validation.config is not being copied to the output director.  Set its  Copy to Output Directory to Copy Always.

 

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

Feb 3, 2010 at 5:12 PM

Quick question. Is there a way in the app.config to set the filePath using a registry entry? For instance, right now I set the filePath for the external config file; validation.config, as follows filePath="C:\Config\validation.config". Would it be possible to use a registry entry that specifies a file path you want to use instead; HKEY_LOCAL_MACHINE\SOFTWARE\CONFIG?

Feb 4, 2010 at 5:01 AM

Hi,

As far as I know, that is not supported by ent lib. As I've tried before, the FileConfigurationSource only supports absolute and relative path.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com