Context is not a member of MyProg._Default - asp.net

I am endeavouring to correct a problem with a Web Project:-
Could not load type 'MyProg._Default'.
To fix this I have adopted the solution suggested here and changed CodeBehind into CodeFile. As is customary in ASP.Net Whack-a-Mole, this has introduced a new and different error:-
Context is not a member of 'MyProg._Default'
The very strange solution to this suggested here doesn't seem likely to fix the problem as I have no user-defined controls on the form.
I have two questions, really. First, is changing CodeBehind this way likely to fix the original problem, and if so how do I fix the new problem?
Edit to answer wazz's question, the top line in the aspx is:-
<%# Language="VB"
AutoEventWireup="true"
Inherits="MyProg._Default"
CodeFile="Default.aspx.vb"
MaintainScrollPositionOnPostback="true" %>
and the class is defined thus:-
Public Class _Default
Inherits System.Web.UI.Page

Related

ASP.NET site error: Could not load type '[SITE]._Default'

I've written up an ASP.NET / VB site and it's been working fine all through debugging. However, once I publish the site and go to it in browser, I get the error listed in the title.
I've followed a few different sets of instructions to fix the problem, but none of the stuff I've tried seems to be working.
Here is what's at the top of my Default.aspx page:
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="[SITE]._Default" %>
And, the class in my Default.aspx.vb file:
Public Class _Default
I've tried changing "CodeBehind" to "CodeFile" which didn't work and gave me further errors. I'd also like to point out that another project was used as a template and renamed, along with all of the files associated with it, so maybe that's causing an issue? I have no idea. Any help would be appreciated!

What happens if the Inherits attribute is removed from the #Page directive?

I don't know what happened with my project, but since I reinstalled my pc with Windows 8, the website doesn't build...
My #Page directives look summing like this:
<%# Page Title="Register" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeBehind="Register.aspx.vb" Inherits="_Register" %>
The codebehind for this page looks like this:
Partial Class _Register
Inherits MobilePage
' subs go here (don't think they're important for the question)
End Class
With this set up this way, I'm getting the following error:
Could not load type '_Register'.
Removing the Inherits attribute fixes this error, but what else does it do in terms of the page's functionality?

Content page requiring Global.MasterPageClassName and designer reverting it everytime i re-open the page

I have a simple master page defined as such:
Public Class AppUIMasterPage
Inherits System.Web.UI.MasterPage
Then i have a base class for content pages:
Public MustInherit Class AppUIBase
Inherits System.Web.UI.Page
Then the master page tag:
<%# Master Language="VB" AutoEventWireup="false" CodeBehind="my.master.vb" Inherits="AppUI.AppUIMasterPage" %>
On the content page:
Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/my.Master" CodeBehind="somecontentpage.aspx.vb" Inherits="AppUI.viewprocedure" %>
And content code-behind
Public Class viewprocedure
Inherits AppUIBase
The designer automatically inserts the following:
'''<summary>
'''Master property.
'''</summary>
'''<remarks>
'''Auto-generated property.
'''</remarks>
Public Shadows ReadOnly Property Master() As AppUI.AppUIMasterPage
Get
Return CType(MyBase.Master, AppUI.AppUIMasterPage)
End Get
End Property
When i try to build the complier throws an error and intellisense wants me to change AppUI.AppUIMasterPage to: Global.AppUI.AppUIMasterPage
I'm not exactly sure why it is doing this, and I would be OK if it was just a simple change, however every time i close and re-open the page VS changes it and before i build i have to change it back again.
I believe if you use the System.ComponentModel.DesignerCategory attribute with a blank string as the parameter, the designer will stop trying to automatically mess up your file.
Ref: Disable designer in Visual Studio?
While disabling the designer would be one approach, the better way was just to rename the classes in such a way that the designer was no longer getting confused. Find and replace was my best friend in doing this.
This issue only appears to occur if the base class names confuse the designer.

could not create type XYZ.ashx

When I am trying to build my solution I am getting Could not create type Upload.ashx.I am pulling out my hair to solve this.Can anyone suggest me how to rectify this problem.And I don't know how to actually append the namespace to the class?
As I am having
Here is my code:
<%# WebHandler Language="vb" CodeBehind="Upload.ashx.vb" Class="Upload" %>
And this is my dir structure:
wwwroot/Test/Myproject
I don't think there is such a thing as an .ashx.vb file type.
Try changing your top line to:
<%# WebHandler Language="VB" Class="Upload" %>
and then just put your code behind code in the .ashx file
<%# WebHandler Language="VB" Class="Upload" %>
Imports System
Imports System.Web
Public Class Upload : Implements IHttpHandler
'Code here....
End Class
Alternatively, have you tried building your code?
See this similar question for more help:
Custom Http Handlers IIS7 and ASP.NET
I've been banging my head against the wall for a few hours over this error "could not create type", and it may not help your exact problem
I had split my codebehind across many partial classes, all called "restserver" apart from one which was called "restServer" (note the capital S) it was that small difference that was causing the error, I changed them all to the same case and it worked perfectly.
VS isn't very helpful when working with ASHX files.
I know this is an old question, but it is at the top of google at the moment, so for anyone looking: In a website project, the handler directive expects different parameters for websites and webapps. In this case (website) was looking for codeFile instead of (webapp) codeBehind:
<%# WebHandler Language="vb" CodeFile="Upload.ashx.vb" Class="Upload" %>
Add below tag
<%# Assembly Name="YourNameSpace.YourHandlerClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=90e3045b123af1c3" %>
above your WebHandler tag
<%# WebHandler Language="vb" CodeBehind="Upload.ashx.vb" Class="Upload" %>
Necromancing a thread but I just had the same issue. The suggestion for Assembly Name by #sagar-s didn't work for me. So I tried this and I got a good build (not sure yet about actual functionality) :
<%# Assembly Src="~/MyService.ashx.cs" %>
<%# WebHandler Language="C#" CodeBehind="MyService.ashx.cs" Class="Namespace.MyService" %>
The Src and Name attributes are mutually exclusive. The CodeBehind attribute and Src attribute are redundant. I haven't tried to see if Src will be adequate if CodeBehind is removed. No time to experiment at almost 3am here - or to read docs which may clarify such things. HTH

Creating a Template Item from a web form and auto generating the Inherits page directive

OK, so I'm trying to create a template item from a web form.
I have referenced this article: http://www.west-wind.com/weblog/posts/740022.aspx
and it exports the template and installs it fine.
When you try and use the template item within a project though it leaves the inherits="_Default" in the page directive like shown below:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="FormTemplateDev.aspx.cs" Inherits="_Default" %>
So it thinks all the new template items use the original form name pre-template generation. This is an issue in the code behind too as shown here:
public partial class _Default : System.Web.UI.Page
I have seen example of passing paramater strings through but havent managed to get anything to compile. I found something like below:
public partial class $safeitemname$ : System.Web.UI.Page
Does anyone have any suggestions?
This was the link to the list of available template parameters i found:
Project Template Parameters
OK so It is as simple as this:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="FormTemplateDev.aspx.cs" Inherits="$safeitemname$" %>
and...
public partial class $safeitemname$ : System.Web.UI.Page
It threw me because the page won't compile and the page turns red with rage! This means you will have to put these $slightlystrangeparameters$ in once you have got your template item completed and built. Add the parameters in and export it as a template.
Hope this helps someone else...

Resources