Link to home
Start Free TrialLog in
Avatar of mathew_s
mathew_s

asked on

Error when building default page (The file 'src' is not valid here because it doesn't expose a valid type)

Running a C# project in VS 2010. The project has a master page. When I attempt to build the default page, I get the following error.
The file 'src' is not valid here because it doesn't expose a valid type.

Default Page:
<%@ Page Title="My Test" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
I found if I take Masterpage reference out (MasterPageFile="~/Site.master") of the default page then the error goes away when I build the default page. The funny thing is if I build just the Masterpage there are no errors on that page so not sure what this error is complaining about?
 
Master page:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster"%>
Avatar of mathew_s
mathew_s

ASKER

Get this error when building any page that inherits from site master. I wonder if the problem is that you cannot build the child page by itself if it refers to a master page?
Avatar of Bob Learned
If you have a master page, then it has the full HTML along with ContentPlaceHolder elements, and the child pages don't have the full HTML, but only the related Content elements.

I am thinking that there is an error in the master page.  Do you have any @Register lines anywhere?
Maybe this will help.

I assigned a value to AssemblyCulture before, and when I set it to empty again, the error was gone.
Randy - I check the assembly culture in the assemblyinfo.cs file and it is the following:
[assembly: AssemblyCulture("")]

So it appears empty to me.

Bob - Yes I have Register lines in the pages. So for example one of the pages that doesn't build has:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" ClientIDMode="AutoID" CodeFile="TemplateAdditionalWorkdownDetails.aspx.cs" Inherits="TemplateAdditionalWorkdownDetails" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<%@ Register src="Controls/TemplateMilestoneWorkPeriod.ascx" tagname="TemplateMilestoneWorkPeriod" tagprefix="uc1" %>

Open in new window


I also have an error message about an unknown server tag on this page uc1:TemplateMilestoneWorkPeriod here:
<uc1:TemplateMilestoneWorkPeriod ID="TemplateMilestoneWorkPeriod" runat="server" />

Open in new window


See attachment for the errors on this page.
Capture1.GIF
It is really odd, because I can rebuild the project without issue though I occassionally get an error of "the application domain in which the thread was running has been unloaded." When I get this error I just rebuild. I can also publish the page but I cannot publish when I select the option allow this precompiled site to be updateable. I get an error saying Object reference not set to an instance of an object with no line number, nothing telling me where the problem is.
Sorry Bob didn't read your message properly. The master page does have one register in the page.

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

Open in new window


The Telerik.Web.UI is showing in the bin folder.
I can also build the master page without error.
I looked at this line, and one thing might be the line is case-sensitive.

<%@ Register src="Controls/TemplateMilestoneWorkPeriod.ascx" tagname="TemplateMilestoneWorkPeriod" tagprefix="uc1" %>

One place I read suggested that this error is related to a @Register line with a "src" being incorrect.

Try this, with corrected case:

<%@ Register Src="Controls/TemplateMilestoneWorkPeriod.ascx" TagName="TemplateMilestoneWorkPeriod" TagPrefix="uc1" %>
Tried changing every src to Src but error still occurs. See screenshot.
Capture2.GIF
I had changed the case on the entire @Register entry, but I see that you only changed the "Src". Try changing the "TagName" and "TagPrefix" attribute also.  

I have had problems in the past when moving from ASP.NET 1.1 to 2.0, since the Codebehind attribute became CodeBehind.
OK went in and updated all the register entries in the solution so it is proper case, Still same error.
Capture3.GIF
Well, it was worth a shot.

1) Are your user controls in the same assembly as the web page?

2) Try to reference ~/Controls/TemplateMilestoneWorkPeriod.ascx

3) Clean and rebuild solution
The problem is not that I can't rebuild the solution, actually I can and I don't get these errors showing up oddly enough.
Problem is that if I attempt to publish with the option of allowing the precompiled site to be updateable I get the error:

Object reference not set to an instance of an object with no reference to a line number or file.

When I take off this option and publish it works fine but then the problem is I get an error message from the webpage when i launch the site that says the default.aspx has not been pre-compiled, and cannot be requested.

I figured these errors when building the page was related maybe it isn't.

So anyways
1) Yes I believe they are in the same dll. Both the control and this page are in the same dll.
This was the markup again for the aspx page.

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" ClientIDMode="AutoID" CodeFile="TemplateAdditionalWorkdownDetails.aspx.cs" Inherits="TemplateAdditionalWorkdownDetails" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Src="~/Controls/TemplateMilestoneWorkPeriod.ascx" TagName="TemplateMilestoneWorkPeriod" TagPrefix="uc1" %>

