I decided to change the name of a folder within "Models->ABC->A" to "Models->ABC->B" Manually.
the problem is, now in the view imports i'm getting old suggestions A but not B. i don't understand where the A is coming from? i cleaned the solution, rebuilt the solution. checked in directory but A doesn't exists there still it shows A in suggestion. it seems when i build the project Visual Studio (2019 Community) is using the same old data and namespaces are out of sync. any idea how to fix it?
The namespace given in the Class is having the old namespace that is Models->ABC->A. Change it to Models->ABC->B.
Related
I am trying to work through this tutorial, ASP.Net Core Razor Pages, but (often) when I build the solution, I get a CS0234 error stating that a namespace is missing from file Index.g.cshtml.cd, but where does this file exist?
I have tried
All the build/clean/rebuild solution options.
I have restarted Visual Studio
I have deleted the DEBUG files and restarted VS and FINALLY
I have restarted my PC.
The ONLY solution that seems to work, is to delete the entire solution/project and start again.
Surely there must be a fix for this?
Can you assist?
If an error says a using directive or namespace is missing from xxx.g.cshtml.cs, that usually means, that there is a directive directly in the view (.cshtml or .vbhtml), that the compiler cannot resolve.
In my case I had the following statement in a partial view:
#inject UserManager<AppUser> UserManager
I then went along and refactored the AppUser class from the web application Namespace.Web.AppUser into Namespace.Entities.AppUser, which then was causing that error.
There are different ways to resolve this.
The easiest way is to use a fully qualified type namespace:
#inject UserManager<Namespace.Entities.AppUser> UserManager
And do not forget to add a reference to the other project, if it is in another project.
Or: add a using statement:
#using Namespace.Entities;
Or: Add the using statement above to your ~\Views\_ViewStart.cshtml. This will make that class available in all views.
I landed here with the same errors with Visual Studio 2019 16.2.2. For me, I had changed the name of some of the models and rather than picking up the error in the actual views which were using the models, the error showed in page.g.cshtml rather than page.cshtml.
So, my solution was rather simple. If the error was in page.g.cshtml, ignore the g, go to the view page.cshtml, update the model name to the correct name, rebuild and errors gone.
right click your project and open folder in Explorer. Then search for "Index.g.cshtml.cs"
Then delete the file search results
Make sure your Index.cshtml is referencing the correct model.
Recently I have faced the same issue,
Try the following simple method
copy the error and paste it in the notepad. There you can able to see the original root cause path of the error file, e.g 'YourProjectFolder'\obj\Debug\netcoreapp2.2\Razor\Views\'View Name'\index.g.cshtml.cs
Locate the file, if the error really persists refer the correct namespace in your index.cshtml file else delete the file and rebuild.
Also check you have any duplicate file and which was excluded from the project. If it is exists delete the file too
Now clean and rebuild the project. (You may need to clean, close VS, rebuild)
If your solutions keeps failing because of those .g .cs files, it could be because you forgot to update the namespace of a class that you may have moved, in the actual cshtml file (example via an injection of the said namespace).
This is what solved the issue for me:
https://til.secretgeek.net/.net_core_MVC/error_in_g_cs.html
you can try below solution
Go to C:\Temp\msbuild
2.There you would find folder with your project name and inside those folder you find these files as shown in below image
Try to delete those files and rebuild your solution that might help you
There is actually no real answer to this question.
It turns out that the file is create inside the DEBUG folder.
However, after deleting the Debug folder, I was still getting the error.
So it must be a VS bug?
Try to clean all the obj folders in all of your projects and build again. This is part of the code that is generated by the compiler, sometimes it is not synchronized with the view itself, even Rebuild that should clean everything doesn't work. Do it manually. Hope this helps
It's Microsoft.AspNetCore.Razor.Design Package issue.
I tried with 2.2 version in my VS2017 which does not support this and gives ".g.cshtml not found" in obj directory.
I solved issue as below:
I downgraded ASP.NET Core version of my project 2.2 to 2.1
Changes done in startup.cs:
CompatibilityVersion.Version_2_2 to CompatibilityVersion.Version_2_1
Change all dll of Nuget packages to 2_1 supportive dll
SDK make sure its 2.1.x
and issue resolved.
Add full namespace in _ViewImports
#using Microsoft.AspNetCore.Http
May be my answer is something late, but hopefully it will help someone:
I have faced the dame issue because I have changed the Project name and later I tried to change the namespaces inside controllers and models, then I found out there is a direct mentioning of the namespace inside (Pages/_ViewImports.cshtml) from there I updated them to match the namespace used inside my models and the issues gone. ViewImportsImage
Now my ViewImports.cshtml content looks as follows:
ViewsImport.cshtml content
I am working in EF 6 and facing the following issue when I try run my project.
Schema specified is not valid. Errors:
Multiple types with the name 'TableName' exist in the
EdmItemCollection in different namespaces. Convention based mapping
requires unique names without regard to namespace in the
EdmItemCollection.
I tried too much on StackOverFlow and google and found no solution. I am using visual studio 2012. I crated a single .edmx file for whole of my database. I searched the tableName throughout the project and there is single occurrence of table.
Please help me in this regard
Finally I figured out the solution of the problem.
In my question above, I stated that I have only single edmx file in my project. It is true in one sense. But wrong in the other sense.
I am using git to manage my code. I created another edmx file in another project and used that project's reference in my main project.
Then I switched git branch with dll in .gitignore. Those dlls which were in .gitignore could not be replaced by git with the newly switched branch's dlls.
So I had two references of edmx files in my project with fully built dlls.
Problem solved when I keenly checked my bin folder and removed the dll which was actually not belonging to the current git branch.
I hope it will help you.
Comment here if some thing is not clear.
Thanks
I spend hours fixing it, tried publishing/deploying all the projects but no luck. So, finally found out that there was a dll that was referenced twice. But with slightly change in name but pretty much similar content. So, program wasn't sure which file to look at. I redeployed all the projects but still no luck. So, finally deleted all the files from server except webconfig and global asax. And the deployed the files again. Finally it worked.
I've seen the above question asked many times on many sites, but I haven't seen an answer that fixed the problem.
The scenario is this...
I am on .NET Framework 4.0, building a C# web application in VisualStudio 2012 Express with the Razor view engine.
I'm trying to use Microsoft.VisualBasic.FileIO.TextFieldParser in my code. From what I've read it is appropriate to do so by adding a project reference to Microsoft.VisualBasic, which I've done, and coding #using Microsoft.VisualBasic; in my view. However when I code...
Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(new StringReader(xxxxxxxx));
...in the view and rebuild the solution it returns errors: The type or namespace name 'FileIO' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)
I know the reference is in the correct project because when I add and remove it I see it come and go from the references folder. I know the code I'm trying to reference exists because I can see it in Object Browser. I've even tried adding the reference using Object Browser instead of through the menus and although it gets added, the results are the same.
The solution it's in is a bit complicated so I tried just creating a test stand alone C# project and I get the same results. I also tried creating a test stand alone Visual Basic project, and sure enough, it works there as advertised. I'm by no means an expert on Visual Studio so I'm guessing that it's just something I'm missing in the configuration, but I'm at a loss to figure it out.
I've spent days on this, so any help anyone could offer would be greatly appreciated.
Right-click on your project and select Add Reference...
In the Reference Manager, expand Assemblies and select Framework. Then check the box for Microsoft.VisualBasic and click OK.
Credit goes to:
https://stackoverflow.com/a/17146200/2530360
I just had the same problem and your question title was more verbose so I figured it should have the answer inside.
I have a weird error showing up in my project when it is open in the VS2012 IDE. Everywhere where I make use of another referenced project it suddenly says "Type or Namespace name could not be found". And by "says", I mean it has the text underlined in red with the error when I hover over it. The intellisense doesn't work for that code. BUT (and here's the weird part), the errors do not show up in the error console and the project builds and runs fine.
I can even debug and step through the code and it works perfectly fine. So at runtime the project is referenced fine but at design time the IDE can't find it. This worked for the past 2 weeks, and only then suddenly went a little bonkers. It's really annoying because I am rubbish at coding without intellisense!
Has anybody ever seen anything like this or have any suggestions?
I had this. I referenced assemblies whose "Target Framework" were set to ".Net Framework 4" in the "Application" secion of the projects properties. I changed this to ".Net Framework 4.5" not just in the referenced assembly's project but also the project I was building and it worked. Give this a try.
I have found this is a known problem with VS2012. Check to see how you are building, 64 bit or 32 bit. It won't work with 64 bit but it will with 32 bit. It will say things are missing and design will not work, however the program will run fine. I have heard the new VS update that hasn't been released yet will fix it.
Manually delete all the references to the libraries of the other projects and re-add. Intellisense rebuilds whatever it needs at that point and doing this has helped me in the past.
Another source of this problem is a solution with multiple projects containing code for the same namespace. The compiler can handle this. Intellisense won’t.
Related to a couple other answers here, I had a "Data" project using a "Data" namespace. Built fine, but just started recently showing errors from intellisense (even though it continued building fine.) (VS 2015.)
I fixed this by changing my "Data" project and namespace to "MyCompany.Data".
Oddly, the problem didn't seem to show up until recently, but making the change did fix it. Presumably there was a conflict in namespace with another project or reference, which can build fine, but intellisense can't handle.
You can change this in the Application tab of Project properties. You can also open up an EDMX diagram, right click, choose model browser, choose the second collapsable item in the model browser tab, hit properties, and there you'll find the Namespace option for generated Entity Framework entities and contexts. (Similiarly, if you modify an Entity Framework Model's namespace, you might also need to change the related connection to match [in Web.Config for ASP.Net and MVC.])
Make sure that there is no class with the name same as Project default namespace.
make sure that you don't reference .net framework 4.5 projects in .net 4 projects!
Examine your .proj files in a text editor and make sure the paths to your references are correct.
This can also happen if you set the Build Action to "None" on the referenced file and forget about it.
I had the same problem, where it would build and run fine, it just would always show that error and I couldn't use intellisense with the class.
I actually used the automatic method of creating the class in a new file to resolve the issue, then just copied the code over from the real class. I deleted the old file, renamed the new file, and now it works.
In C#, I made a ClassLibrary that has one Namespace and one Class.
I saved it and build it.
in other Projects, when i use it, I add it to my references by browsing to the .dll location.
But The Problem is that its name is not showing up in the Intellisense.
i.e when I: using ... my dll doesn't show ..
I'm Importing the library to a ConsoleApp.
both of the App and the library target Framework is .NET Framework 4.0
and I made their Assembly Version 4.0.0.0 so they're the exact same.
is there a setting or something that I'm missing ?
how can i make it pop up ?
I'm using VS2010 Professional
Thank you for your help
Maybe this be usefull, I was having a similar issue, I have a Web project, add the reference to a Class Library by selecting the project, but if I made a change on the class library, I can´t see that change on the intellisense of the Web Project, after try many things, I see that in the recently added reference, the value of the option "Local Copy" was set "True", then I change it to false and everething works!
I had a similar issue but in my case it was a property on the class. If you go to the file properties and look for a Build Action. Somehow mine was set to Content it had to be set to Compile.
I am using Visual Studio 2013. I hope this helps someone else.
Is the namespace for your assembly different than the namespace for your currently open project? I've had times when the current project and an assembly share the same namespace path the intellisense can mess up.
In general, Visual Studio is pretty good about intellisense generation, especially for C#. But sometimes there are some interesting conditions regarding ambiguities, and especially mixing project types where it just doesn't quite work.
Placing your content in the same namespace makes me wonder if you've actually fixed the problem (it may just be autocompleting the namespace in the currently loaded project rather than the assembly), but if it allows you to continue working, then go with it!
Right click on project on which you add reference of your dll/project select menu project dependancies and select/MarkCheckBox for reference project/dll. then it will work fine.
If the class library project had its name changed after creation, then intellisense may fail finding it due to directory issues, I believe.
I created my class with the generic "ClassLibrary1" or whatever, and then later changed the default namespace, class name, and project name inside of VS2017. I closed VS2017 and changed the directory name to match my default namespace, and then re-associated the project file in VS2017, and then re-added the reference in my main project file.
All seems to be fixed now.