17

We're working on a WPF project using Visual Studio 2015. We've got a folder in the project named Assets. It shows up fine in VS 2015. The files in it show up fine in the Solution Explorer. But when we build it, VS 2015 complains with the following error:

Error CS0234 The type or namespace name 'Assets' does not exist in the namespace 'CoreFramework' (are you missing an assembly reference?)

(CoreFramework is the name of our solution and the project that Assets is in.)

I don't get how the folder is there in CoreFramework, but when building it, VS 2015 just doesn't see it. I've tried cleaning both the project and the solution in VS 2015, but it doesn't help at all. The same errors keep popping up. And they popup in our nightly builds as well.

So what is causing VS 2015 to simultaneously see a folder within a project and not see that same folder in the project?

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Rod
  • 4,107
  • 12
  • 57
  • 81
  • 3
    is `Assets` using the same .NET version as your other assemblies? – Jonesopolis Feb 15 '16 at 22:02
  • 1
    Whats the build action on the folder? Right click it and check properties. – NikolaiDante Feb 15 '16 at 22:03
  • 1
    you quite possibly have a mismatch in .net versions – Simon Price Feb 15 '16 at 22:04
  • See this answer: http://stackoverflow.com/questions/5567945/type-or-namespace-name-does-not-exist and notice the one where the person mentions having a folder named System. I believe you have same sitch with Assets folder. answer by : GrandMasterFlush – raddevus Feb 15 '16 at 22:06
  • @Jonesopolis there are only 2 projects in the solution. But are using .NET 4.5.2. – Rod Feb 15 '16 at 22:47
  • @NikolaiDante there are no build actions defined for the Assets folder. Nor do any other folders in the project have any build actions defined. – Rod Feb 15 '16 at 22:47
  • 2
    Do the objects in the Assets folder also have the `Assets` namespace? When you reference something from that namespace in another part of the code, if you press F12, does it take you to the corresponding source file in that folder? How many project does the solution have? – Andrew Feb 15 '16 at 22:49
  • @Andrew there's only 1 file in Assets; a .XAML file. It's got a resource dictionary in it. – Rod Feb 15 '16 at 22:58
  • @Andrew the solution only has 2 projects. The primary project and a unit test project. – Rod Feb 15 '16 at 23:05
  • When you add a resource file, it adds a .Designer.cs file, with a `CoreFramework.Assets` namespace. Is that ok? If you type `CoreFramework` in any source file and then press `.`, does it offer the `Assets` subnamespace? If you add another resource file, does it work? – Andrew Feb 15 '16 at 23:21
  • Just because there is a folder called `Assets`, it does not mean that such an namespace or a class exists, and that is what the error message is saying. Are you sure you have an `Assets` class or namespace? Please double click on the compiler error, this should jump to the line causing the error. Please make a screenshot and post it here. – Martin Feb 16 '16 at 10:12
  • @Andrew There is no .Designer.cs file related to the resource code in the Assets folder. Out of curiosity I checked the whole solution directory structure. I couldn't find a .Designer.cs file with the same name as the resource file anywhere. – Rod Feb 16 '16 at 16:43
  • @Martin Double clicking on the error related to Assets takes me to a temporary file created by the build process. In this case the file's name is ColumnsDialog.g.i.cs. There's a ColumnsDialog.xaml and ColumnsDialog.xaml.cs file that exist at the root of the project, but like I said that .g.i.cs file is a temporary one. Assets isn't a class anywhere in our project; its just a folder. Just like the folders View, ViewModel, UserControls and Settings, which the build process has no problem with. – Rod Feb 16 '16 at 16:49
  • 2
    I finally got the errors to go away! What I had to do was delete everything in our project's obj folder. That's where the .g.i.cs files resigned. Honestly, I thought that doing a Clean in VS 2015 in either the project or solution would have taken care of that, but apparently it didn't. What in heck is that Clean command for, if it doesn't actually CLEAN up temporary files? At this point it feels more like a placebo, rather than actually cleaning anything. – Rod Feb 16 '16 at 17:04
  • Great. I suggest you post what you did to answer your own question, and then mark it as accepted answer. – Andrew Feb 16 '16 at 17:40
  • @Martin, you are right but when you create a resource file, its code is automatically placed in the `Yournamespace.ResourceFolder` namespace. If you place it in your project's root folder, then it won't create any subnamespace. – Andrew Feb 16 '16 at 17:43
  • All right @Andrew, will do. – Rod Feb 16 '16 at 18:43

3 Answers3

9

In this case what I had to do was to delete everything in the obj folder beneath our project main folder. The solution's name is CoreFramework and the main project's name is also CoreFramework. So what I did was go to \CoreFramework\CoreFramework\obj and deleted everything there. Since at this point we're only dealing with a debug version, the only thing there was the Debug folder and all temporary files and folders under that. Once I did that, then rebuilding the solution re-created all of the temporary files and folders, without the problem I was having with the Assets folder. It built fine.

YMMV

Rod
  • 4,107
  • 12
  • 57
  • 81
4

Check the .Net-Framework Versions of both Projects. If the referenced project has a higher .Net-Framework Version than the referencing project this error might occur.

ProjectName -> Properties -> Application -> Target framework

Findas
  • 69
  • 3
1

I had the same issue after I manually copied the referenced DLL file. I solved it by displaying the reference properties in the Solution explorer then changing the Specific version setting from True to False and finally changing it back to True. I rebuild and... it works just fine. Do not ask me why...

Note : I had to do the same for each project which had the CS0234 error message

PS : in my case Visual studio version is 16.1.6

leguminator
  • 164
  • 1
  • 8