Errors when including Entity Data Model across referenced projects - asp.net

Decided to take a dive into recreating a website so that it's an ASP.NET MVC web application. We were originally using the Entity Framework for it, figured to still use it since it works nicely enough. When doing some reading, noticed the there is no such thing as the App_Code/ folder for MVC applications, and that most people were creating a class library for their needs like that. So what I ended up doing was creating my MVC application and a class library, both in the same solution, and the MVC application was referencing the class library. The class library has my EDMX Entity Data Model file in it since some of my classes reference it and I thought that it would be easiest to have it in the library to reference. So here is a picture to what my solution layout is. But when I build and run the website, I get an error on a page that would reference the Entity Data Model. Here is a picture of what the error is.
So I thought, what if I placed the EDMX into my models folder since the error looks like it's complaining about not finding the entities. Here's a picture of my solution now with the move. But now, I'm getting a different error (picture). I'm kind of at a loss as to where to go from here. Is the way I have everything laid out and designed the proper and most efficient way to do it? If not could someone give me some advice?
Thanks, it's really appreciated!

Yes, you should be able to have the edmx in a class library and reference if from your main project. The first error is likely due to an incorrect connection string (check this blog post) but you may also have changed the build action of the edmx file somehow, make sure it is "Entity Deploy".
The second error is probably because you copied the edmx from your class library into the Models folder and it is still referencing the old namespace. To fix that, open the edmx in designer view and click on the background. One of the properties in the property window is Namespace, make sure that's set to the new place you want to keep it.
Edit:
Some things to try:
Clean and rebuild the project
Delete the Temporary ASP.NET Files folder referenced in the error message
Double check your cshtml files for old references to URG_MVC.Models namespace. For example, the line in the error should be IEnumerable<URGLibrary.Proposal>
Right click the edmx file and select Run Custom Tool to regenerate the model files

Related

Cannot add Controller to asp.net Core MVC Project because of error: The specified runtimeconfig.json does not exist

I am trying to learn about the MVC structure of Asp.NET core MVC.
Therefore, I am trying to build a small web app similar to the ecommerce system 'simplcommerce' whose code is open source.
My Solution is split into three parts:
1. Modules
2. Infrastructure
3. WebHost
In the Modules part, I have five different Modules (e.g. Contacts, Core) which have their own Controllers, Models, ViewModels and Views.
Now I am trying to add a new Controller into the Contacts Module.
I have already added two Controllers earlier, which was no problem at all.
But after having changed lots of things (like adding and deleting dependencies, adding Models and Views, etc.) I receive the following error-message when trying to add a new Controller:
"There was an error running the selected code generator:
'The specified runtimeconfig.json [C:...\TestApplication\TestAppplication.Module.Contacts\bin\Debug\netcoreapp2.0\TestApplication.Module.Contacts.runtimeconfig.json] does not exist. "
I have checked the folder from the error message and there is no TestApplication.Module.Contacts.runtimeconfig.json.
But I have also checked the same folder in the original SimplCommerce solution, which I have copied parts from, and there is no such file either.
Where is the file from the error message specified?
And what can I do to solve this problem?
Thank you very much in advance!
This file is automatically generated by Visual Studio when you build the project. Interesting thins is that when I removed this file and added new Controller to my test project, this file appeared although I haven't built the solution. The issue looks like your project cannot be compiled.
Make sure that the project does not have any compile-time errors and try to rebuild it before you add the Controller.

Copying/Moving App Code to New Project

Ok, I am in the process of breaking apart of intranet application (VS 2010 Web Site, ASP.NET Web Forms with VB code behind). During this process i'm trying to convert some of our our app_code files in to WCF rest service in a new project. However, when I copy or "add existing" vb files into the new "services" project. I get tons of errors including...
error BC30002: Type 'XXX' is not defined
warning BC40056: Namespace
or type specified in the Imports 'System.ServiceModel' doesn't
contain any public member or cannot be found. Make sure the
namespace or the type is defined and contains at least one public
member. Make sure the imported element name doesn't use any aliases.
From what i've read it may (or may not) have something to do with Assemblies and references that I just have very little knowledge on. I have added the namespaces from the current web.config to new project's web.config, and the files are identical. So there is something in the background that needs to be added to the new project I just don't know what its.
PLEASE HELP!!
THANKS
JOSH
UPDATE 1
So one of the errors i'm getting = "error BC30002: Type 'MailMessage' is not defined." Which is a namespace that is added to the web.config, which apparently isn't being picked up??? IDEAS?
I've come across a similar issue - not sure what the reasoning behind it is, but I got around it by creating a new .vb class with the same name as the one you want to copy, then copy and paste all the text from the old one to the new one. Save it, then it seems to like it - it didn't like me copying and pasting the actual file, nor did it like me adding existing files.
Hope this helps :/
This issue seems to be tied to the the differences between Web Application Projects versus Web Site Projects. Eventually I had to add different namespaces on the new project level.
Here is more info about WAP vs WSP....
http://msdn.microsoft.com/en-us/library/dd547590(v=vs.110).aspx

MVC conversion project, fully qualified classes are not available unless 'Global' is added or System... is removed

