views:

37

answers:

1

Hi all,

We have a updatable web site project that is written in c#, it has the usual web form implementation using master page, skins, user controls,...etc. Up to this point we neglect to change the default compilation language from VB to C#. However, the second we change it, we see the following error.

Object reference not set to an instance of an object. --->
System.NullReferenceException: Object reference not set to an instance
of an object. at ASP.Default.__DataBinding__control499(Object sender,
EventArgs e) at System.Web.UI.Control.OnDataBinding(EventArgs e) at
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at
System.Web.UI.Control.DataBindChildren() at
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at
System.Web.UI.Control.DataBindChildren() at
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at
System.Web.UI.Control.DataBindChildren() at
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at
System.Web.UI.Control.DataBindChildren() at
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at
....

Further investigation points out that this error is getting generated from a Theme related assembly (Source : App_Theme_Default.zclakrlo). Any ideas?

One of my co-worker suggested that it might be skin file related since we have a theme call "Default" and there is no way to specify a language on a skin file. Therefore, when the asp.net runtime tries to compile it under C#, it will give a name collision? Does this make sense?

Any help is appreciated.

Update: It turns out that there is a span tag in one of the skin file which look like the following:

<span runat="server" visible='<%# Eval("foo") %>'>

where foo is a string value of either "true" or "false". For some reason, this works under VB compilation, but fails in C#.

The fix is to change the type of foo from string to bool. All in all, very weird edge case!

+2  A: 

This is because the code for this control ultimately distills into something like the following for VB:

Public Sub __DataBinding__control499(ByVal sender As Object, ByVal e As EventArgs)
    Dim control As HtmlGenericControl = DirectCast(sender, HtmlGenericControl)
    Dim bindingContainer As IDataItemContainer = DirectCast(control.BindingContainer, IDataItemContainer)
    control.Visible = CBool(MyBase.Eval("Foo"))
End Sub

...where as in C# it is:

public void __DataBinding__control499(object sender, EventArgs e)
{
    HtmlGenericControl control = (HtmlGenericControl) sender;
    IDataItemContainer bindingContainer = (IDataItemContainer) control.BindingContainer;
    control.Visible = (bool) base.Eval("foo");
}

CBool actually accepts any numeric or string expression whereas the direct cast from Eval("foo") to bool will fails in this case because Eval("foo") isn't a boolean.

Nariman