Every once in a while, when I'm editing an aspx or ascx page, Visual Studio will start telling me there is an error on the first line of my file. For instance, right now, it is saying Argument missing
on line 1. That line is just your typical header, with no apparent problems (to my eyes), and I hadn't even changed that one when the error started appearing.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyControl.ascx.cs"
Inherits="MyNamespace.MyControl" Debug="true" %>
Unlike most compile errors, the build still succeeds. (At least this time it did.)
It's worth noting that no other errors or warnings are thrown by this file or its as[p|c]x.cs
Sometimes, to get out of it, I am forced to undo my changes until it disappears and carefully redo what I wanted. This time, grasping at straws, I cleaned and rebuilt the solution. While I was typing this, the error disappeared, sometime after the rebuild finished.
I have a suspicion that it often happens when I tinker with the databinding in my markup. Sometimes it seems to appear if I'm missing a space inside a tag before its closing slash, like so:
[...] Text='<%# Eval("Field") %>'/>
versus:
[...] Text='<%# Eval("Field") %>' />
...But that doesn't seem to have been the problem in this case.
When coding PHP and Perl, sometimes the interpreter would throw an error referencing the very last line of the file. Over time, I learned to look for imbalanced brackets and other delimiters somewhere up above. This problem in ASP.NET feels similar, but stranger, since it's the first line, and not just something amiss above, cascading down to the bottom. Or is it just Visual Studio getting temporarily confused? Can开发者_Go百科 any pros shed some light on this problem, with reasons why it happens? I'd like to have some logic (as opposed to my own built up superstition) to throw at this the next time it rears its ugly head.
Here is what I found - when I get this error there is usually a code in the aspx page with a function call that is in fact missing arguments - like this one
<asp:DropDownList DataValueField="Value" DataTextField="Text"
runat="server" Width="90%" ID="Duration"
DataSource='<%# Utils.GetDropDownList(, ) %>' />
Note that arguments are missing in the call Utils.GetDropDownList(, )
So the error message does not correctly point to the line in aspx page, but there is in fact an issue with the code. Hope this saves somebody some time.
Having observed this a few more times now, it seems like this happens when a Rebuild of the solution is in order. I tend to use Build most of the time, because it's conveniently mapped to F6. (I'm not currently aware of a built-in mapping to Rebuild.) Remember to use Rebuild when things are going strangely awry.
精彩评论