I'm getting a few:
'The type or namespace 'blah' does not exist in 'A.B.C' (are you missing an assembly reference?)
The code looks like:
namespace A
{
using B.C;
public class Blah()
{
//...
}
}
A and B are both assemblies that are included in the solution. Both use .NET 4.0. Assembly B does in fact have a namespace C. Assembly B is included as a reference in assembly A.
Why is it looking for A.B.C when the reference is B.C?
The problem was a typo in a different file than the ones with errors.
In another file I had:
namespace A.B.C
{
//...
}
I must have done an accidental Ctrl-P at some point?
The steps I took to find the offending file:
Open up the most recent file that I had changed
Examine the namespace
Repeat with the next most recent
Related
I'm trying to compile a project I'm working on and this error mesages pops out:
Invalidating makefile for SpaceShooterEditor (SpaceShooter.Build.cs modified)
While compiling E:\ue projects\SpaceShooter\Intermediate\Build\BuildRules\SpaceShooterModuleRules.dll:
e:\ue projects\SpaceShooter\Source\SpaceShooter\SpaceShooter.Build.cs(3,29) : error CS0246: The type or namespace name 'ModuleRules' could not be found (are you missing a using directive or an assembly reference?)
e:\ue projects\SpaceShooter\Source\SpaceShooter\SpaceShooter.Build.cs(5,25) : error CS0246: The type or namespace name 'ReadOnlyTargetRules' could not be found (are you missing a using directive or an assembly reference?)
ERROR: Unable to compile source files.
Any idea why this might happen? Last night i was trying to code a widget, modified the build.cs, then replaced the modified version (which chrashed the game) with a build.cs that worked previously, and still nothing? Is there any hope to make it work or should i start over? Moreover, how can this be avoided?
I already did the restarts and refreshes. I went to even delete the binaries and some cashed files and it didn't work.
Below you'll find the content of the Build.cs:
public class SpaceShooter : ModuleRules
{
public SpaceShooter(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });
// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
}
When i try to input specify the using UnrealBuildTool;, Visual Studio, for some reason, deletes it when i hit compile or save.
After some digging, i found out that wrapping the content in a namespace UnrealBuidTool.Rules{} solves this. In the end, the build file looks like this:
namespace UnrealBuildTool.Rules
{
public class SpaceShooter : ModuleRules
{
public SpaceShooter(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });
// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
}
}
As you do not share what is included in your Build.cs file I will just explain what the error is and how you could fix it. The error basically says that it couldn't compile the Build.cs file based on the lines 29 and 25, and that the types that are used there called 'ModuleRules' and 'ReadOnlyTargetRules' could not be found in any of the namespaces that were included by the using statements at the top of Build.cs. These types are both stored in the UnrealBuildTool namespace and can thus be included in your file by typing:
using UnrealBuildTool;
This however seems like a trivial solution to your problem, but as you do not share a lot of info this is the best solution I can give you for now.
EDIT: Thank you everyone! I have never upgraded to a newer version of
.NET and language version before. Thus didn't know about .csproj
configuration. Even though I did a research before posting a question
I was not able to find a solution myself. So, I just leave these two
links for further reference, perhaps this might help someone as well.
https://learn.microsoft.com/en-us/dotnet/standard/frameworks
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version
I have upgraded to .NET 5.0.301
And finally got around to try record type in C# 9.0
I wrote a simple code but got an error during compilation.
I use Visual Studio Code as an editor.
VS Code version 1.57.0
C# extension version 1.23.12
Here is my settings.json:
"editor.semanticHighlighting.enabled": true,
"csharp.semanticHighlighting.enabled": true,
"omnisharp.path": "latest"
Set up:
dotnet new sln -n "Test"
dotnet new console -n "TestProject"
dotnet sln Test.sln add .\TestProject\TestProject.csproj
My code:
using System;
namespace TestProject
{
class Program
{
static void Main(string[] args)
{
var person = new Person() { Name = "Tom" };
person.Name = "Bob";
Console.WriteLine(person.Name);
}
}
public record Person
{
public string Name { get; set; }
public int Age { get; set; }
}
}
Problems:
CS0246 The type or namespace name 'Person' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'record' could not be found (are you missing a using directive or an assembly reference?)
CS0548 '<invalid-global-code>.Person': property or indexer must have at least one accessor
CS1513 } expected
CS0116 A namespace cannot directly contain members such as fields or methods
CS1022 Type or namespace definition, or end-of-file expected
Any help much appreciated
Check your target framework and language version in your .csproj file. You should find something like:
<TargetFramework>net5.0</TargetFramework>
<LangVersion>9.0</LangVersion>
If you don't find these properties, add them inside the <PropertyGroup>...</PropertyGroup> tags. If they are set to older versions, change them.
If this does not solve your problem, you may have installed your .NET SDK incorrectly, or you may have installed it in a directory other than the default one and the VS Code C# extension is not able to find it.
I have a project of namespace SpaceCats.Planet.Types that has a class called MajorTomCat.cs
My test project namespace is Test.Fiddlesticks
In my test project, there is a namespace Test.Fiddlesticks.SpaceCats which is generated automatically from a WCF service reference
When I do MajorTomCat cat = new MajorTomCat(), it says it cannot find MajorTomCat.
I try to put it explicitly:
SpaceCats.Planet.Types.MajorTomCat cat;
But it still can't find it. Hovering over it, it says
The type or namespace Planet does not exist in the namespace Test.Fiddlesticks.SpaceCats.
It appears to be looking in the wrong SpaceCats namespace.
I can't figure out how to force it to look in the root.
Any ideas?
I'm trying to set up serialization for a class. When I added:
[Serializeable]
I got the error:
"The type or namespace name could not be found (are you missing a using directive or an assembly reference?)"
I added System.Runtime.Serialization.Formatters.Soap and System.Runtime.Serialization but they didn't work. I also tried to find the other assemblies listed on the documentation page. I only found mscorlib in the VS Reference Manager and it was already added.
I wrote the code like so:
[Serializeable]
public class Test { }
Edit: I also tried:
[Serializeable()]
public class Test { }
I expected the code to compile without errors.
Edit: fixed wrong name for an assembly
Per MSDN, the SerializableAttribute type can be found in the following assemblies:
System.Runtime.Serialization.Formatters.dll
mscorlib.dll
netstandard.dll
System.Runtime.dll
EDIT
It may be easier to try the below. There may be namespace conflicts.
[System.SerializableAttribute]
public class Test {}
So I was changing my Project name and also my folders etc. I followed guide from here How do I rename a Project Folder from within Visual Studio?. All seemed to work, I can launch my app, but I got some erros and lots of lots of warnings
Warning example:
Warning CS0436 The type 'ObservableObject' in 'C:\Users\Godhaze\Documents\Volaapp\Volaapp\Volaapp\Base\ObservableObject.cs' conflicts with the imported type 'ObservableObject' in 'TodoScheduler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'C:\Users\Godhaze\Documents\Volaapp\Volaapp\Volaapp\Base\ObservableObject.cs'. Volaapp C:\Users\Godhaze\Documents\Volaapp\Volaapp\Volaapp\Base\SelectableObject.cs 5 IntelliSense Active
And errors like this:
Error CS0234 The type or namespace name 'XamlFilePathAttribute' does not exist in the namespace 'Xamarin.Forms.Xaml' (are you missing an assembly reference?) Volaapp C:\Users\Godhaze\Documents\Volaapp\Volaapp\Volaapp\obj\Debug\TodoScheduler.Pages.MenuPage.xaml.g.cs 14 IntelliSense Active
The code of the error:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace TodoScheduler.Pages {
[global::Xamarin.Forms.Xaml.XamlFilePathAttribute("C:\\Users\\Godhaze\\Documents\\Visual Studio 2017\\Projects\\Volaapp\\Volaapp\\Volaapp\\Pa" +
"ges\\MenuPage.xaml")]
public partial class MenuPage : global::TodoScheduler.Controls.BasePage {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private global::Xamarin.Forms.ListView listView;
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private void InitializeComponent() {
global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(MenuPage));
listView = global::Xamarin.Forms.NameScopeExtensions.FindByName<global::Xamarin.Forms.ListView>(this, "listView");
}
}
}
So I think Its an problem with Assembly?
I Added Reference In the first place, so what could be the problem?
Also do I need to change my namespaces? My projects name of PCL is "Volaapp" But Im using namespaces like: TodoScheduler.Base, because I think its refers to the Assembly. I might misunderstood this!
I tried cleaning the solution then deleting bin,obj folders and then rebuilding it, but that dident help.
So what should I do? I really want to fix this case and I can even give the full code of this to fix :(
I had the same problem, and found out I was performing a font size change operation on an array of labels that contained an image by accident.