Reputation: 6202
Note: The newly added class/file was to a Xamarin.Android project, and referenced from another.
After adding a new class/file, NewClass
/NewClass.cs, to a particular folder with the Add > New Item command, it wasn't detected by the compiler, which was indicated by the error:
"The type or namespace 'NewClass' could not be found (are you missing a using directive or an assembly reference)?
Note: I made sure the new type was made public
The project that NewClass
was added to built successfully. It was in the referencing project where the error was occurring (in a separate namespace and assembly).
After cleaning the solution and first building the referenced project failed, I tried the following:
NewClass
into an existing file and commented original one in NewClass.cs - error fixed.NewClass
into another existing file and commented original one in NewClass.cs - error fixed.Is there a manual operation that can be performed to ensure that a newly added class is successfully discovered by the compiler? Cleaning and rebuilding didn't work, nor did reopening the solution.
Upvotes: 3
Views: 1101
Reputation: 7803
I believe you used a different template originally (other than class
) and renamed, or something of the sort, so the build action is incorrect.
Right click on the file and hit Properties
. In the Properties window, make sure Build Action
is set to Compile
.
As a last resort, copy your code, delete the file, add a new file with the same name, then paste the code back.
Upvotes: 1