My question is similar to here: ASP.NET System.Anything is not defined
I am in the process of converting a website project to an MVC 4 project. To do this, I created a new MVC project and imported all of my content from the previous website. Both projects are in VB, and I'm using Visual Studio 2010 SP1, with both the MVC 4 update and TFS 2012 update applied.
I now have errors popping up when I build the MVC project. Things like "Type 'System.Web.UI.Webcontrol' is not defined." When I hover over the error, two of the prompts I get to fix it are
1) Change 'System.Web.UI.WebControl' to 'Global.System.Web.UI.WebControl'
2) Change 'System.Web.UI.WebControl' to 'WebControl'
Both of these seem to fix it, but does anyone know why I can't use "System.Web.UI.WebControl" to refer to this class? I'd rather not change all of my code... there are 100s of thousands lines in there.
Update: Outside of the System and System.Web.UI namespaces, I can also drop the 'System.'. So 'System.Drawing.Color' would become 'Drawing.Color'.
There exists another namespace containing System in your solution somewhere (e.g. Abc.System.def) - probably in a referenced library. After the conversion, the project file probably imported the prefix to System in said namespace (e.g. Abc), so when you type in System, it resolves to Abc.System.
I posted this question before I had whittled down as much of the compile errors as possible.
It appears that after I had removed all the System. references from the previous App_Code classes, the real errors started appearing. There were all sorts of messages about aspx controls not existing.
Ultimately, it seemed that I needed to right-click on the .aspx pages from my website project and choose 'Convert to Web Application.' This generated a .aspx.designer.vb file with the asp.net control declarations in yet another partial class.
After doing that for all pages, I am now able to use System. throughout the app.
To others who've asked, this System. error was only affecting the non-page code. .aspx, .aspx.vb, .ascx, .ascx.vb, .ashx, etc., files were not affected.
This does make some sense, anyhow, as I had previously pulled in all the App_Code libraries prior to pulling in the pages, and the site compiled. After importing the pages and their code behinds, the order of the errors was just odd. But I stuck with it and found the underlying cause.
Thanks for the willingness to help. If you have any other questions, I'd be glad to respond.

Using nAnt to build projects containing EDMX

I've been working on training myself in the ways of using nAnt over the past few days, and have stumbled across an issue. During the development process, I've been using the new tools, like Entity Data Model, for database access.
When you go to try to build a library/executable that contains the Edmx product, you cannot embed the required files from visual studio. Now, I realize that I can do an exec task inside of nAnt and call msbuild for the particular project file, but I am trying to keep this to be completely nAnt build for now, so I'm in a heavy struggle to get things to work.
I did some searching to find a way ot handle this, and came across this Inline C# class that is supposed to do the trick. My problem is that I do not see how you call this in the target stack in order to get it to do its job. Can anyone shed some light on this? It would be of some great help.
Ok... so I'm a bit further along with this. I have since found that the code the gentleman has posted needs to be under the task for which it is meant to be run for. I'm even getting the *.ssdl, *.csdl, and *.msl files rendering into the directory... cool beans.
nwo i'm getting something interesting coming through... I've got reference via a "references" tag to System.Data.Entity, but I keep getting the following compile error:
error CS0234: The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
Any suggestions?
OK!!!
Got it! I had to edit the NAnt.exe.config file and add the System.Data.Entity.dll file into the Framework element for the .net framework 3.5!!!
I may wind up building a 3.5 SP1 entry, and if someone can give me a good area to post it, I'd be good to go.

Casting error in ASP.NET

I have a class declared in the App_Code folder. The class contains a public shared method that returns a type Portfolio.
When I try to call this method to initialize an object of type Portfolio in one of the ASCX controls, i get a "Value of type Jaguar.Portfolio cannot be converted to Jaguar.Portfolio" message.
This is a "Website" project. I have tried using CType and DirectCast and I still get the same compilation error when I try to build the site.
I am using the line of code listed below in the code behind file of the ascx control
Dim pObjSvc As Jaguar.Portfolio = ClassName.GetPortfolio
Do you have a webpage or a user control also called Portfolio? You may have a name space collision where it's confused between which Portfolio object to use. If this is the case, you'll need to change the name of the Class/Module or the control's or page's code behind class and you should be all set.
There seems to be someone else with the same problem out there:
ASP Net - value of type "MyNamespace.MyClassName" cannot be converted to "MyNamespace.MyClassName"
I have a ASP.Net application that uses
assemblies from several other
solutions. When testing the
applications on my machine I build all
the referenced assemblies using nmake.
The latest assemblies get placed in a
common directory that is referenced by
my ASP.NET app.
Occasionally I receive the following
error: value of type
"MyNamespace.MyClassName" cannot be
converted to "MyNamespace.MyClassName"
(there are a lot of these for
different classes) when doing a debug
build. I have tried the following with
no luck:
Build the ASP.Net application Rebuild
the ASP.Net application Close VS and
build the ASP.Net application Close
VS.Net as rebuild the asp.Net
application IISreset and build/rebuild
the application
It seems the only thing that works is
if I run nmake to build all my referenced assemblies, I can then
build the ASP.Net application.
Any ideas as to what causes this? Is
there an easier way to fix it?
Sadly, the author of the question did non find a definitive answer. But perhaps it contains a hint which could be helpful to find the solution.
UPDATE: I'm not sure if that is even possible in a ASP.NET website, but maybe you accidentally added a reference to a (temporary) assemmbly of the project itself? That would explain the error. Try also to remove the contents of bin and obj folder.
Just a debugging tip:
Try to rename the Portfolio class and recompile. Maybe there is an old assembly somewhere or some other code in .vb your files which contains a class with the same name?
I have seen situations similar to this when an aspx page was created with the same name as a business object class. Do you have some some aspx page with a code-behind class of Portfolio as well?

Resources