First of all, I know ASP.NET MVC, but have very little/no experience with Web Forms. I inherited a site today that is a Web Forms site. Once I got to looking at it, it was quickly apparent that the .cs (code behind) files that go with the .aspx files are missing (or hidden somewhere). I get an error page in the browser when I try to build because the files are missing. The curious thing is that the live site is totally fine...so surely those files exist somewhere?...or maybe you don't need them?...like I said, today is my first day trying to tackle an old Web Forms site.
The files are not present in the local directories nor in Visual Studio. Am I missing something...am I crazy...am I just a newb? I attached some pics.
Related
I am working on an ASP.NET Web Forms site that is written completely in C#. All initial page loads in one subdirectory cause the VB compiler to run. Oddly, page loads in that directory's subdirectories do not cause the VB compiler to run.
There are no elements in the Web.config.
This happens in every solution that includes the project.
None of the Microsoft.VisualBasic assemblies are referenced in the project
Is there a setting somewhere that I can change that will disable VB compiler?
Could this be due to a referenced assembly used in this folder but nowhere else?
Since there seems to be some concern with the validity of this question, I and another senior developer have spent about 10 hours trying to run down this problem. We have searched the code base, visual studio, and online for an answer but it appears to be unique enough that no one has brought it up.
Additionally, when the same code is put in a different directory, the VB compiler does not run on initial page load. This is what leads me to believe there is a setting somewhere that I am missing.
Every time I've seen this, it's because of a "badly"-compiled file that exists in the folder structure (not even necessarily the csproj).
Check the folder structure of the pages in question, see if there's a bad file located somewhere in there. You may have to Show All Files in Visual Studio.
Delete it with extreme prejudice.
I have a Website Solution and I want Convert it to Web Application.
When I Transfer Base files (like DAL,BLL(.cs files my mean)) and Build My Solution it's working.
But When I Add other files that use the Base Files I have Many Errors Like (CS0246,CS0103,CS0118,CS1061).
I see this answer like:
https://msdn.microsoft.com/en-us/library/w7xf6dxs.aspx
and
Why am I getting error CS0246: The type or namespace name could not be found?
I want to Know if I build My Solution and Visual Studio Create .dll files why I have error that say not found X.dll? and how can it be fix?
You will have to go through and fix each error in turn as you migrate.
https://msdn.microsoft.com/en-us/library/aa983476(v=vs.100).aspx
I usually create an empty Web Application project and then copy the output into the same folder as my Web Site. Then I open the web application project in tye same solution as my website. Now you have two Projects for the same location.
Now enable the "show hidden files" option and "include" all the files in your project. At this point you will get loads of errors... Make sure that you first right-click on the root of your Web Application and select "Upgrade to Web Application" as this will do much of the grunt work for you.
In Web Applications you get Partial classes and when generated they are clashing with each other. In a Web Site you can have duplicate namespaces and class names, in a web application you can't. You need to go through all of your *.aspx and it's associated files and rename all of the class snakes to be unique.
This will start removing the errors although it may take some time to get through them all.
I have just started using SharpDevelop and I am trying to convert a Visual Studio Express website project into a SharpDevelop one. I managed to create the solution fine and the project within it. This is a C# ASP.NET webforms project by the way. Just simple aspx pages with C# codebehinds and an .asmx webservice in there. Nothing special and in fact quite old fashioned stuff, which worked fine in Visual Studio.
I am liking the SharpDevelop environment so please don't answer with "why not use Visual Studio instead" (I have reasons). But here is my problem:
SharpDevelop is not linking the .aspx files with their .aspx.cs counterparts. So instead of the solution explorer showing MyPage.aspx which you then expand to see MyPage.aspx.cs under it, you see them as two distinct separate files next to each other and unrelated.
And when I compile the solution I get an error because the codebehind can't tie itself to the aspx page and doesn't recognise the control names. (Example below is from my Contact.aspx page but it happens on every page where I have any server-side asp.net control).
The name 'EmailAddress' does not exist in the current context (CS0103) - Contact.aspx.cs:52,100
Now keep in mind this never used to happen in Visual Studio, so something has gone wrong in my SharpDevelop solution. The error occurs anywhere in the codebehind (.aspx.cs file) which refers to:
EmailComments.Text
Things I have already checked:
1) The #Page directive is correct and the Inherits name matches the class name.
2) The .cs and .aspx filenames and class names all match.
3) The .net framework version is 4.5 (does this make a difference?)
4) I have tried explicity declaring the asp.net controls in the codebehind and yes this prevents the error however the link between files remains broken and why should I have to declare the control in the codebehind anyway? Never used to in Visual Studio and it worked fine there.
Wierdly there is one file in my entire solution which does not have this problem (the aspx and aspx.cs files are linked fine) and this is the default.aspx page. There is nothing different about it. The only thing I can see is that it's a lowercase filename whereas the others are mixed case. (Surely that's not relevant?)
I would really appreciate help from anyone familiar with SharpDevelop or if it's a more general .net issue then please tell me. I feel as if there is some basic thing I am forgetting that will make this work.
Thank you very much for any help.
UPDATE: I have managed to link the .aspx and .aspx.cs files by doing the following: Drag and drop the .aspx.cs file on to the .aspx file in the solution explorer. Do this for every pair of files. Then save and close the solution and re-open and they remain linked. BUT, the error remains as per above because the codebehind does not recognise the controls referred to in it.
You may have a website or a "web application" project. There are differences in how code-behind is wired up between the two. Most importantly you may need CodeBehind instead of CodeFile attribute in your page directive. See http://msdn.microsoft.com/en-us/library/vstudio/dd547590(v=vs.100).aspx#summary_of_differences
Hope this helps.
I have created webservice and published it on local machine. Then I have uploaded it on server.
Now while I tried to access webservice it gives following error :
Parser Error Message: Could not create type 'webservice.myservice'
Source Error:
Line 1: <%# WebService Language="C#" CodeBehind="myservice.asmx.cs" Class="webservice.myservice" %>
I tried This link but unable to solve my problem.
What should I do?
I don't know if this is dragging something up from the dim and distant past, but I had this problem. I fixed it. So I thought I'd to share it.
When you create a web service in Visual Studio (I'm using 2010 but I'd imagine it's the same for others), it creates a file called Service1.asmx
You will be tempted to rename it to MyService.asmx (or whatever).
Then you'll look inside and see the line
public class Service1: System.Web.Services.WebService
which you'll change to
public class MyService: System.Web.Services.WebService
and then when you try running it, you get the error
Could not create type 'MyProject.MyService'
Because it still thinks the class is called Service1.
If you right click the .asmx file and select view markup, you'll see it still says:
<%# WebService Language="C#" CodeBehind="MyService.asmx.cs" Class="MyProject.Service1" %>
change it to
<%# WebService Language="C#" CodeBehind="MyService.asmx.cs" Class="MyProject.MyService" %>
save it, try it.
It worked for me.
I had the same problem and looked for it for a long time!
I tried a lot of things including the following:
Frameword version incorrect
A whole list of things that could be wrong
None of those worked for me. After some searching, testing and cursing, I finally found the problem: The application (webservice) was incorrectly hosted.
Let me explain with a little background:
I had a project containing two solutions: One solution was the website that I made (html, javascript, etc), the other solution contained a folder with the business logic, the database model and the webservices. Obviously the webservices folder contained my .asmx files and code-behind for them.
Project
Data Core
Database Model
Business Logic
Webservices
myWebservice.asmx
Website
I was hosting these in the following way:
My website was hosted as a new site with the website folder as root folder
My webservices I was hosting as an application in my website, with the webservices folder as root
More visually:
IIS 7
My Website => Pointing at the "Website" folder
Webservices Application => Pointing at the "Webservices" folder in the Data Core
This resulted in the following url "http://website/webservices/myWebservice.asmx", which gave me the "Could not create type" error.
Now, after playing around a bit I tried hosting my webservice application starting with the data core as root, instead of the webservice folder.
Visually:
IIS 7
My Website => Pointing at the "Website" folder
Webservices Application => Pointing at the "Data Core" folder.
Obviously using the same url as before would give me a "File not found" error. However, using the following url "http://website/webservices/webservices/myWebservice.asmx",I finally got my working webservices page!
A small url breakdown:
http ://website/ => My website from the "Website" folder
webservices/ => Equivalent to the "Data Core" folder
webservices/ => The "webservices" folder in the "Data Core" folder
myWebservice.asmx => The webservice file in the "webservices" folder, in the "Data Core" folder
I assume that because I was hosting my webservices directly from the "webservices" folder in the Data Core, that the server could not find the compiled DLL of the webservices (which resides in the "bin" folder), since I was hosting at a deeper level.
After changing the configuration and hosting the webservices from the "Data Core" folder, the IIS server could "see" the bin folder and host the webservices succesfully. When using the correct url that is ^_^
I hope this is clear and helps you with you problems!
Another thing that can cause the problem. Is not creating an application for the project through the IIS itself. If the code is already on the server navigate to it in IIS from the left Connections pane. If the web site directory is still a yellow folder icon (and not a globe icon) you need to right-click on it and choose Convert to Application otherwise follow these steps...
Start -> Search For IIS
Open It!!
Right Click on the Default Web Site or the web site you are planning to publish the service to it.
Add application... Enter an Alias ex. "MyWebService" ... Choose the physical path. in my case was C:\inetpub\wwwroot\MyWebService which is my default web site path.
Then when you publish through Visual Studio choose that folder. or just copy your code files to it.
I'm fairly certain this is just a summary of what Glenn said, but I ran into this issue because my application was created from the directory one level too high in the directory structure.
For example, my web service was in SiteProject_1/SiteProject_2/service.asmx
Originally SiteProject_1 was what I converted into the application within IIS. I was able to resolve the issue by removing that application within IIS and instead making SiteProject_2 into the application.
I was having this problem this morning and Google landed me here, but none of these answers worked for me. But I did figure out what was wrong - at least in my case - so I thought I'd share it in case it helps others.
I had a web service that had been working fine for months in a solution with other parts of the application that I work on. Yesterday, I needed to fix something in a release branch, so I opened Visual Studio on a copy of the solution in another directory. Visual Studio decided to be helpful and silently remap all my virtual directories in IIS to where the programs would be in the release folder (if I had bothered to build them, which I hadn't). Now when I tried to hit my web service, IIS was pointing to the release version which had the asmx but no bin folder.
Opening the Web properties tab in my development solution and clicking the Create Virtual Directory remapped it back to the development version and all was good with the world again.
I have a web site where any new aspx pages throws a "Parser Error". It has existing pages, and I can change the html or the c# code in it, and the change will appear in the web page in the browser.
The error page gives a message of "Could not load type classname". I've tried adding several different pages in Visual Studio, and copying the pages to IIS, so the syntax of the page should be fine.
I;ve also made sure that the "Inherits" attribute has the correct class and the class exists. I'm completely stuck.
Have a look at the Directive at the top of the page. Does it have a CodeBehind attibute? If so change it to CodeFile, and try the page in the browser again.
If that doesn't work, compare the top part of a non-working page and a working page. Would be a little easier if you could post the top parts of the page here.
One thing that popped to mind immediately is to make sure that the target version of the .NET Framework for your web site is the same as the one specified for the application pool in IIS in which the site is running.
Right-click on the web site in Visual Studio and check the "Target framework" setting. Make sure this matches the ".Net Framework version" setting in IIS.
Are you using any usercontrols? Is your project set up as a web Application project or website?
If you are developing a web application project and you copy a new file or add a page without using the add new by right clicking you may have some page files that lack their designer files.
If that is the case then I suggest right clicking any page missing the designer file and click "Convert To Application" Then rebuild your solution