I just want to see if others get this same behavior I get.
I have a class called GridViewEx which extends GridView. One of the properties in that class has Browsable(true) as an annotation. This allows (well, at least prior to IIS 7.5 it did) the property to be set in the markup. But on Windows 7 IIS 7.5, it gives a parser error. Note that on a Win 2008 server with IIS 7.5, the app ran fine.
So I'm wondering if it's some IIS 7.5 setting in Win7 that is messing it up.
Steps to Reproduce
a) Create new ASP.Net application, use 4.0 for framework version
b) Create a new class called GridViewEx (the get/set are just dummy code, not important):
namespace GUI.Controls
{
public class GridViewEx : GridView
{
[Browsable(true)]
[Description("my test")]
public int VirtualItemCount
{
get
{
return 42;
}
set
{
int x = value;
int y = x + x;
}
}
}
}
c) In Default.aspx, register the tag prefix (change WebApplication1 to whatever you called your project). This line should go right underneath the Page directive.
<%@ Register TagPrefix="common" Namespace="GUI.Controls" Assembly="WebApplication1" %>
d) In Default.aspx, add this to your content:
<common:GridViewEx runat="server" ID="gv" VirtualItemCount="-1">
</common:GridViewEx>
If I run this app on IIS 7.0 or earlier, I get no errors. However, on Win 7 IIS 7.5, it gives the following error:
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: The 'VirtualItemCount' property cannot be set declaratively.
I don't understand why I get the error on Win 7 IIS 7.5, but not on earlier IIS versions and not on IIS 7.5 on a Win 2008 server. Any ideas?
Ok, I found a hack to make this work. Added these attributes to VirtualItemCount
:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[EditorBrowsable(EditorBrowsableState.Always)]
[Bindable(true)]
Now I no longer get the parser error. I don't understand why I had to add these to make in work on my Win 7 machine, but on the server I tested it on these extra attributes aren't needed (both my Win 7 machine and the server are on IIS 7.5). I guess that will remain a mystery.
Many thanks to the person who answered this question, as it steered me in the right direction.
来源:https://stackoverflow.com/questions/14899899/win-7-iis-7-5-weird-behavior-with-system-componentmodel-browseableattribute