Open in new window


The control that it is referring to has the following markup:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TemplateMilestoneWorkPeriod.ascx.cs" ClientIDMode="AutoID" Inherits="Controls_TemplateMilestoneWorkPeriod" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

Open in new window



2) I tried to reference it that way, cleaned and built just the page again and same error.
3) See comment above that I can rebuild solution.


Hmm, I am thinking the problem is in my building of the solution that my main web project is not getting compiled properly. If I look in the bin folder of when it says it is successfully published, I do not see a bunch of dlls that I would expect to see from the main project. How to check this?
Here are some screenshots showing how my project is configured to getting built. I noticed my main project which requires the other 3 projects (Data, Services and Business) is showing that it is getting build with DEV configuration?

I don't see a release configuration for that project either.
Capture4.GIF
Capture5.GIF
Capture6.GIF
It sounds like you have a mess on your hands with the configurations.  

1) I am not sure what those images show.  Is one of them for the Build > Configuration Manager screen?  

2) How do you change configuration?

3) How are you publishing the web site?
Yes a mess. I managed to get the release mode showing up in the Configuration Manager screen now by editing the sln file.That was the capture4 screenshot.  I noticed debug was in both the debug and release for the main project.
            {CF45BC6D-242F-4BA8-AA2F-83FF4E895CF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
            {CF45BC6D-242F-4BA8-AA2F-83FF4E895CF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
            {CF45BC6D-242F-4BA8-AA2F-83FF4E895CF8}.Release|Any CPU.ActiveCfg = Debug|Any CPU
            {CF45BC6D-242F-4BA8-AA2F-83FF4E895CF8}.Release|Any CPU.Build.0 = Debug|Any CPU



The other 2 screenshots are from r-clicking a project and selecting project dependencies... and project build order...

I am changing the configuration by clickong on Release in the dropdownlist.

I am publishing the site by clicking on Build->Publish Web Site and then clicking on allow this precompiled site to be updateable. I have tried unchecking this option and it does then publish successfully but the main solution does not seem to compile I think - not seeing the dlls.
What is the output of the Publish Web Site operation?  What is the configuration for the publish settings?
In your master page, try to remove this line:
<%@ Register src="Controls/TemplateMilestoneWorkPeriod.ascx" tagname="TemplateMilestoneWorkPeriod" tagprefix="uc1" %>

Open in new window


And remove the control from your master page, this line:
<uc1:TemplateMilestoneWorkPeriod ID="TemplateMilestoneWorkPeriod" runat="server" />

Open in new window


And do build, if everything went fine then your main problem is in the TemplateMilestoneWorkPeriod user control, try to share the code of this uc

Good Luck
Output of the publish web site operation attached.This is option where I have NOT selected the precompiled site to be updateable and it shows successful but again I don't think it is compiling the main project (C:\...\IOSNet\) at the end. At least I don't see where the App_Web files and App_Code files are.


How to find the configuration of the publish settings? I am simply clicking on Build->Publish web site and pointing to a location on the c: drive.
Build.txt
1) What version of Visual Studio are you using?

2) There should be a Web One Click Publish menu option, but maybe some versions of Visual Studio don't have that option.

3) You can define publish settings, that are stored in a folder under the web project.  Since you are using what looks like the Web Site model, I have no idea where the files get written (I use only Web Application model).
Ammar - user control is not on master page but a child page that refers to the master. Anyways I tried removing uc and still get same issue.
1) I am using VS 2010 Pro
2) Don't see the option
For publish - I don't have a properties folder for the main web project but have it for the Data, Services and Business folder
Since I have Visual Studio 2013, I can't attest to what other versions may or may not have without researching.

Here is a Micro$oft article that talks about the deploy:

How to: Deploy a Web Application Project Using One-Click Publish and Web Deploy
https://msdn.microsoft.com/en-us/library/vstudio/dd465337(v=vs.100).aspx

User generated image
ASKER CERTIFIED SOLUTION
Avatar of mathew_s
mathew_s

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I better clarify when I read my comment...lol
When I say better meaningful comments I mean from Microsoft on error messages. I thank the experts here for there help :)
Ended up creating a new solution and then I imported the files into that and I can publish the files again. Obviously something really messed up in the solution though I still occasionally get object reference not set to an instance of an object. Just clean, rebuild, publish. Wish we could get some better meaningful comments.