I’m in the process of learning vs2005.net. Every once in a while I run into a problem that makes me run to Google. This is no exception. I wanted to validate the the asp.net CheckBoxList control to make sure that at least one item from the list was checked. I found this wonderful sample code from 4 Guys from Rolla.com on how to create a custom validation control for this purpose. After creating a new C# custom control you need to register it with VisualStudio (which places the dll) in the ‘bin’ directory of your web site. 4 Guys then show that you need to register the tag prefix that you will be using the @ Register directive as shown below:

<%@ Register TagPrefix="CustomValidators" Namespace="CustomValidators" Assembly="filename_of_DLL_file" %>

Which I change to:

<%@ Register TagPrefix="cv" Namespace="MyCustomValidators" Assembly="~/bin/CustomValidationControls.dll" %>

However as soon as I compiled the page I received: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) After searching Google some more I wasn’t any better off with a solution. What is wrong with my code base? Recompiling didn’t help renaming it didn’t help. However after some careful reading of the on-line help related to the @ Register directive I found this statement:

assembly
The assembly in which the namespace that you are associating with the tagprefix attribute resides.

Note
The assembly name does not include a file extension. …

That was the clue I need combined with another post I had read. I had added the full path and extension for the assembly but what it was looking for was ONLY the assembly name it self with no extension or directory path. .net assumes that the path for the assembly will be the bin directory. So the correct @ Register directive should be:

<%@ Register TagPrefix="cv" Namespace="MyCustomValidators" Assembly="CustomValidationControls" %>

As soon as I did that the page compiled with out errors and I now can validate my CheckBoxList.

As an aside note you can also solve this by putting the source file in the App_Code directory and then register the tag prefix this way:

<%@ Register TagPrefix="cv" Namespace="MyCustomValidators" Assembly="__Code" %>

6 Replies to “Fixing The given assembly name or codebase was invalid.”

  1. Heh, this was exactly what I was doing wrong, and I was even doing it with a CheckBox validator!

    Thanks much.

  2. I found that simply removing any symbol characters from the name that is (usually) automatically assigned by VS when the main form is renamed or given a title rectified the problem.

    This may not help anyone else, but the solution worked for me…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.