Click here to Skip to main content
11,804,919 members (66,718 online)
Rate this: bad
Please Sign up or sign in to vote.
I can't seem to import a generic type on an ASP.Net page set to a language of "vb":

<%@ Page Language="vb" %>
<%-- This works fine. --%>
<%@ Import Namespace="MyString=System.String" %>
<%-- This gives an error. --%>
<%@ Import Namespace="MyList=System.Collections.Generic.List(Of System.String)" %>
<%-- Error: "The 'namespace' attribute cannot contain spaces." --%>

Note that I'm NOT interested in these alternatives (for boring reasons you don't care about):
  • Alter the web.config.
  • Alter the code-behind.
  • Use the code-behind instead of the page.
  • Using C# instead of VB.Net.
  • Googling (the MSDN page makes no mention of generic types).
  • Modifying the app.config.
  • Adding the namespace to the "imported namespaces" via the "References" tab in the project settings.
  • Workarounds (I already have workarounds, but I want to see if this can be done properly).

Is it possible to alias a generic type on a VB.Net ASP.Net page, or is this an oversight by Microsoft?
Posted 26-Oct-11 8:15am
Edited 27-Oct-11 7:23am
SAKryukov at 26-Oct-11 14:43pm
Hm, interesting question, I voted 5.
I never tried such thing with ASP.NET (that's why I'm not posting any solution), but at first glance actually would expect that if "MyString=System.String" works, "MyList=System.Collections.Generic.List(Of System.String)" should work.

Actually I would certainly recommend to avoid it by resorting to one of the alternatives you deny by "boring reasons", like the last one, but it would not make the formulation of the problem invalid.
JRickey at 28-Oct-11 2:00am
I came across one allusion to using (System.String()) instead of (Of System.String) as a way to circumvent the no-space restriction.
AspDotNetDev at 28-Oct-11 2:05am
Doesn't seem to work. I came across some funky syntax that used an apostrope and some square brackets, but I forget exactly what it looked like. I'll probably do some more searching tomorrow.
AspDotNetDev at 28-Oct-11 2:08am
Actually, I just tried the syntax I was thinking of and it didn't work: MyList=System.Collections.Generic.List`1[System.String]
JRickey at 28-Oct-11 13:10pm
Have you tried substitutes for the space (such as %20, etc.)? Another possibility is something akin to white-space handling.
himanshu agarwal at 30-Jul-15 5:10am
I believe you are not importing a namespace there when you say System.Collections.Generic.List(Of System.String), you should just try aliasing to import System.Collections.Generic or System.Collections.Generic.List
AspDotNetDev at 1-Aug-15 22:32pm
That is exactly my problem, as I indicated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 3,205
1 Maciej Los 1,950
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,187

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 27 Oct 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100