VAB - IValidatorDescriptor is inaccessible due to protection level

J

Jay

In both of the UnitTest projects that ship with the Ent Lib, (VSTS and
Nunit), there is a TestMethod with the name:
AttributeWithLowerAndUpperBoundsOnlyCreatesAppropriateValidator.

Each of these tests creates a StringLengthValidatorAttribute:
ValidatorAttribute attribute = new StringLengthValidatorAttribute(10,
20);

The next line creates a validator object based on the settings defined
in the Attribute:
Validator validator =
((IValidatorDescriptor)attribute).CreateValidator(null, null, null);

The final step prior to being able to access the properties of the
StringLengthValidator is:
StringLengthValidator stringLengthValidator = validator as
StringLengthValidator;

The following is what I have completed in my UnitTest class. The
concept of my Unit Test is to loop through all properties defined in
my Entity class, and then through the Attributes defined for each
property.

Sample:

foreach (PropertyInfo myInfo in myType.GetProperties())
{
foreach (Attribute attribute in myInfo.GetCustomAttributes(true))
{
if (attribute is
MSValidation.Validators.StringLengthValidatorAttribute)
{
Validator validator = ((IValidatorDescriptor)
(ValidatorAttribute)attribute).CreateValidator(null, null, null);
Assert.IsNotNull(validator);

StringLengthValidator stringLengthValidator = validator as
StringLengthValidator;
Assert.IsNotNull(stringLengthValidator);
}
}
}

The issue is that I am getting a compile error of:

Microsoft.Practices.EnterpriseLibrary.Validation.IValidatorDescriptor'
is inaccessible due to its protection level
D:\Development\UnitTest\Entity\CustomerUnitTest.cs

As expected, the IValidatorDescriptor is not color-coded in my unit
test but is in the sample UnitTests. My project is referencing the
EntLib...Validation DLL but I am obviously missing something. Can you
help?

Thanks
 
J

Jesse Houwing

As expected, the IValidatorDescriptor is not color-coded in my unit
test but is in the sample UnitTests. My project is referencing the
EntLib...Validation DLL but I am obviously missing something. Can you
help?

If I'm not mistaking the EntLib dll's have a [InternalsVisibleTo]
Attribute which allows specific assemblies (including the provided test
assemblies) to see the internal variables.

Jesse
 
J

Jay

If I'm not mistaking the EntLib dll's have a [InternalsVisibleTo]
Attribute which allows specific assemblies (including the provided test
assemblies) to see the internal variables.

I was looking at that attribute. However, isn't the attribute used in
the configuration of the source DLL and specifying the target assembly
that is permitted to use the Internals?

Meaning that in this scenario wouldn't I have to add that line
AssemblyInfo.cs file of the Enterprise Library object and permit my
object's access to the Enterprise Library methods?

Sorry, I'm new to the VAB and am trying to soak in as much as I can.

Thanks for your help,
Jay
 
J

Jay

Update...I managed to get this working.

I opened the actual VAB c# project ("D:\EntLib3Src\App Blocks\Src
\Validation\Validation.csproj") and modified the AssemblyInfo.cs file
within this project to include the line:

[assembly: InternalsVisibleTo("SourceApplication.UnitTest")]

The SourceApplication.UnitTest is the namespace of my unit testing
project.

After re-compiling the application, I have taken the updated
"Microsoft.Practices.EnterpriseLibrary.Validation.dll" file and then
updated the reference to this DLL in my application. Presto! the
IValidatorDescriptor is now accessible and can convert the attribute
into a valid Validator.

Thanks all for the help.
 
J

Jesse Houwing

* Jay wrote, On 28-5-2007 20:44:
If I'm not mistaking the EntLib dll's have a [InternalsVisibleTo]
Attribute which allows specific assemblies (including the provided test
assemblies) to see the internal variables.

I was looking at that attribute. However, isn't the attribute used in
the configuration of the source DLL and specifying the target assembly
that is permitted to use the Internals?

Meaning that in this scenario wouldn't I have to add that line
AssemblyInfo.cs file of the Enterprise Library object and permit my
object's access to the Enterprise Library methods?

That is correct. So it isn't going to work with the default
pre-compiled, pre-signed assemblies.
Sorry, I'm new to the VAB and am trying to soak in as much as I can.

Don't worry.

Jesse
 
J

Jesse Houwing

* Jay wrote, On 28-5-2007 21:43:
Update...I managed to get this working.

I opened the actual VAB c# project ("D:\EntLib3Src\App Blocks\Src
\Validation\Validation.csproj") and modified the AssemblyInfo.cs file
within this project to include the line:

[assembly: InternalsVisibleTo("SourceApplication.UnitTest")]

The SourceApplication.UnitTest is the namespace of my unit testing
project.

After re-compiling the application, I have taken the updated
"Microsoft.Practices.EnterpriseLibrary.Validation.dll" file and then
updated the reference to this DLL in my application. Presto! the
IValidatorDescriptor is now accessible and can convert the attribute
into a valid Validator.

Thanks all for the help.


You're welcome :)

Jesse
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top