简体   繁体   中英

Alias Generic Type With ASP.Net Import Directive in VB.Net Page

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?

Yeah, bad news:

  1. You can't alias a generic type anywhere in .NET (may have changed recently, don't think so).
  2. You can't import a namespace with a space in it, in ASP.NET. It's the parser for the ASPX that's the issue. Yep, Microsoft oversight. Since C# would be List<System.String> , it would not throw the error. They left out VB again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM