I was searching a ZigBee library for c# and I found GBee. I took a look to the code and I've found the following statement:
using AtCmd = NETMF.OpenSource.XBee.Api.Common.AtCmd;
Why is used this statement and what means?
Searching into the code I also found that AtCmd is used as a "class" to send standard command e.g.(AtCmd.RestoreDefaults,AtCmd.NetworkReset)
This meas, that all AtCmd statements in code will become from NETMF.OpenSource.XBee.Api.Common namespace. It simply means 'default namespace' for this type.
Probably you have in code two exact names, but deriving from different namespaces.
From MSDN:
This is called a using alias directive
Related
I am getting this error:
"CS0104: 'DataType' is an ambiguous reference between
'System.ComponentModel.DataAnnotations.DataType' and
'CarlosAg.ExcelXmlWriter.DataType'"
while running an ASP.NET 4.0 application. Can any one help me on this issue?
As described in the documentation on Compiler Error CS0104 you've got a symbol clash - there are two classes in scope of your source file which are both called DataType - one is in the namespace System.ComponentModel.DataAnnotations and the other is in the namespace CarlosAg.ExcelXmlWriter.DataType'.
You need to do one of the following to resolve this:
1. Explicitly provide the full namespace prefix on each usage, i.e.
System.ComponentModel.DataAnnotations.DataType and CarlosAg.ExcelXmlWriter.DataType:
var cdt = new CarlosAg.ExcelXmlWriter.DataType();
var sdt = new System.ComponentModel.DataAnnotations.DataType();
OR 2. Or use a using directive to alias the namespaces / types, e.g.
using SystemDT = System.ComponentModel.DataAnnotations;
using Carlos = CarlosAg.ExcelXmlWriter;
And then then identify the types with the namespace aliases, e.g..
var dt = new Carlos.DataType();
OR 3. You can also alias at the class level:
using SystemDataType = System.ComponentModel.DataAnnotations.DataType;
using CarlosDataType = CarlosAg.ExcelXmlWriter.DataType;
...
var myObj = new CarlosDataType();
OR 4. If you don't need to symbols from both namespaces, then delete the unused namespace from the using clause.
My preference would be for Option 2 - it makes it clearer to the reader that there is a namespace clash, without being too verbose (like Option 1 is)
Edit
Re: "I tried by giving full prefix but still I am getting error "CS0138: A
using namespace directive can only be applied to namespaces;
'CarlosAg.ExcelXmlWriter.DataType' is a type not a namespace"
(All relating to point #2, above). The error message refers to a situation like this, which isn't permitted in .Net (but is permitted in Java imports)
// i.e. This won't work, can't import at a class level unless it is aliased
using System.ComponentModel.DataAnnotations.DataType;
As per my answer, I would recommend that you alias the namespace, and then use the alias prefix to disambiguate between the 2 DataTypes
I had the same problem. The solution I used was to delete all using and make the references again. Worked perfectly.
I've been attempting to set up FizzlerEx, found at http://fizzlerex.codeplex.com/. After adding the references to my project, I've attempted to run the example code given on the website- the entirety of my code is listed below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;
using Fizzler.Systems.HtmlAgilityPack;
namespace Fizzler_Test
{
class Program
{
static void Main(string[] args)
{
var web = new HtmlWeb();
var document = web.Load("http://example.com/page.html");
var page = document.DocumentNode;
foreach (var item in page.QuerySelectorAll("div.item"))
{
var title = item.QuerySelector("h3:not(.share)").InnerText;
var date = DateTime.Parse(item.QuerySelector("span:eq(2)").InnerText);
var description = item.QuerySelector("span:has(b)").InnerHtml;
}
}
}
However, this yields build errors, claiming that:
Error 1 'HtmlAgilityPack.HtmlNode' does not contain a definition for 'QuerySelectorAll' and no extension method 'QuerySelectorAll' accepting a first argument of type 'HtmlAgilityPack.HtmlNode' could be found (are you missing a using directive or an assembly reference?)
It would seem that QuerySelectorAll is not actually a part of HtmlNode, but given that this is the official example code taken verbatim from the website, I'd expect the creators understand how their library works. I'm at a loss as to what the actual issue could be.
A related problem seems to have been found here, but no suitable answer was ever found: Fizzler and QuerySelectorAll
It would seem that QuerySelectorAll is not actually a part of HtmlNode, but given that this is the official example code taken
verbatim from the website, I'd expect the creators understand how
their library works. I'm at a loss as to what the actual issue could
be.
You are correct about this part. Though you are not correct about the second part, since the author of HAP isn't the author of FizzlerEx. The problem is elsewhere.
Simply by looking at the error, you get the only clue you need to go to solve this .
Error 1 'HtmlAgilityPack.HtmlNode' does not contain a definition for 'QuerySelectorAll' and no extension method 'QuerySelectorAll' accepting a first argument of type 'HtmlAgilityPack.HtmlNode' could be found (are you missing a using directive or an assembly reference?)
So, what do we get; it tells us that there is no method called QuerySelectorAll in the class HtmlNode in the namespace HtmlAgilityPack. If we take a look at the source code of HAP, you can easily determine that the error message is indeed correct, since there is no method by that name in the class we are looking.
Source code for HtmlAgilityPack.HtmlNode - class
Where is this method that we want to use, but cannot find?
It's here, In the Fizzler.Systems.HtmlAgilityPack.HtmlNodeSelection-class.
After trying a few things, I get the code to work perfectly just as it is. The problem was the extensions in the reference between Fizzler and HAP source code.
If you download Fizzler you get HtmlAgilityPack at the same time. When you add the references in Visual Studio (assuming you use that), only add
Fizzler.Systems.HtmlAgilityPack.dll
HtmlAgilityPack.dll
Clean your solution and rebuild it and it should work!
You should add Fizzler by right clicking on references -> Manage Nuget Package, and search online for it, you will find it as Fizzler for HtmlAgilityPack, and then can download it.
I'm trying to create a manager class to use with my charting tool, the problem is the tool I use, uses the same names for both a 3d and 2d charts which is resulting in ambiguous reference when I try to add the 2d library.. any ideas how best to resolve this?
For example,
using tool.2dChartLib;
using tool.3dChartLib;
BorderStyle is a member of both of these
I've tried casting the areas where I use BorderStyle. I suppose it could work if i just reference tool but then that would mean I'd have hundreds of tool.class lines instead of class
If the types with the same name exist in both namespaces, you have a couple of options:
1) If the number of types is small, create an alias for that type:
using BorderStyle3d = tool.3dChartLib.BorderStyle;
2) If the number of types is large, you can create an alias for the namespace:
using t3d = tool.3dChartLib;
Then in your code...
t3d.BorderStyle
You can use full type names, or create aliases:
using 2dBorderStyle = tool.2dChartLib.BorderStyle;
Use namespace alias
using twoDimensionLib = tool.2dChartLib;
using threeDimensionLib tool.3dChartLib;
I had similar problem that the class had ambiguous reference for the SAME namespace, so I deleted a specific Project (under Dependencies/{my.prj.name}.API) which had duplicated reference.
After that I referenced Project back with using of CTRL+.
Hope it'll work for you.
New reference of specific class
I need to do some Natural Language Processing on various text inputs from user in a C# based desktop application. I am using Antelope for this purpose. The first step is to split the text into sentences. Following the documentation provided by Antelope, I used:
using Proxem.Antelope;
using Proxem.Antelope.Lexicon;
using Proxem.Antelope.Tools;
using Proxem.Antelope.LinkGrammar;
using Proxem.Antelope.Stanford;
using NUnit.Framework;
...
...
...
ISentenceSplitter splitter = new Tools.MIL_HtmlSentenceSplitter();
splitter.Text = text;
foreach (string sentence in splitter.Sentences)
{
// Process sentence…
}
Also, I have added references to these libraries as well. But it gives the error
The type or namespace name 'ISentenceSplitter' could not be found (are you missing a using directive or an assembly reference?) C:\Users\...
and
The type or namespace name 'Tools' could not be found (are you missing a using directive or an assembly reference?) C:\Users\...
I can't seem to figure out the solution. After a search on net I found out that other people are also having this problem but no one could actually found a solution. Can you please help me guys?
Simple answer is to avoid using this library. No offense to the authors, they might have done v.good and hard work but if it can not be utilized after all kinds of possible tries then it is useless. They mention in doc that a function belongs to a particular interface but when you go there, it doesn't exist in ANY of the available interfaces.
For those who are curious: I did contact the authors through their site but didn't get a reply even after 8 days.
There are other alternatives available like OpenNLP (java) or its C# counterpart SharpNLP.
I had the same problem. It stems from the fact that antelope dlls are compatible with
.net framework 2.0 and your application is set to use .net 4.0. (possibly)
I changed my application to .net 2.0 and trouble disappeared. :)
In addition I have used both SharpNLP and Antelope. Antelope has some superior features like
Collapse detection and port to wordnet which I had not seen in SharpNLP.
good luck.
Quite simple answer to this one: ISentenceSplitter is not in the actual release. I have v 0.8.7 which should be the same free 2009 version everyone else has To confirm this, I did a
grep -r ISentenceSplitter .
and nothing came back. Try to grep with another interface that does exist such as ILexicon and you see all the dlls that contain ILexicon.
Note that we are talking about a free version and Proxem, like other reasonable companies, want to market their technology as a profitable enterprise. Therefore you have to be happy with what you have, look into the paid solutions, use something else or write your own library which the community would be very happy to have.
I ran into that same error. Sali Hoo has the actual correct answer. This is not an answer for how to find or use ISentenceSplitter; however, it does show how Proxem's example application splits sentences as part of a larger process.
The example application that ships with the libraries can split sentences, so I figured the code allows for it. After reading a bit of code, I found that their example uses the Proxem.Antelope.Document class for sentence splitting and syntactical parsing. Rather than decompiling the libraries to see how the guts of the Document constructor uses ISentenceSplitter (I'm fairly confident that it does) I just used the class and it actually ended up performing all of the functions I needed, not just sentence splitting. I definitely recommend taking a look at how their example uses it, but here's the essence of my implementation:
public sealed class SyntaxService : ISyntaxService
{
public SyntaxService(IParser parser, ILexicon lexicon)
{
m_parser = parser;
m_lexicon = lexicon;
// These are the setting I needed, YMMV. They seem to add a lot of UI logic to this method :(
m_processingResources = new ProcessingResources(m_lexicon, null, null, m_parser, 5, null, false, null, null, null, null, false);
}
public IEnumerable<Sentence> GetSentences(string s)
{
IDocument document = new Document(s, m_processingResources);
return document.Select(Mappers.SentenceMapper.Map);
}
readonly IParser m_parser;
readonly ILexicon m_lexicon;
readonly IProcessingResources m_processingResources;
}
The Sentence class referenced here is a simplified syntax tree along with the original sentence value. If you're not super interested in this type of dependency injection friendly wrapping and mapping, you can just use the guts of GetSentences(string).
I have a namespace conflict between two referenced assemblies:
i.e., I'm referencing Foo.A.Foo and Foo.Bar, so when I say I want Foo.Bar.Control, VS is trying to find Foo.A.Foo.Bar.Control
I can twiddle the Designer.cs code by adding new global:Foo.Bar.Control(), but as soon as I change anything, VS switches back.
I know there's something about adding aliases directly to the reference, I've tried but haven't managed to find the right combination (inline alias, using alias, reference alias).
Help?
"extern alias" may be what you mean, but I'm not sure what the designer will do with it, unfortunately...
I'm not even sure that's what you're after though - that's normally for two types from different assemblies with the same name.
You can write namespace aliases with a using directive, e.g.
using FooControl = Foo.Bar.Control;
but again, the designer is going to rewrite your code...
OK, this isn't the answer, but it's what I found for a workaround:
namespace FooBar
{
class FooBarControlHack : Foo.Bar.Control { }
}
So I can do the following in the Designer.cs :
this.fooBarControl = new FooBar.FoorBarControlHack();