I'm getting the following error:
Error 25 The type or namespace name 'IEnumerable' could not be found (are you missing a using directive or an assembly reference?) C:\Development\Leverage\Leverage\Reports\SurveyLevel.aspx.cs 39 17 Leverage
because of this line:
private IEnumerable<string> GetDateParameters()
How do I deal with this? I tried to add in the line:
using System.IDisposable
at the top, but this doesn't fix it.
As others have said, you're missing using System.Collections.Generic;.
But that's giving you a fish; we should be teaching you to catch your own fish.
The way to solve this problem on your own is:
Enter the name of the type into your favourite search engine, and see what comes back:
IEnumerable(T) Interface (System.Collections.Generic)
http://msdn.microsoft.com/en-us/library/9eekhta0
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
See the bit that I highlighted in bold there? That's the namespace that you're missing.
If you still get the error then you are likely missing a reference; you can find out which DLL you have failed to reference by clicking on the link and reading the documentation page; it will tell you which DLL to reference.
You are missing a using System.Collections.Generic; statement at the top of the code file.
The generic IEnumerable<T> type cannot be found directly.
You could declare the full name instead:
private System.Collections.Generic.IEnumerable<string> GetDateParameters()
IEnumerable is in System.Collections
IEnumerable<T> is in System.Collections.Generic
You just need to add System.Collections.Generic namespace top of your code.
IEnumerable<T> belongs on this namespace in mscorlib.dll assembly.
You can use it like;
private System.Collections.Generic.IEnumerable<string> GetDateParameters()
Above answers are good. In my case, even after following the above answers it did not resolve the issue. Still the red squiggly constantly appeared.
Issue was the Framework of the project. It was by default set to .NET Framework 4.0.3 and changing to .NET Framework 4.0.0 will also help.
Save your Project properties after the change, build and it should all work.
Hope this helps.
Related
I get the following error on my page:
Server Error in '/' Application.
The current type, Microsoft.Owin.Security.IAuthenticationManager, is an interface and cannot be constructed. Are you missing a type mapping?
I founded out that I should put this code in Unityconfig.cs to resolve this problem:
container.RegisterType<IAuthenticationManager>(
new InjectionFactory(
o => System.Web.HttpContext.Current.GetOwinContext().Authentication
)
);
But the problem is that the IAuthenticationManager is not visible
although I have added the Owin.Security as reference, I have the
using Microsoft.Owin.Security;
Can you please give me some hints?
Note that the interface you are trying to use (Microsoft.Owin.Security.IAuthenticationManager) isn't in Microsoft.Owin.Security.dll but is actually in Microsoft.Owin.dll. Check the two lines at the top that tell you both the namespace and the assembly. So you just need to add a reference to that assembly.
For situations like this, it's always worth checking the docs as the namespace doesn't always equate to the assembly name.
I'm using a namespace ListExtensionsMethods(defined in file ext.cs) both in my C# dl.dll and in the main.cs file. But when I try to include dl.dll in the main.cs I get about 30 error messages like this:
Warning 2 The type 'ListExtensionsMethods.MachineExtensions' in
'b:\library\C#\ext.cs' conflicts with the imported type
'ListExtensionsMethods.MachineExtensions' in 'C:\path\update.dll'.
Using the type defined in
'b:\library\C#\ext.cs'. C:\path\db.cs 52 39 testing
How do I fix this?
I believe you should be able to use the global namespace, however this warning exists for a reason and you should make sure you really want to use the same namespacing.
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.
Following this tutorial http://msdn.microsoft.com/en-us/vstudio/hh543922.aspx , I'm trying to use the ReplaceNode method that should be in the SyntaxNode class.
The thing is, I have this error: "Roslyn.Compiler.CSharp.SyntaxNode does not contain a definition for 'ReplaceNode'
Any ideas?
ReplaceNode is actually an extension method (so that it can return the type passed in). Make sure you have using Roslyn.Compilers; and using Roslyn.Compilers.CSharp;
Looks like an issue with that version of the CTP. Others are having the same issue, such as http://youtrack.jetbrains.com/issue/DOTP-4774 or http://youtrack.jetbrains.com/issue/DOTP-4836 .
I am trying to use the Label control of ASP.NET as below:
public static bool addData(string storedProcName, string[] dynamicParamName, object[] paramVals, Label msg)
{
msg = "Recorded Added successfully";
cmd2.Connection.Close();
cmd2.Dispose();
}
However, I do not seem to get the "Text" property of Labels, as in msg.Text. Is there something I am missing here? Thank you.
Much as Chris Mullins suggested it looks like you are referring to the wrong type of label.
I am surprised that you aren't getting any comments of ambiguous names if you definitely have the System.Web.UI.WebControls referenced in a using statement. However, you should be able to fix it by either removing the line that you probably have saying "Using System.Windows.Controls" or by changing your reference to lable to be:
System.Web.UI.WebControls.Label lb = new System.Web.UI.WebControls.Label();
Or similar things.
Essentially it all looks like it boils down to ambiguity of the label class in your code.
Check that you have using System.Web.UI.WebControls; in your using section. Other than that you probably have a syntax error somewhere causing .net to not give you the intellisense.
Based on what you said in your comment it sounds like you may be working in a class library, if so make sure you include a reference to System.Web If you have a reference to System.Windows.Forms or a using System.Windows.Forms, you can remove them if you are not using them.
If you include both using System.Windows.Forms and using System.Windows.Forms then the compiler may not know which one you mean when you just say Label, in which case you would have to fully qualify it with all the namespaces.