The source type could not be found for name x

Topics: Validation Application Block
Apr 2, 2010 at 2:45 PM
Edited Apr 2, 2010 at 2:49 PM

 

Hi Guys,

Our application uses the Enterprise Library's PropertyProxyValidator class to validate user input (v4.1 - Oct 2008). Validation by using only the object modal works just fine.

Validator<Dossier> validator = ValidationFactory.CreateValidator<Dossier>(rule.ToString());return validator.Validate(this);

The Dossier object is an object generated by the Entity Framework (.edmx). When I use a propertyproxyvalidator in my .ascx page I get an error:  The source type could not be found for name "MyProject.DAL.Dossier". I configured the propertyproxyvalidator like:

 

 

cc1:propertyproxyvalidator id="TextBox1Validator" runat="server" ControlToValidate="txtBA" PropertyName="Name" RulesetName="RuleSet1" SourceTypeName="MyProject.DAL.Dossier"></cc1:propertyproxyvalidator>

 

 The error is caused  by the following call in the VAB class "PropertyProxyValidator":

validatedType = BuildManager.GetType(this.SourceTypeName, false, false);

 

I am using the validation block in a SharePoint WebPart. The MyProject.DAL.Object exist in a separate assembly which is deployed in the GAC.

Any ideas for causes would be greatly appreciated. 

Thanks!

 

 

 

Apr 5, 2010 at 9:43 AM

Hi JohanKlijn,

Have you already referenced your MyProject.DAL.Object assembly in your Web Project? If not yet, please do add it in the reference and try to test again and see if the error is still being encountered. Please let me know of the outcome and if there are any questions.

HTH,

~ginkapitan

Apr 5, 2010 at 2:29 PM
Edited Apr 5, 2010 at 2:30 PM

Hi ginkapitan,

I have a reference to my MyProject.DAL.Object assembly. That's way I can not explain why I get this error.

Could it be something related how SharPoint is loading Web Parts? Because I am using the VAB in a SharePoint Web Part.

Johan.

Apr 5, 2010 at 3:33 PM

I just found out, that if I specify the full qualified name of the type I don't get an error.

So

 SourceTypeName="MyProject.DAL.Dossier, MyProject.DAL Version=1.0.0.0, Culture=neutral, PublicKeyToken=....."<font size="2" color="#0000ff"><font size="2" color="#0000ff">

 

</font></font><font size="2" color="#0000ff">

 

</font>

does not cause an error. Is this required?

 

Apr 6, 2010 at 2:26 AM

I believe setting the SourceTypeName properly is very important to make VAB works.

Based from experience I was able to make it work by putting either the business object’s namespace.classname or namespace.classname, assemblyname in the SourceTypeName property.

Though, as per this thread http://entlib.codeplex.com/Thread/View.aspx?ThreadId=82322 and based from the VAB Hands-On Lab using the namespace.classname, assemblyname is advisable.

Try and see if this will work on you. If not then at least you have the full qualified name working in your application.

HTH,

~ginkapitan 

Apr 6, 2010 at 8:59 AM

You are right, setting the SourceTypeName is very important others is will not work.

But setting "namespace.classname, assemblyname " without the versionnumber and PublicKeyToken is not working in my solution. And I cann't explain why. Because when I use FusLogVw.exe I see that my "Myroject.DAL" assembly is loaded from the GAC (before any propertyproxyvalidator is used), but BuildManager.GetType is still not able to "resolve" the type.

Apr 6, 2010 at 12:08 PM

Hi JohanKlijn,

Just want to make sure, are you sure you really had your MyProject.DAL output assembly/DLL added in your Web Project References?

I'm asking this because as I have tried to reproduce your scenario using my simple application somehow I noticed that the behavior of having "namespace.classname, assemblyname, version, culture, publickeytoken" type of format in the SourceTypeName is applicable and beneficial when your business object's assembly is in the GAC and cannot physically add that DLL into your Web Project References. Failure to comply with this format will cause your Web App to throw the error The source type could not be found for name X. While if your business object's assembly is properly referenced to your Web Project all SourceTypeName can be used.

Also, try cleaning up your Temporary ASP.NET Files folder, just to make sure we're not dealing with a glitch :-)

HTH

~ginkapitan

Apr 11, 2010 at 10:51 AM

Hi ginkapitan,

I added a reference to MyProject.DAL. (I am not sure what you mean by Web Project Reference). But more important I think is, I am creating a SharePoint solution. I created a web part which loads  dynamically a Web User Control. This control uses the VAB. So I am not using a "real" asp.net Web Project. Maybe that's why the BuildManager can not find MyProject.DAL assembly? Because MyProject.DAL is not a "top level" reference in SharePoint.

 

Johan.

Apr 12, 2010 at 1:36 AM

If you select the MyProject.DAL reference and see its properties in the Properties window, does the Copy Local set to true or false?  If it's false, .NET assumes that your reference is in the GAC.

 

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

Apr 15, 2010 at 2:27 PM

It is set to Copy Local. We deploy the assembly indeed to the GAC. But what does that have to do with the fact that the BuildManager can not find the assembly?

Apr 16, 2010 at 3:33 AM

Ah, I missed the fact that the error was being thrown when calling BuildManager.GetType.  Yes, I think your assessment that it's not a top-level reference  is the reason why it can't load the assembly. 

 

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

Nov 29, 2010 at 3:41 PM

Hi, I seem to have the same problem, my PropertyProxyValidator only accepts the SourceTypeName, when it uses the right PublicKeyToken, Version, etc.

I am also working on SharePoint...

On my side I have another problem, maybe Johan can help... I get a Security Exception:

Security Exception
Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request failed.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SecurityException: Request failed.]
   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) +212
   System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException) +474
   System.Security.PermissionSetTriple.CheckSetDemand(PermissionSet demandSet, PermissionSet& alteredDemandset, RuntimeMethodHandle rmh) +105
   System.Security.PermissionListSet.CheckSetDemand(PermissionSet pset, RuntimeMethodHandle rmh) +71
   System.Security.PermissionListSet.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +59
   System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant, CompressedStack securityContext) +172

How can I resolve this?

Nov 30, 2010 at 2:42 AM

I haven't really worked on Sharepoint development but found these 2 related thread and article with which I noticed the extra step of adding entlib assemblies to the SafeControls section of your web.config. 

http://www.codeproject.com/KB/sharepoint/MSEL_in_Sharepoint.aspx - skip reading steps 1-11 as those steps need not be executed if you're using the strongly-named entlib assemblies, the one from Program Files\Microsoft Enterprise Library {version}\bin folder.

http://stackoverflow.com/questions/185621/sharepoint-and-enterprise-library-4-0

 

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