I got many exceptions like:
Error 95 The type or namespace name 'Web' does not exist in the namespace 'MyProj.System' (are you missing an assembly reference?) C:\Projects\Solution\MyProj\Web References\GeneralServices\Reference.cs 269 24 MyProj
Error 108 The type or namespace name 'Uri' does not exist in the namespace 'MyProj
.System' (are you missing an assembly reference?) C:\Projects\Solution\MyProj\Web References\GeneralServices\Reference.cs 322 43 MyProj
The only thing I sis was adding WCF service (I already have web services in the same project). How can I solve those errors??
Where did they came from??
For some reason I don't know people closed this questions because they think it is fake question. So this is not a fake question and if they need more information - they can be specific and ask and I'll provide it. I know it looks like very generic question - but I really don't know what info to add.
It is nor a refernces problem for sure. It happend after I add wcf service and the all errors accurs in Reference.cs file that generated after I added an external web service.
*EDIT*
Here is the code of the WCF service I added. I am not sure that it is the problem:
using System.Collections.Generic;
using System.Linq;
using MyProj.Domain.Business.Entities.System.Calls;
using MyProj.Domain.Business.EntitiesRepository.System.Calls;
using StructureMap;
namespace MyProj.System.WcfServices
{
public class SystemService : MyProjService, ISystemService
{
#region Calls
public Reason[] GetCallReasons()
{
IReasonRepository rep =
ObjectFactory.GetInstance<IReasonRepository>();
return rep.GetReasonsList().ToArray();
}
public Call InsertCall(long reasonId, string phoneNumber, string description)
{
ICallRepository rep =
ObjectFactory.GetInstance<ICallRepository>();
return rep.Insert(User.UserCompany.CompanyId, reasonId, phoneNumber, description);
}
public void UpdateCall(long callId, long reasonId, string phoneNumber, string description)
{
ICallRepository rep =
ObjectFactory.GetInstance<ICallRepository>();
rep.Update(User.UserCompany.CompanyId, callId, reasonId, phoneNumber,
description);
}
public void CloseCall(long callId)
{
ICallRepository rep =
ObjectFactory.GetInstance<ICallRepository>();
rep.CloseCall(User.UserCompany.CompanyId, callId);
}
public IList<CallsListItem> GetCallsList(bool? isClosed)
{
ICallRepository rep =
ObjectFactory.GetInstance<ICallRepository>();
return rep.GetCallsList(User.UserCompany.CompanyId, isClosed);
}
public Call GetCall(long callId)
{
ICallRepository rep =
ObjectFactory.GetInstance<ICallRepository>();
return rep.GetCall(User.UserCompany.CompanyId, callId);
}
#endregion
}
}
*Another EDIT*
I remember that I also installed ef4.1 from Here.
Maybe It make something??..
*Another Another EDIT*
I think I figure it out! but I still don't know how to fix this..
The file that creates the errors has using System, using System.Web and so on. The Im My project I have also System Folder and the WCF service is in MyProj/System/WcfServices/SystemService.svc. So, it creates a cs file with namespace MyProj.System.WcfServices.
This namespace confused with System namespace! Because the file that creates the errors is generated by the system (it is the References.cs file that created for web reference) I can't edit the file. How can I solve it?..
One solution would be to stop naming folders "System"!
Another solution would be to qualify the system namespaces:
using global::System;
using global::System.Web.UI;
etc.
These mean that you're missing an assembly reference. E.g. you are referencing a type in your code for which you have not added a reference to your project. It sounds like you need to add a reference to System.Web by right clicking on your project and choosing "Add Reference".
If that doesn't work then make sure your project is targeting the full .NET framework instead of the "Client Profile" - do this by right clicking on your project and choosing "Properties" and then set the "Target Framework" on the "Application" tab.
Even if it looks like the references are correctly added, perhaps there is a .NET version mismatch? .NET 4 Client doesn't support all WCF features, so that could be the problem. Sometimes intellisense and the complier don't quite see eye-to-eye, so it might look like everything is OK but then it fails to build.
You can check which version you're project is set to by right clicking on the project -> "Properties". Go to the "Application" tab, and check under "Target framework."
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.
I'm fairly new to .NET and I'm trying to get an old program to work that no longer has it's .csproj file. I've managed to receive an old .sln file from the creator and opened the solution in VS.
From what I can see this is a Developer Web Server project?
Here is the issue.
In the folder Smreka there are 2 files, log.cs and smreka.cs. The log.cs contains the implementation of a class Logger, which I am trying to import in to smreka.cs. They are both using the same namespace Bum.Iglavci.Smreka so as far as I know, I should be able to import the Logger class without any issues.
The problem is that the compiler just can't see it. If I try to directly import it with using static Bum.Iglavci.Smreka.Logger;, I get an error Feature 'using static' is not available in C# 5. Please use language version 6 or greater.
I would like to know why the namespace can't see each other. Is it because I'm missing the .csproj file? Does Developer Web Server even need a .csproj file? If so what's the best way to generate one?
EDIT:
Due to some confusion I'll try to add more details regarding how log.cs and smreka.cs look like. The files are actually a lot longer but I think this should give an idea.
log.cs:
namespace Bum.Iglavci.Smreka{
public class Logger{
public Logger(){
}
public void DoSomething(){}
}
}
smreka.cs:
namespace Bum.Iglavci.Smreka{
public class Baza{
private Logger log;
public Baza(){
log = new Logger();
}
}
}
The compiler has no idea what Logger is under property private Logger log; It states the error The type or namespace name 'Logger' could not be found (are you missing a using directive or an assembly reference?)
I think the namespace is correctly placed, that's why i have a feeling there's something wrong with the project or the solution itself that i need to fix.
Since both classes are in the same namespace they are already able to use each other. You can acces the class by simply doing the following. Let's take Log as the class to call the other class.
Log class:
namespace Bum.Iglavci
{
public class Log
{
public static void ExecuteDoSomething()
{
Smreka.DoSomething();
}
}
}
Smerka class:
namespace Bum.Iglavci
{
public class Smerka
{
public static void DoSomething()
{
//execute code here
}
}
}
It could be possible that the files have the Buil Action property set to
None this will not compile the files. Set it to C# Compiler, this should solve it.
If you don't know how to acces the properties of a file.
Right click the file
Navigate to Properties in the bottom of the list
Set the Build Action to C# compiler (see image)
I found no simple solution. I now created a new .net framework application project and added the files in to the new project. For some reason the namespace works correctly now and the files can see each other in the same namespace.
Yes the error comes from the fact that you don't have a .csproj file.
Such files contain the list of files to compile when building a project. Just having the solution file is not enough.
I suggest some readings on project and solution using Visual Studio :
https://learn.microsoft.com/en-us/visualstudio/ide/solutions-and-projects-in-visual-studio?view=vs-2022
https://learn.microsoft.com/en-us/visualstudio/get-started/tutorial-projects-solutions?view=vs-2022
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'm doing research into the OpenXmlSdkTools v2.5 and had a sneak peak inside the OpenXmlSdkTools.Core.DLL and saved it as a c# Project with ILSpy.
While this question is active, here is the OpenXmlSdkTools.Core.DLL as a way to quickly reproduce the problem I'm encountering.
When I tried to compile the single class library project, I get two errors about a missng reference to assembly 'System.Xaml'. eg:
The type 'System.Windows.Markup.IQueryAmbient' is defined in an
assembly that is not referenced. You must add a reference to assembly
'System.Xaml
The type 'System.Windows.Markup.IUriContext' is defined in an assembly
that is not referenced. You must add a reference to assembly
'System.Xaml
So I added the ref.
After that I'm stuck on what I hope is the last compile error and I can't figure it out.
Cannot convert anonymous method to type 'System.Delegate' because it
is not a delegate
type C:\TFS\ABC\src\OpenXmlSdkTool.Core\DocumentFormat.OpenXml.Tools\ApplicationExtensions.cs
10
Here is the code:
using System;
using System.Windows;
using System.Windows.Threading;
namespace DocumentFormat.OpenXml.Tools
{
public static class ApplicationExtensions
{
public static void DoEvents(this Application application)
{
application.Dispatcher.Invoke(DispatcherPriority.Background, delegate
{
});
}
}
}
I'm stuck and puzzled that its a decompiled DLL that should be easy to re-compile again. Do you think by me adding the Xaml reference its caused this problem? And why would I need to add the Xaml reference if the Core.DLL is a class library project and ILSpy didn't included it in the csproj file?
I've looked at all the other questions on here with the same error but none of them really helped.
Update
When you add System.Xaml.dll as reference to your project. The interface is declared there. Here is the doc.
So now I'm in a Catch22, if I add the Xaml dll it will solve the first 2 errors but then it will cause this other error.
After reproducing the issue on my machine, I found this http://staceyw1.wordpress.com/2007/12/22/they-are-anonymous-methods-not-anonymous-delegates/ (referenced from Convert this delegate to an anonymous method or lambda).
Adding a cast to Action solved the issue
application.Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate
{
});
But there are probably other solutions.
I'm trying to allow a user to enter data into a textbox that will be added to the web.config file. I've added the relevent lines to the web.config file but when I make this class all goes wrong.
I keep getting the are you missing a using directive or assembly refenrence error whenever I try to run my app. I have looked at the other times this question has been asked and can't seem to figure out where I'm going wrong. The thing is that I am extremely new to Visual Studio and am just left blank at what could be the answer.
Below here is the class file that's generating the error. I hope I've included everything you need to assist me. Thank you.
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
namespace WebConfigDemo
{
public class CompanyConfigSection : ConfigurationSection
{
[ConfigurationProperty("", IsRequired = true, IsDefaultCollection = true)]
public CompanyConfigCollection Companies
{
get
{
return (CompanyConfigCollection)this[""];
}
set
{
this[""] = value;
}
}
}
public class CompanyConfigElement : ConfigurationElement
{
[ConfigurationProperty("id", IsKey = true, IsRequired = true)]
public int Id
{
get
{
return (int)this["id"];
}
set
{
this["id"] = value;
}
}
[ConfigurationProperty("name", IsRequired = true)]
public string Name
{
get
{
return this["name"].ToString();
}
set
{
this["name"] = value;
}
}
} '
public class CompanyConfigCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new CompanyConfigElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((CompanyConfigElement)element).Id;
}
}
public class CompaniesConfig
{
private static readonly Dictionary<int, CompanyConfigElement>
Elements;
static CompaniesConfig()
{
Elements = new Dictionary<int, CompanyConfigElement>();
var section = (CompanyConfigSection)ConfigurationManager.GetSection ("companies");
foreach (CompanyConfigElement system in section.Companies)
Elements.Add(system.Id, system);
}
public static CompanyConfigElement GetCompany(int companyId)
{
return Elements[companyId];
}
public static List<CompanyConfigElement> Companies
{
get
{
return Elements.Values.ToList();
}
}
}
} '
Any help is appreciated
You probably don't have the System.Configuration dll added to the project references. It is not there by default, and you have to add it manually.
Right-click on the References and search for System.Configuration in the .net assemblies.
Check to see if it is in your references...
Right-click and select Add Reference...
Find System.Configuration in the list of .Net Assemblies, select it, and click Ok...
The assembly should now appear in your references...
.Net framework of the referencing dll should be same as the .Net framework version of the Project in which dll is referred
If you've tried the above solutions and haven't found the answer, make sure that the .NET versions of all projects are the same.
I ran into this problem when importing a .NET version 4.6.1 into a .NET version 4.6.2 project. Without any warnings from Visual Basic!
More Info: The type or namespace name could not be found
Your using statements appear to be correct.
Are you, perhaps, missing the assembly reference to System.configuration.dll?
Right click the "References" folder in your project and click on "Add Reference..."
This problem would be caused by your application missing a reference to an external dll that you are trying to use code from. Usually Visual Studio should give you an idea about which objects that it doesn't know what to do with so that should be a step in the right direction.
You need to look in the solution explorer and right click on project references and then go to add -> and look up the one you need. It's most likely the System.Configuration assembly as most people have pointed out here while should be under the Framework option in the references window. That should resolve your issue.
I have observed a quote ' in your 1st line and also at the end of your last line.
'using System.Collections.Generic;
Is this present in your original code or some formatting mistake?
I had the same problem earlier today. I could not figure out why the class file I was trying to reference was not being seen by the compiler. I had recently changed the namespace of the class file in question to a different but already existing namespace. (I also had using references to the class's new and previous namespaces where I was trying to instantiate it)
Where the compiler was telling me I was missing a reference when trying to instantiate the class, I right clicked and hit "generate class stub". Once Visual Studio generated a class stub for me, I coped and pasted the code from the old class file into this stub, saved the stub and when I tried to compile again it worked! No issues.
Might be a solution specific to my build, but its worth a try.
In some cases, when necessary using has been obviously added and studio can't see this namespace, studio restart can save the day.
I was getting warnings about different versions in .NET framework; I ignored them.
The project compiles fine making the change in the solution's properties.
I'm using Visual Studio Code and could not use instructions from above so I found another way to fix the problem with referencing to namespace from another file.
All what need to be done is to add include to your .csproj file e.g:
<ItemGroup>
<Compile Include="filename.cs" />
</ItemGroup>
Then you can use namespaces from filename.cs
The following technique worked for me:
1) Right click on the project Solution -> Click on Clean solution
2) Right click on the project Solution -> Click on Rebuild solution