Visual Studio 2012 Web Express Compile Project with EDMX - c#

I created a project in Visual Studio 2012 Web Express. After that I included an EDMX file and updated it with database generated models. Now when I perform a build, Visual Studio lists down alot of errors all relating to the piece of code I have written below.
The compiler points the following as errors When I open the Model class. This is the auto generated model class.
namespace Mvc
{
using System;
using System.Collections.Generic;
public partial class MyTableName
{
public MyTableName()
{
The moment I move using statement outside the namespace as follows, the errors get resolved.
using System;
using System.Collections.Generic;
namespace Mvc
{
public partial class MyTableName
{
public MyTableName()
{
I havent faced this issue before and what I performed is simply out of the box. Any clue whats going wrong?

Oops! Looks like the database had a table with a reserved C# class name. Issue Resolved.

Related

RootNamespace not being used as namespace prefix

I recently created a new .net6 project and moved my source code into it.
I've set the following in the project file
<RootNamespace>$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
In the project properties there is a section at the bottom of Application -> General there is a "Default namespace" which also has "$(MSBuildProjectName.Replace(" ", "_"))"
For the sake of this question I have omitted the solution completely and let's assume my project structure is as follows
MyProject (this is a project with project file MyProject.csproj)
DB (this is a folder in the project)
MySQL (this is a sub-folder under the DB folder)
MSSQL (this is a sub-folder under the DB folder)
UI (this is a folder in the project)
If I add a new class at the root level of my project it's namespace is MyProject however if I add a new class to DB it's namespace is DB.
I expect this to be MyProject.DB
Similarly if I add a new class to the MSSQL project I get a namespace of
DB.MSSQL whereas I expect this to be MyProject.DB.MSSQL
I have tried hard coding the $(MSBuildProjectName.Replace(" ", "_")) as MyProject but this doesn't help.
As strange as this sounds, the problem was with WebView2 version 1.0.1343.22
Updating to version 1.0.1370.28 resolved the issue
I did also recreate this in a fresh solution with only 1 project and no other dependencies to ensure that is the case.
Interestingly the default using statements are also different.
With version 1.0.1343.22 installed, creating a new class file you get
using System;
using System.Collections.Generic;
using System.Text;
namespace DB.MsSQL
{
internal class Class1
{
}
}
Whereas with version 1.0.1370.28 a new class file looks like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WebView2NamespaceIssue.DB.MsSQL
{
internal class Class2
{
}
}
Both of these classes were created in the same folder of the same project.
The only difference was changing the version of WebView2 being referenced

EB GUIDE Studio extension doesn't work anymore after switching to version 6.8

I tried to migrate an extension from Guide 6.7.3 to 6.8. Compilation did work without any changes, but the DLL is not loaded anymore.
It looks like the DLL is not even loaded, breakpoint in main constructor is not hit and Visual Studio claims that there are no symbols available.
Same version works correctly in Guide 6.7.3.
Stripped down minimal version which shows the problem:
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Xml;
using Elektrobit.Guide.Studio.Workbench.ViewModels;
using Elektrobit.Guide.Ui.ViewModels;
using Elektrobit.Guide.Utilities;
[Export(typeof(IMenuItemProvider))]
public class TestMenuProvider : IMenuItemProvider
{
public string MenuId => "test";
[ImportingConstructor]
public TestMenuProvider()
{
}
public IEnumerable<IMenuItemViewModel> CreateMenuItems(object context)
{
return null;
}
}
Constructor TestMenuProvider() is run on 6.7.3 but not 6.8.
The example code works fine for me.
However, I stumpled upon a similar issue, so this might help you:
As they switched from x86 to x64 with version 6.8, I could imagine you may have missed to update the build settings of your extension project.
In the project properties of the Visual Studio project, head for Build -> Platform target and make sure it is set to x64 for all build configurations.

DataClassesDataContext Not Found - VS2012

I'm doing a project in ASP.NET and I'm using Visual Studio 2012 with .NET 4.5.
I've been searching online for my problem but haven't found any solution yet. Maybe anyone here can help me.
I'm working on a project and started with an empty Web Application. I've added a folder "App_Code" in which I put my Models and DataClasses. I've added a LINQ-to-SQL class with the correct tables and saved this file in the App_Code folder.
Now, when I add a Class to the App_Code folder, the class can't find the DataClasses.
This is the code of my class "Product" in the folder App_Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Outside.App_Code
{
public partial class Product
{
private static OutsideDataClassesDataContext db;
public static List<Product> GetAll(int id)
{
// Init the DB
db = new OutsideDataClassesDataContext();
// Get all the products and return
return db.Products.Where(a => a.id > 0).ToList();
}
}
}
Visual Studio won't let me run the code. I get this error:
The type or namespace name 'OutsideDataClassesDataContext' could not be found (are you missing a using directive or an assembly reference?) \App_Code\Product.cs 10 24 Outside
The build action of the file Product.cs is "Compile".
Can anyone help or give advice about this? Or try to help get the DataClasses recognised? I'm still learning ASP.NET. If you need other data or other code, just tell me.
Thanks in advance!
I've removed everything from the folder App_Code and made a new folder called Models. Placed everything (class Product and a new OutsideDataClass) in the folder Models and suddenly it works. Weird.
App_Code seems like a bad idea.
Firstly, make sure you have Linq to SQL added manually from the Visual Studio installer.
It will be under 'Individual Components'
The error is looking for the Linq dbml file that makes a generic version of the database you are connected to, to add this dbml right-click on your solution/project;
Choose Add New Item, then under Data, choose Linq-To-SQL Classes . This will create an empty DBML file. You'll then need to create a server connection to a database (if you have not already) and drag the tables you want into the DBML designer.
Looks like your OutsideDataClassesDataContext() is
in another namespace or in another project of your solution.
Try to shorten your namespace name to Outside
or add reference from project, where your class exists.

C# Connect database to Visual Studio project

I have just started studying databases and now I'm trying to connect to a SQL database with Visual Studio. I made the main model. There are tables and stuff. Now I created a console application. I made reference to the project with the data (where the diagram with tables is). But when I try to compile the project I get this error
error CS1502: The best overloaded method match for
'System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction(string,
params System.Data.Entity.Core.Objects.ObjectParameter[])' has some
invalid arguments
and this error
error CS1503: Argument 2: cannot convert from
'System.Data.Objects.ObjectParameter' to
'System.Data.Entity.Core.Objects.ObjectParameter[]'
And on the other project with the data I get this error
error CS0006: Metadata file 'C:\Users\United\Documents\Visual Studio
2012\Projects\C#\EntityFrameworkDemo.Data\EntityFrameworkDemo.Data\bin\Debug\EntityFrameworkDemo.Data.dll'
could not be found
I couldn't find a solution to any of the errors. Can you suggest something?
Here is the sample code that I'm trying to run:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EntityFramework;
namespace EntityFramework
{
class Program
{
static void Main(string[] args)
{
NorthwindEntities db = new NorthwindEntities();
foreach (var customer in db.Customers)
{
Console.WriteLine(customer.ContactName);
}
db.Dispose();
}
}
}
It looks like you have conflicts between the types defined in the Sysytem.Data.Entity assembly and the EntityFramework assembly. If you're using EF 6 or later, remove all references to System.Data.Entity and try recompiling. You may need to remove some lingering using statements for those types as well.

namespace or class could not be found (ASP.NET WebSite "project")

I am currently trying to cleanup a bit of a corporate website that I inherited here. I managed to clean up most of the errors in the website but something is still up here.
I have one masterpage that have this code :
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class MasterPage : System.Web.UI.MasterPage {
public lists m_listsClass = new lists();
(no it's not a typo the S in lists).
Now in App_code I have one class lists.cs
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
/// <summary>
/// Summary description for lists
/// </summary>
public class lists
{
public lists()
{
When I try to build the website in visual studio 2008 I have this error :
Error 3 The type or namespace name 'lists' could not be found (are you missing a using directive or an assembly reference?) C:\Users\egirard\Documents\Visual Studio 2008\Projects\iFuzioncorp\iFuzioncorp\Masters\MasterPage.master.cs 23 12 iFuzioncorp
Am I missing something ?
Also I saw some strange behaviour on the server. Apparently according to IIS7 it is compiling using .net 2.0 (the pool is configured with .net 2) but there are some "using" statements that include Linq ... how is it possible to compile the page if Linq is not part of the .net 2 itself ?
Just edited with news details on the code itself. No namespace at all everywhere.
Hi There – i had a similar problem; all my namespaces and inheritance was in place. Then i then noticed that the class file’s build action was set to “Content” not “Compile” (in the properties window.
For whatever worth might there be for an answer (possibly not the right one) after many months, i think i should contribute this:
There is a case that this happens, when you place a web site inside another (ie in a subfolder).
In that case, the only App_Code folder that is legitimate is the App_code folder of the outer web site. That is, the App_Code folder right under the root of the master web site.
Maybe (say maybe) there should be no need to transform your web site to a web application, if you place the class file inside the App_code folder of the ROOT web site.
include the namespace under which lists calss is defined
or
define both the master page and lists class under the same namespace
Finally I understood quite lately that it was a website and not a web application I had to question the guys here to get it... So it's quite normal all the error I had. I haven't had the occasion to convert it first.
Make sure that in your masterpage, you have an #include statement for the namespace that the lists class is a part of (if they're in seperate namespaces, the masterpage isn't going to automatically pick up on it).
As for the strange server side behavior, .NET 2.0, 3.0, and 3.5 all run inside of .NET 2.0 app pools in IIS. It looks strange at first, but you get used to it. Here's a link with a little more in-depth explination:
The Way I See It: Where is ASP.NET 3.5 on IIS?
In order to use a type, you must reference the assembly which defines it and include the appropriate namespace.
Using only includes namespaces, if you don't use any types from said namespaces it has no effect.
is lists.cs wrapped in a namespace? if it is the case then you need to add the namespace (yournamespace.lists) or include it in masterpage. Check Also if your MasterPage is in a Namespace
Modify the Build Action of the App_Code Class to Compile.
Clean and Build the Project
This worked for me.
I had this problem myself
It wasn't working because the project I was referencing was set as a console application in its properties instead of a class library

Categories

Resources