Pages

Search This Blog

Thursday, October 25, 2007

CS0030: Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'

Facing an error below and found that i'm not alone.

Posted by Microsoft on 9/29/2005 at 4:46 PM
If you have used a Page that effectively uses a codebehind classname that is the same as say the Login control, that is Login, e.g. your page was called Login.aspx, then when you pre-compile (publish) the web site as an updateable web site, the aspx is retained and tries to compile against a type called Login in the code behind.


Server Error in '/' Application.
--------------------------------------------------------------------------------
Compilation Error


Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0030: Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'


Source Error:

Line 118: public login_aspx() {

Line 119: string[] dependencies;
Line 120: ((Login)(this)).AppRelativeVirtualPath = "~/Login.aspx";
Line 121: if ((global::ASP.login_aspx.@__initialized == false)) {
Line 122: dependencies = new string[6];

Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\3e0e0b67\701b7b2\App_Web_login.aspx.cdcab7d2.fhpe1ais.0.cs Line: 120






Many post and solutions can get from the internet. Among them is

  1. Rename Login.aspx to others name like signin.aspx
  2. Try using a classname for your codebehind and defined in the inherits that does not clash with a type in System.Web, e.g. LoginPage, or qualify the class and therefore the inherits statement with a namespace, e.g.<%@ page ... inherits="theNs.Login" %.namespace theNs { public partial class Login : System.Web.UI.Page { .. } }
  3. uncheck “Allow this precompiled site to be updatable” when Publish Web Site in Visual Studio 2005.
Solution no. 3 is good for me. Less work and works 100%.

Wednesday, October 24, 2007

A generic error occurred in GDI+.

Error Message received when try to upload picture to my web application:

Server Error in '/' Application.

A generic error occurred in GDI+.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.


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:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +396978
System.Drawing.Image.Save(String filename, ImageFormat format) +69
Account.WarpImageDimensions(String filePath, String fileName, Bitmap imageToSave) +301
Account.ImageButton1_Click(Object sender, ImageClickEventArgs e) +350
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +86
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +115
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746



Solve this by:
1. check the permission for upload folder
2. check the correct upload path

problem solved.

Select top xx from DataTable

I was trying to figure out how to sort and select top 20 from a DataTable. Understand from the reading, DataTable have no "select top" feature. Some suggest use below method

DataTable outputTable = SourceTable.Clone();
for(int i=0;i<20;i++)
outputTable.ImportRow(SourceTable.Rows[i]);

In my case, i need to sort my DataTable oldTable and select top 20 after the sorting. I use DataView dView to sort it and copy it into a new DataTable newTable. For the display purpose, i use "for loop" to select top 20 from the new DataTable newTable.

Sample Code:

int maxDisplay = 20;
DataView dView = oldTable.DefaultView;
dView.Sort = " [Count] DESC ";
DataTable newTable = dView.ToTable();



int dCount = newTable.Rows.Count;
if (maxDisplay > dCount )
maxDisplay = dCount ;
if (dCount > 0)
{
for (int i = 0; i < maxDisplay ; i++)

{
xxxxxx;
xxx + newTable.Rows[i]["name"].ToString();

xxxxxx;
}
}

text wrapping in table : Firefox and IE

My case:
I'm using C# StringBuilder object to generate a long string with all blog Tags with link and without any white space between them. I've tried below code.


.hardbreak
{
width: 190px;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
<table style="TABLE-LAYOUT: fixed; WIDTH: 210px" cellpadding="'3'">

<tr>
<td class="hardbreak" style="WIDTH: 200px">

xxxx return StringBuilder code over here xxxx
</td>

</tr>
</table>

Result in IE: working fine. Even the word can be wrapped.



Result in Firefox: not working



this give me a problem.

I've try to google around and finally i found that i should insert a white space " " after every single tag before append to StringBuilder. Surprisingly, without using the class above, my problem solved.

Friday, October 19, 2007

Server Error in '/'Application. Configuration Error

Error Message on web.config when setting up a new application.

Server Error in '/'Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Unrecognized attribute 'requirePermission'.

Change the ASP.NET version to the correct version.



Problem solved.

Thursday, October 18, 2007

Must declare the scalar variable "@UserId".

We are doing server migration testing. I've restored a DB from production to staging server. I setup up a ASP.NET application and point to production server, everything work fine but when point to staging server, error below appear. By the way, we are using MS SQL 2005 standard edition in both server.

Server Error in '/' Application.

Must declare the scalar variable "@UserId".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@UserId".

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:


[SqlException (0x80131904): Must declare the scalar variable "@UserId".]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +862234
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +739110
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1956
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
System.Data.SqlClient.SqlDataReader.get_MetaData() +62
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +903
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) +62
Dal.GetRecentRater(Int32 PostId, DataTable dt) +190
Post.BindBlogPost() +1295
Post.Page_Load(Object sender, EventArgs e) +49
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061










At this point, i suspect something wrong with the staging server DB. So i access to the staging server and execute the stored procedure in Query Panel and it give me some error message.
Must declare the scalar variable "@UserId".







I open and check the stored procedure and the stored procedure is simple

ALTER PROCEDURE [dbo].[GetUserDetails]
@UserId int
as
select * from Users where UserId = @UserID


After check for a while, i change the @UserID to @UserId and magic happened. Problem solved. It's case sensitive.

It's strange because this stored procedure running in production server without any problem. Collation for both MS SQL 2005 DB are SQL_Latin1_General_CP1_CI_AS.

Tuesday, October 16, 2007

DataList Paging

There are always a problem to customize paging for DataList as below.

I'm able to develop a DataList Paging for my own application. Credit should give to Netomatix.
Please download and check the sample source code from my testing.
For testing purpose, i use Northwind database and i've created a new stored proc called: GetProductByCategory










Stored Procedure: GetProductByCategory

CREATE PROCEDURE [dbo].[GetProductByCategory]
@PageIndex INT,
@NumRows INT,
@Discontinued BIT = 1
AS
BEGIN
SET NOCOUNT ON
DECLARE @StartRowIndex INT;
SET @StartRowIndex = (@PageIndex * @NumRows) + 1;
WITH myProducts AS(
SELECT ProductID, ProductName, UnitPrice,
CategoryName, Description, UnitsInStock,
ROW_NUMBER() OVER(ORDER BY ProductID DESC) as Row,
count(*) over() AS ResultRowCount, Discontinued
FROM Products P
INNER JOIN Categories C
ON P.CategoryID = C.CategoryID
WHERE Discontinued = @Discontinued
)
SELECT * FROM myProducts
WHERE Row BETWEEN @StartRowIndex AND (@StartRowIndex + @NumRows)-1
ORDER BY ProductID ASC
SET NOCOUNT OFF
END

Monday, October 15, 2007

Could not load type '_Default'

Server Error in '/DataListPage' Application.

Parser Error

Description
: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type '_Default'.

Source Error:

Line 1: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" % >
Line 2:
Line 3: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
">

I'm able to run my application in Visual Studio, when try to open the application directly from IE, i get this error. After check for a while, i found that it's the problem for the ASP.NET Version that selected. After i change to ASP.NET 2.0.50727, problem solved.

ASP.NET wrapper for Twitter API

I was developing a ASP.NET wrapper for Twitter API and end up using the wrapper provided by Yedda. Credit should to Yedda.

Download the wrapper from Yedda. Unzip the files and you can play around with the project.

What i do is
  1. Create a new class name TwitterWrapper in my App_Code
  2. Copy the code from Twitter.cs and paste in TwitterWrapper.cs

to twitter your message:

string xmlOutput = "";
string TwitterUserName = "username";
string TwitterPassword = "password";

string TwitterMessage = "Hello twitter";

if (TwitterUserName != "" && TwitterPassword != "")
{
try
{
TwitterWrapper twitter = new TwitterWrapper();
xmlOutput = twitter.Update(TwitterUserName, TwitterPassword, TwitterMessage, TwitterWrapper.OutputFormatType.XML);
}
catch (Exception ex)
{ }
finally
{ }
}

Sunday, October 14, 2007

System.Web.HttpParseException: Could not load the assembly App_Web_xxxx. Make sure that it is compiled before accessing the page.

I always received error message from the web application after the last deployment.

System.Web.HttpParseException: Could not load the assembly 'App_Web_fsfkjwna'. Make sure that it is compiled before accessing the page. ---> System.Web.HttpParseException: Could not load the assembly 'App_Web_fsfkjwna'. Make sure that it is compiled before accessing the page. ---> System.Web.HttpParseException: Could not load the assembly 'App_Web_fsfkjwna'. Make sure that it is compiled before accessing the page. ---> System.Web.HttpException: Could not load the assembly 'App_Web_fsfkjwna'. Make sure that it is compiled before accessing the page.at System.Web.UI.TemplateParser.GetType(String typeName, Boolean ignoreCase, Boolean throwOnError)at System.Web.UI.TemplateParser.ProcessInheritsAttribute(String baseTypeName, String codeFileBaseTypeName, String src, Assembly assembly)at System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData)--- End of inner exception stack trace ---at System.Web.UI.TemplateParser.ProcessException(Exception ex)at System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData)at System.Web.UI.PageParser.PostProcessMainDirectiveAttributes(IDictionary parseData)at System.Web.UI.TemplateParser.ProcessMainDirective(IDictionary mainDirective)at System.Web.UI.TemplateControlParser.ProcessMainDirective(IDictionary mainDirective)at System.Web.UI.PageParser.ProcessMainDirective(IDictionary mainDirective)at System.Web.UI.TemplateParser.ProcessDirective(String directiveName, IDictionary directive)at System.Web.UI.BaseTemplateParser.ProcessDirective(String directiveName, IDictionary directive)at System.Web.UI.TemplateControlParser.ProcessDirective(String directiveName, IDictionary directive)at System.Web.UI.PageParser.ProcessDirective(String directiveName, IDictionary directive)at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)--- End of inner exception stack trace ---at System.Web.UI.TemplateParser.ProcessException(Exception ex)at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)--- End of inner exception stack trace ---at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)at System.Web.UI.TemplateParser.ParseFile(String physicalPath, VirtualPath virtualPath)at System.Web.UI.TemplateParser.ParseInternal()at System.Web.UI.TemplateParser.Parse()at System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType()at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)at System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)




After struggling for a while, i found that by doing 2 steps can solve this problem.




  1. Create a new Application Pool.

  2. Change the application pool for my application to the newly created pool.


Create new Application Pool in Internet Information Server 6 (Windows Server 2003)




  1. Open IIS 6


  2. Right click on Application Pools node from the tree view


  3. Select New -> Application Pool ... from the context menu


  4. Enter Application pool ID (myAppPool) and click OK.


  5. New Application Pool Created.



  6. Change the application pool for my application to the newly created pool.

  7. Open IIS
  8. From the explorer view, open the Web Sites folder.


  9. Point to the web application that want to change the Application Pool (mysite.com)


  10. Right click on mysite.com


  11. Select Properties


  12. A new Properties window pop up, Select "Home Directory" tab


  13. Change the Application Pool to "myAppPool" and click OK.


  14. Application Pool Changed


  15. Done.

    For Windows XP developer, when face this error, Kill aspnet_wp.exe process,

    go to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files and delete all the temporary files. Try to compile your project again.