Problem using an assembly

  • Thread starter Nathan Sokalski
  • Start date
N

Nathan Sokalski

I have a User Control that I created (.ascx & .ascx.vb file pair) that I am trying to put in a separate assembly. I know that the User Control works when it is in the same project and is compiled along with the project it is used in, so the problem is obviously something I am doing wrong with the references or something. My current code registers the assembly as:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="DatePickerTest.aspx.vb" Inherits="WebApplication1.DatePickerTest"%>

<%@ Register TagPrefix="NateCtrl" Namespace="NateCtrl" Assembly="NateCtrl" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<title>DatePickerTest</title>

<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">

<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">

<meta content="JavaScript" name="vs_defaultClientScript">

<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">

</HEAD>

<body>

<form id="Form1" method="post" runat="server">

<NateCtrl:DatePicker id="DatePickerCtrl" runat="server"></NateCtrl:DatePicker><BR><BR>

<asp:label id="lblSelectedDate" runat="server"></asp:label>

<asp:button id="btnRefresh" runat="server" Font-Bold="True" EnableViewState="False" Text="Refresh"></asp:button><BR><BR>

<asp:button id="btnXmas2000" runat="server" Font-Bold="True" EnableViewState="False" Text="Christmas 2000" CausesValidation="False"></asp:button><BR><BR>

<asp:button id="btnMyBirthday" runat="server" Font-Bold="True" EnableViewState="False" Text="My Birthday" CausesValidation="False"></asp:button><BR><BR>

<asp:button id="btnNewYear95" runat="server" Font-Bold="True" EnableViewState="False" Text="New Year's 1995" CausesValidation="False"></asp:button>

</form>

</body>

</HTML>


When I attempt to execute the page, I recieve the following error:


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

Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 62: ViewState.Add("stopyear", Date.Today.Year + 25)
Line 63: For i As Integer = 1 To 12
Line 64: ddlMonth.Items.Add(New System.Web.UI.WebControls.ListItem(System.Globalization.DateTimeFormatInfo.CurrentInfo.GetMonthName(i), CStr(i)))
Line 65: Next
Line 66: Me.CreateLists()

Source File: c:\inetpub\wwwroot\NateCtrl\DatePicker.ascx.vb Line: 64

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
NateCtrl.DatePicker.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\NateCtrl\DatePicker.ascx.vb:64
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Page.ProcessRequestMain() +750



What am I missing here? Thanks.
 
K

Ken Tucker [MVP]

Hi,

Your @Register is wrong here is an example from one of my
projects.

<%@ Register TagPrefix="uc1" TagName="RssViewer" Src="RssViewer.ascx" %>

If drag the control from the solution explorer to the form you
want the control on. VB.net will add the @ register for you.

Ken
----------------
I have a User Control that I created (.ascx & .ascx.vb file pair) that I am
trying to put in a separate assembly. I know that the User Control works
when it is in the same project and is compiled along with the project it is
used in, so the problem is obviously something I am doing wrong with the
references or something. My current code registers the assembly as:

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="DatePickerTest.aspx.vb"
Inherits="WebApplication1.DatePickerTest"%>
<%@ Register TagPrefix="NateCtrl" Namespace="NateCtrl" Assembly="NateCtrl"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>DatePickerTest</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<NateCtrl:DatePicker id="DatePickerCtrl"
runat="server"></NateCtrl:DatePicker><BR><BR>
<asp:label id="lblSelectedDate" runat="server"></asp:label>
<asp:button id="btnRefresh" runat="server" Font-Bold="True"
EnableViewState="False" Text="Refresh"></asp:button><BR><BR>
<asp:button id="btnXmas2000" runat="server" Font-Bold="True"
EnableViewState="False" Text="Christmas 2000"
CausesValidation="False"></asp:button><BR><BR>
<asp:button id="btnMyBirthday" runat="server" Font-Bold="True"
EnableViewState="False" Text="My Birthday"
CausesValidation="False"></asp:button><BR><BR>
<asp:button id="btnNewYear95" runat="server" Font-Bold="True"
EnableViewState="False" Text="New Year's 1995"
CausesValidation="False"></asp:button>
</form>
</body>
</HTML>

When I attempt to execute the page, I recieve the following error:


Server Error in '/WebApplication1' Application.


Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 62: ViewState.Add("stopyear", Date.Today.Year + 25)
Line 63: For i As Integer = 1 To 12
Line 64: ddlMonth.Items.Add(New
System.Web.UI.WebControls.ListItem(System.Globalization.DateTimeFormatInfo.CurrentInfo.GetMonthName(i),
CStr(i)))
Line 65: Next
Line 66: Me.CreateLists()


Source File: c:\inetpub\wwwroot\NateCtrl\DatePicker.ascx.vb Line: 64

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
NateCtrl.DatePicker.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\NateCtrl\DatePicker.ascx.vb:64
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Page.ProcessRequestMain() +750




What am I missing here? Thanks.
 
S

Scott Allen

I have a User Control that I created (.ascx & .ascx.vb file pair) that I am trying to put in a separate assembly. I know that the User Control works when it is in the same project and is compiled along with the project it is used in, so the problem is obviously something I am doing wrong with the references or something. My current code registers the assembly as:

It's not really possible to do this in 1.x, because Visual Studio
doesn't know how to compile the .ascx file into an assembly.


In 2.0 the ASP.NET runtime does all the compilation. I have a proof of
concept where I use the AspNet compiler to produce assemblies and
merge them together to reference from another project:
http://odetocode.com/Blogs/scott/archive/2005/10/06/2326.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top