Click to See Complete Forum and Search --> : "specified cast not valid" - can you tell me why I'm getting this?


jubbf
September 9th, 2004, 11:39 AM
Hi all,

I know what an invalid cast error is supposed to mean, but I don't understand why I'm getting it here. Let me explain...

We have several simple ASP.NET pages that run fine using MS .NET Framework v1.0.3705. Our Sysadmin just installed the v1.1.4322 Framework and wants to use that because of improved security. Once he pointed the .aspx pages in the website folder at that framework, all pages ceased to work, and all of them report back a "Specified cast is not valid" error instead.

For a test, I created two pages, both of which are listed below in their entirety:

<%@ Page Language="VB" %>

<html>
<head>
<title>Howdy</title>
</head>
<body>

<% Dim MyName as String
MyName = "Bob" %>
<font size="10"> Hello World! </font> <br>
</body>

</html>

...and...

<%@ Page Language="VB" %>

<html>

<body>

<% Dim I As Integer
For I = 0 To 7 %>
<font size="<%=I%>"> Hello World! </font> <br>
<% Next %>

</body>

</html>

The second one is sample code, takes without alteration from Microsoft's ASP 1.1 tutorial. Both of the above pages result in an error page stating "System.InvalidCastException: Specified cast is not valid." Here's the stack trace, in case it helps...

[InvalidCastException: Specified cast is not valid.]
System.Web.Configuration.HttpCapabilitiesEvaluator.Evaluate(HttpRequest request) +499
System.Web.Configuration.HttpCapabilitiesBase.GetConfigCapabilities(String configKey, HttpRequest request) +43
System.Web.HttpRequest.get_Browser() +143
System.Web.UI.Page.CreateHtmlTextWriterInternal(TextWriter tw, HttpRequest request) +29
System.Web.UI.Page.CreateHtmlTextWriter(TextWriter tw) +12
System.Web.UI.Page.ProcessRequestMain() +1916

Oh, and if you switch these pages to point back to the installed 1.0 framework, they work as they should. That's not a solution, however, since the Sysadmin is big on security and 1.0 isn't secure enough. I had the Admin install service pack #1, just to be thorough, but the problem remains. I've been all over the web, trying to find some help for this, but have found nothing. Does anyone have any ideas?

Frederick Jubb
Grand Rapids, MI

MRutledge
September 9th, 2004, 12:36 PM
You have to recompile all your web apps with the new framework. You cant just point it to the new framework install.

jubbf
September 9th, 2004, 12:49 PM
Thanks for the reply, but as I understand it, compiling is done on the server side the first time a page is accessed. The two pages that I pasted up above were created for the first time AFTER the framework switch was made, in a website folder that was likewise created after the framework switch. So, as I understand the process, the compilation was done in the 1.1 framework.

Oh, and I don't use Visual Studio or anything else. Just Notepad.

If there's something I'm not understanding about compiling ASP.NET pages, please let me know. I'm pretty new to this stuff.

MRutledge
September 9th, 2004, 12:59 PM
read this and its supporting documents. Maybe this will give you a better idea of what is going on

http://msdn.microsoft.com/netframework/technologyinfo/versioncomparison/default.aspx