Compilation Error with XDocument - asp.net

I have been working on a website for a car dealer. When getting the website ready to go live we came to the realization that the server they use is set up with the 3.5 framework and unfortunately I had built the site in 4.0 not 3.5. After changing the site over I now get a Compilation Error.
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'XDocument' could not be found (are you missing a using directive or an assembly reference?)
Line 99: //query the database to search for New cars only
Line 100: XDocument feed = XDocument.Load(Server.MapPath("VEHICLES.XML"));
I think the error is that I am calling my assembly references in the code behind file and then calling XDocument within the page itself so I can run the search and then Response.Write the results right onto the page. This works in 4.0 but in 3.5 it seems to not be able to find the assembly. I did not use a repeater for this because I needed to check certain things, such as if the car is certified or not as I list them on the page so I can make changes, this didnt seem to work with a repeater.
If anyone has any ideas on how to fix this error or how to go about it more effectively I would really appreciate it.

Add this to the top of the class...
Using System.Xml.Linq
If you still get the error, add the System.Xml.Linq.dll reference to your project.

Related

.Net Core 3 Asking for Namespace that already exists

Hoping someone can help, ive just updated some nuget packages (from .net core preview to 3) ran a build and now get an error saying:
The type name 'SqlConnection' could not be found in the namespace. This type has been forwarded to assembly Consider adding a reference to that assembly.
As you can see from the image below i have got the names in there. but i believe the grey means that it doesnt think its using it? and im getting the error.
Any ideas on how to fix the issue?
Thanks

Cannot use Linq to sql due to System.Data.Linq being unavailable

I am new to webforms. I am trying to setup a linq to sql connection. I did it the (what I think is) the standard way. I added a linq to sql class. Then I went to my database explorer and dragged a table in and saved. Whenever I try to load the project in the browser I am getting the following error:
The type or namespace name 'Linq' does not exist in the namespace 'System.Data'
I am kind of at a loss here. I googled around. I saw some of the standard solutions like add a reference to System.Data.Linq (which I already had but did again) and to make sure debug="true" in my compilation tag and target framework in my compilation tag was the same as the target framework for the project which I did (both are .NET 4.0). I am still getting the error and I have no clue on how to proceed from here.
The error is thrown on the following line of the Conditions.dbml file:
using System.Data.Linq;
Add a reference to the System.Data.Linq assembly. Right click the References folder in your project, go to Add Reference, then make sure you're on the Assemblies tab and add a checkmark next to System.Data.Linq. (These directions are for VS 2013).

Error when building existing solution in Visual Studio

Hy guys,
I got one existing project from my co-worker. I opened the folder in VS as web site. When I build it and try to run I get the following message-
Warning C:\Users......: ASP.NET runtime error: Object reference not set to an instance of an object.
Error - Object reference not set to an instance of an object.
I have a Visual Studio 2012, registered as student version, target framework is 2.0
Try to check your project reference to load well, not missing reference (you can check in folder "Reference"), or sometime this error because your object is not initialize [blank value], you can add images to give us detail information for your issue.
That is called a Null Reference, you (the code) try to use an object which is not created/initialised yet.
Its impossible to give you an answer which would fix your issue, you will have to debug the code yourself.
When the exception occurs, visual studio should ask you if you want to 'break' or 'continue'. Choose break and check where in the code the error is, then take it from there.
//Example:
AClassofSomeSort myObj2 = new AClassofSomeSort();
myObj2.DoSomething(); //Totally fine, cause the myObj2 have been initialised.
AClassofSomeSort myObj;
myObj.DoSomething(); //Oh noes, the 'myObj' is not created! Exception is thrown.

"WebSecurity" does not exist in the current context error in _AppStart.cshtml

I am getting the following compilation error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'WebSecurity' does not exist in the current context
Source Error:
Line 1: #{
Line 2: if (!WebSecurity.Initialized)
Line 3: {
Line 4: WebSecurity.InitializeDatabaseConnection("AreaProject", "User", "UserId", "EmailAddress", autoCreateTables: true);
Source File: c:\Projects\area\trunk\dotNet\area.Web\area.Web\_AppStart.cshtml Line: 2
enter code here
My project is correctly referencing to "System.Web" and my other files that are using " System.Web.Security" are compiling fine.
The problem started when I added the references System.Web, System.Web.Pages and System.Web.Razor to my application. But I didn't make any change to WebMatrix.WebData or WebMatrix.Data.
The WebSecurity class that is being referenced here is apart of WebMatrix.WebData and not System.Web or System.Web.Security. You probably need to add a reference to WebMatrix.WebData.dll and things should at least get past the runtime compiler error.
You get the compiler error at runtime because views are normally compiled when the application starts up for the first time, instead of when the assemblies are complied.
I'm assuming you are trying to run the MVC4 application first time.
MVC4 adds boatload of assembilies for Internet Application template. It becomes PIA to remove them if you do not use it.
Basically, if you do not use WebMatrix or OAuth to authenticate, you can just comment out everything inside SimpleMembershipInitializer class.
private class SimpleMembershipInitializer
{
// Comment out everything
}
Just for testing, you can also comment out every line inside AccountController that throw exception.
Old thread, but just in case it helps someone down the road. I am not sure why it works this way, but sometimes installing packages like WebMatrix.WebData, WebMatrix.Data is not enough. When I look at the Reference section of my application after these assemblies were installed, WebMatrix.WebData, WebMatrix.Data were still not showing up there, although they were in the BIN folder of the application. I had to literally use Add Reference to make them. Only then, they shown up and everything started working.

Facebook Connect with ASP.NET using Facebook Toolkit

I have done the following steps here http://wiki.developers.facebook.com/index.php/How_Connect_Authentication_Works but I'm stuck at number 8. I've added the DLL's but for some reason this line:
API api = new API();
always comes up with this error:
Compiler Error Message: CS0246: The
type or namespace name 'API' could not
be found (are you missing a using
directive or an assembly reference?)
I am actually almost done with the article in DEVTACULAR and its pre-requisites. But somehow I am stuck with this problem.
Need help badly. Thanks :)
You have to import Facebook.Session by putting the following at the top of your class:
using Facebook.Session;
You could also just use the fully qualified name like:
Facebook.Session.Api api = new Facebook.Session.API();

Resources