As part of my first experiments with C# (on Mono 2.6.7) , I am trying to use the StronglyConnectedComponents method from QuickGraph. Here is my code:
using System;
using QuickGraph;
using QuickGraph.Data;
using System.Collections.Generic;
using QuickGraph.Algorithms;
namespace Graph
{
class MainClass
{
public static void Main (string[] args)
{
IVertexListGraph<int,Edge<int>> graph;
graph = new AdjacencyGraph<int,Edge<int>>();
IDictionary<int,int> components=new Dictionary<int,int>();
int noc = graph.StronglyConnectedComponents(out components);
}
}
}
When trying to compile the code above, I get the error message (in MonoDevelop):
Error CS1061: Type `QuickGraph.IVertexListGraph<int,QuickGraph.Edge<int>>' does not
contain a definition for `StronglyConnectedComponents' and no extension method
`StronglyConnectedComponents' of type
`QuickGraph.IVertexListGraph<int,QuickGraph.Edge<int>>' could be found
(are you missing a using directive or an assembly reference?) (CS1061) (Graph)
As for as I can see from the documentation, the extension method should be available:
public static int StronglyConnectedComponents<TVertex, TEdge>(
IVertexListGraph<TVertex, TEdge> g,
out IDictionary<TVertex, int> components
)
Also, I referred all three .dll's from QuickGraph. What am I missing?
Ok, I just checked it out and it works for me on Mono 2.10.5 (Ubuntu), which I currently have, so consider updating. 2.6.7 is very old. I just downloaded quick graph library, referenced only one dll (QuickGraph.dll), copypasted your code (just removed using QuickGraph.Data) and it compiles and runs without any problem.
Related
Program.cs(18, 44): [CS1061] 'AppBuilder' does not contain a definition for 'UsePlatformDetect' and no accessible extension method 'UsePlatformDetect' accepting a first argument of type 'AppBuilder' could be found (are you missing a using directive or an assembly reference?)
So here is my code :
using System;
using Avalonia;
using Avalonia.ReactiveUI;
namespace AvaloniaCrossPlatformApplication1.Desktop
{
class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>().UsePlatformDetect()
.LogToDebug()
.UseReactiveUI();
}
}
My avalonia version is avalonia.0.10.13.nupkg.sha512
i'am using the basic template.
It seems that there is no UsePlatformDetect on Avalonia ...
I used jetbrain rider & dotnet new -i Avalonia.Templates
to generate the template.
Any ideas ? I'am on ubuntu 22.04.
Regards
The UsePlatformDetect extension has its definition in the Avalonia.Desktop assembly, so you have to add a reference to it in your .csproj
<PackageReference Include="Avalonia.Desktop" Version="0.10.13" />
I want to compile and run some c# code, but it's not working due to the methods/classes not being found by referenced libraries. Even though i included the needed namespaces e.g. "using System.Collections.Generic;", they will be grey'd out and marked with "Using directive is unneccessary", even though my code requires it. As a result, compiling fails. What am I doing wrong?
using System.Collections.Generic;
namespace NetCoreExamples
{
class Program
{
static void Main(string[] args)
{
##some code##
}
private static async Task MainAsync(string[] args)
{
var type = Type.GetType(args[0]);
await (Task)type.GetMethod("RunAsync", BindingFlags.NonPublic | BindingFlags.Static)
.Invoke(null, new object[] {args.TakeLast(args.Length - 1).ToArray() });
}
}
}
On phrase "args.TakeLast(args.Length - 1)", "TakeLast" is underlined saying "string[] has no definition for TakeLast and no extension method was found that accepts the first argument as string[]. (Maybe missing using directive or assembly reference)".
To use System.Collections.Generic.IEnumerable, I discovered it's location:
Namespace:
System.Collections.Generic
Assemblies:
System.Runtime.dll, mscorlib.dll, netstandard.dll
But the "using System.Collections.Generic;" keeps being grey'd out, referencing the assemblies for the project did not change anything.
I am sure this is trivial, but I cannot seem to find out what I am doing wrong.
I can't figure out what is wrong. I run this code in Visual Studio in a C# .Net Console Project. Trying to make a simple list. I am using lists in more complicated code, but it is not working and now I can't get lists of any kind to run.
I get the error message on the line List<string> Mylist = new List<string>();
The type or namespace 'List<>' could not be found (are you missing a
using directive or an assembly reference?).
namespace Lists
{
class Program
{
static void Main()
{
List<string> Mylist = new List<string>();
Mylist.Add("a");
Mylist.Add("b");
Mylist.Add("c");
}
}
}
Include the proper namespace to access the types in it. List<T> is contained in the System.Collections.Generics namespace so you need to add the following line on top of your program:
using System.Collections.Generic;
If you don't know which namespace is missing simply press CTRL + . on the highlighted line and Visual Studio will add it automatically.
This might be a C#-noob question...
Assume I have the following CLI/C++ header:
namespace DotNet {
namespace V1 {
namespace X {
public ref class AClass {
public:
AClass() {}
void foo() {}
static void bar() {}
};
}
}
}
Then from C# I do the following:
using DotNet;
V1.X.AClass a = new V1.X.AClass();
I get:
Program.cs(18,7): error CS0246: The type or namespace name 'V1' could
not be found (are you missing a using directive or an assembly
reference?)
Same with:
using DotNet.V1;
X.AClass a = new X.AClass();
Program.cs(18,7): error CS0246: The type or namespace name 'X' could
not be found (are you missing a using directive or an assembly
reference?)
What works is:
DotNet.V1.X.AClass a = new DotNet.V1.X.AClass();
Or
using DotNet.V1.X;
AClass a = new AClass();
So either I have to use the full namespace path, or I have to open all of the path to access the class. Is there anything I can do about this?
I would like to be able to open only a part of it.
So either I have to use the full namespace path, or I have to open all of the path to access the class.
Yes.
Is there anything I can do about this?
Not that I'm aware of. Why would you not just want a using directive for the whole namespace? Isn't that the simplest approach?
Note that this has nothing to do with C++/CLI. The same is true whatever the source language is - so you can see it with C# as well:
namespace DotNet.V1.X
{
public class AClass {}
}
As Jon Skeet stated you have to include the full namespace in either the using statement or each time you reference it in code. I recommend just placing the full namespace in the using statement.
You can, however, achieve that syntax with a using alias, but it does not add anything of value outside of syntax.
using V1 = DotNet.V1;
...
V1.X.AClass a = new V1.X.AClass();
Also if you are using C# version 3.0 or higher the var keyword will only require you type out the full namespace on the right side of the assignment.
var a = new DotNet.V1.X.AClass();
I created my custom DLL "MongoDbExtensions". Now in a new project I add a reference to the "MongoDbExtensions" and then try to invoke a method inside the MongoDbExtensions called ToDocument. I use resharper to add the namespace at the top of the file but when I compile I still get the following error:
Error 1 The type or namespace name 'MongoDbExtensions' could not be found (are you missing a using directive or an assembly reference?) C:\Projects\HelpForum\DemoConsole\Program.cs 6 7 DemoConsole
What is going wrong? My DLL can be downloaded from here:
http://github.com/azamsharp/MongoDbExtensions/downloads
UPDATE 1:
Here is the MongoExtensions class:
namespace MongoDbExtensions
{
public static class MongoExtensions
{
public static List<T> ToList<T>(this IEnumerable<Document> documents)
{
var list = new List<T>();
var enumerator = documents.GetEnumerator();
while (enumerator.MoveNext())
{
list.Add(enumerator.Current.ToClass<T>());
}
return list;
}
}
}
ToDocument is an extension method that works on Object.
I repro. This DLL was built targeting .NET 4.0. You cannot use it in a project that targets anything else but the full 4.0 .NET framework. Either targeting a lower version or the client profile will produce this error.
Since your class is called MongoExtensions, you need to change MongoDbExtensions in your test project source code to MongoExtensions.