Incomplete System.Collections.Generic in Visual C# 2010 Express - c#

I'm trying to access System.Collections.Generic.Stack<> in Visual C# 2010 Express, but the IDE (and compiler) claim that it's not present. Several other classes are also missing, including LinkedList<>, SortedList<> and Queue<>. I've checked the documentation for both the System.Collections.Generic namespace and C# Express, and can find no reference to any deliberate limitations.
Oddly enough, if I sort the documented contents of the System.Collections.Generic namespace alphabetically, everything after List<> is missing, but that may just be a very weird coincidence.
Edit:
I tried a commandline build using MSBuild, which also complained with error CS0246. However, using csc worked.
Followup:
I tried removing all resources from my project and adding a stub class which just created an instance of Stack<>. Not only did that work, everything still worked after adding the old class back in and removing the stub. I can only assume there was some kind of caching silliness going on. Very annoying. I'll re-open if this issue reappears.

I expect that your project is missing a reference to System.dll.
Check whether "System" is listed under "References" in the solution explorer. If not, right-click References, choose "Add Reference...", and add a reference to "System".
Note: List<T> is in mscorlib.dll, and all collections that are alphabetically after List<T> are in System.dll, which is why I think this is what's happening.

Related

Visual Studio does not recognize a referenced assembly?

Opened an old project from years ago. Build fails because Visual Studio (2019) does not recognize an assembly that is clearly there - specifically, Autofac.
You can see it in project references (not marked as missing)
You can see it in the Object Browser, listing all the types referenced in the code
But in code, none of the types show up, gone AWOL.
What is going on here? Intellisense doesn't even pick up types
(Tried cleaning, rebuilding, re-importing packages)
Okay, this is what worked. I had to remove the reference to the Autofac dll, and then add it back. Note - I added it back from the same exact location, the same exact version. But after this, Visual Studio 'magically' recognized it.
If you come across a similar problem, and nothing else works, give it a try. I don't know the reason, I can only assume this is some sort of a bug in Visual Studio.

System references not being recognized?

I am not entirely sure how to better word this question, as I am not entirely sure what the central cause is to these various reference problems, so I apologize in advance for the vague title.
I am writing apps in VS 2012 Express for Windows 8, targeting a winRT (ARM) surface tablet.
I am having multiple problems with references apparently being recognized in their entirety. For simplicity, let me illuminate with some examples.
I am writing some code involving SOAP xml.
First, if I reference "System.Xml" (as well as System.Xml.Linq) by explicitly including a "using.." line, it doesn't seem to actually do anything.
using System.Xml.Linq;
using System.Xml;
...
XmlDocument xmldoc = new XmlDocument();
throws "The type or namespace name 'XmlDocument' could not be found"
Likewise if I am more explicit:
using System.Xml.Linq;
using System.Xml;
....
System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
throws "The type or namespace name 'XmlDocument' does not exist in the namespace 'System.Xml'" as well as the original error message.
Ok. I'm clearly missing something, but there's tons of google results for things like this.
I am running VS2012 on Windows 8 installed on VirtualBox, and thinking perhaps my installation was hosed, I first tried simply reinstalling VS2012, then repairing the installation when this did not seem to affect anything.
Next, I tried manually adding the reference to the .dll files in question. When I tried this, VS would not allow it, saying they are already included by default.
Next, I tried manually opening the .csproj file for my project, and adding Reference Include = "... lines for a few references which I seemed to be missing (like I said, I'm just using System.Xml as an example.) This didn't appear to change anything, as I was getting exactly the same errors.
Next, I went into "Add or Remove Programs" on a google-inspired hunch and, through Control Panel -> Add/Remove Programs, I turned on .Net Framework 4.5 Advanced Services. This unfortunately did not seem to have any effect.
Adding various .dll-containing paths to "Reference Paths" also did not seem to affect anything at all (that field was empty upon first installing VS.)
I am stumped. Am I missing .dlls or other files, even after repeated re-installation and repairs?
Note that I was able to at least create an XmlDocument by referencing Windows.Data.Xml, Windows.Data.Xml.Dom but that namespace seems to be lacking some methods I need.
System.Xml.XmlDocument is not available for Windows Store applications. Take a look at the MSDN page - classes, methods, and properties marked with the green shopping bag are the only ones you can use with Windows Store apps.
As for System and Windows namespace references, all of the ones you can use are already part of the .NET for Windows Store apps Reference in your project, so there's nothing that can be added.
You probably need to actually add the reference to the dll in your project.
see the following link for details
http://msdn.microsoft.com/en-us/library/wkze6zky.aspx
(The System.XML, and System.XML.Linq should be in the .Net tab)

Class Library Intellisense not showing up after adding the dll to the references

In C#, I made a ClassLibrary that has one Namespace and one Class.
I saved it and build it.
in other Projects, when i use it, I add it to my references by browsing to the .dll location.
But The Problem is that its name is not showing up in the Intellisense.
i.e when I: using ... my dll doesn't show ..
I'm Importing the library to a ConsoleApp.
both of the App and the library target Framework is .NET Framework 4.0
and I made their Assembly Version 4.0.0.0 so they're the exact same.
is there a setting or something that I'm missing ?
how can i make it pop up ?
I'm using VS2010 Professional
Thank you for your help
Maybe this be usefull, I was having a similar issue, I have a Web project, add the reference to a Class Library by selecting the project, but if I made a change on the class library, I canĀ“t see that change on the intellisense of the Web Project, after try many things, I see that in the recently added reference, the value of the option "Local Copy" was set "True", then I change it to false and everething works!
I had a similar issue but in my case it was a property on the class. If you go to the file properties and look for a Build Action. Somehow mine was set to Content it had to be set to Compile.
I am using Visual Studio 2013. I hope this helps someone else.
Is the namespace for your assembly different than the namespace for your currently open project? I've had times when the current project and an assembly share the same namespace path the intellisense can mess up.
In general, Visual Studio is pretty good about intellisense generation, especially for C#. But sometimes there are some interesting conditions regarding ambiguities, and especially mixing project types where it just doesn't quite work.
Placing your content in the same namespace makes me wonder if you've actually fixed the problem (it may just be autocompleting the namespace in the currently loaded project rather than the assembly), but if it allows you to continue working, then go with it!
Right click on project on which you add reference of your dll/project select menu project dependancies and select/MarkCheckBox for reference project/dll. then it will work fine.
If the class library project had its name changed after creation, then intellisense may fail finding it due to directory issues, I believe.
I created my class with the generic "ClassLibrary1" or whatever, and then later changed the default namespace, class name, and project name inside of VS2017. I closed VS2017 and changed the directory name to match my default namespace, and then re-associated the project file in VS2017, and then re-added the reference in my main project file.
All seems to be fixed now.

How can I access the currently opened project's types(classes) from a Visual Studio add-in?

How can I access the currently opened project's types(classes) from a Visual Studio add-in(be able to create instances of those classes within the add-in)? Is this possible through reflection? Or maybe dynamically include the project's assembly as a reference?
What I'd like to have in the end is a list of all types accessible from the project, taking into account referenced assemblies and types declared in the project itself. In absence of a method to actually find Type instances, a list of type names may do - this way, I won't run into problems if the project is not yet built and the types therein are not yet implemented.
I use Visual Studio 2008 and the language I prefer is C#.
Edit: I imagine I could parse each file and seek out class declarations, but I'd like to consider types from referenced assemblies as well. The references may be sought after by searching for "using" statements, but that leaves dynamically imported dll types an open issue. Thus, given the branching of separate situations to consider, I'm wondering if there isn't an easier way.
Sure, just get the assembly from the output directory and load it. I am not working on any EnvDTE projects right now so I can't just pop in and knock out a sample, but that is how you would be able to enumerate/instantiate classes.
But.... nobugz is hinting that something smells.. What are you trying to do? There may be a 'better' way to do it.
The Visual Studio code model offers automation clients the ability to discover code definitions in a project and modify those code elements.
For more information go to:
http://msdn.microsoft.com/en-us/library/ms228763(VS.80).aspx

Why can't I reference my class library?

I have a solution that contains a website and a class library in Visual Studio 2008.
I then have another web site project outside of the solution that needs to reference the class library. I right click the Bin folder or Project and select Add Reference, then select my Class Library Project, it adds the 15 or so DLLs that the class library needs to the websites bin folder, but none of the .cs files recognize the using statements.
using MyLibrary.MyFolder;
It says that it can't resolve it, and ReSharper just says it can be safely removed since it's not being used.
ReSharper can recognize that it needs the reference and suggests that it "Reference MyLibrary and use MyFolder". I'm not sure why it's suggesting I add a reference I already have. When I go with the suggestion, I get the error
"Failed to reference module. Probably, reference will produce circular dependencies between projects."
I've tried going to the websites property pages and removing all the references and re-adding them, but it gives the same errors. Any ideas why this isn't working?
Also, check that the new solution's projects run against a compatible framework to the project you're trying to include. I was trying to include a reference to a 4.0 project in a 3.5 project.
I found how to fix this issue (for me at least). Why it worked, I'm not sure, but it did. (I just tried against a second website that was having the same problem and the following solution worked for that as well).
I tried the normal cleaning of the projects and rebuilding, shutting down all my Visual Studio instances and restarting them, even tried restarting my computer.
What actually worked was opening up the project in Visual Studio, closing all the open tabs, and then shutting it down.
Before I had left the tabs open because I didn't think it mattered (and I hardly ever close the tabs I'm using).
One possibility is that the target .NET Framework version of the class library is higher than that of the project.
I had a similar problem, will all my references being buggered up by Resharper - The solution which worked for me is to clear the Resharper Cache and then restarting VS
tools->options->resharper->options-> general-> click the clear caches button and restart VS
I had a similar problems where VS would sometimes build and sometimes not. After some searching and attempts I discovered that I had an ambiguous reference to a class with the same name in different libraries ('FileManager'). The project that would not build were my Unit Tests that reference all modules in my solution. Enforcing the reference to a specific module sorted things out for me.
My point is: Rather than blaming ReSharper or VS, it may be a good idea to double check if there really isn't some kind of circular reference somehow. More than often, classes with the same names in different modules could cause confusion and is often a symptom of bad design (like in my case).
This sounds like a similar issue with ReSharper:
http://www.jetbrains.net/devnet/thread/275827
According to one user in the thread forcing a build fixes the issue (CTRL+Shift+B) after the first build..
Sounds like an issue with ReSharper specifically in their case.. Have you tried building regardless of the warnings and possible false errors?
Since they are both in the same solution, instead of adding a reference to the DLL, add a reference to the class library project itself (the Add Reference dialog will have a tab for this).
Ahh, it's a different solution. Missed that. How about you try instead of adding a reference to the project addding a reference to the compiled DLL of your class library. The Add Reference dialog has a Browse tab which does this.
After confirming the same version of asp.net was being used. I removed the project. cleaned the solution and re-added the project. this is what worked for me.
If you're referencing assemblies for projects that are in the same solution, add a Project reference (using the "Projects" tab) rather than browsing for the dll in the \bin\Debug (or \bin\Release) folder (using the "Browse" tab). See screen shot below. Only browse for the assembly/dll file if it's considered an external assembly.
I deleted *.csproj.user ( resharper file) of my project, then, close all tabs and reopen it. After that I was able to compile my project and there was no resharper warnings.
I had this problem. It took me ages to figure out. I had people over my shoulder to help. We rebuilt, cleaned and restarted Visual studio and this didn't fix it. We removed and re-added the references...
All to no avail.... Until!
The solution to my problem was that my class declaration was spelt incorrectly.
Before you start judging me harshly, allow me to explain why it wasn't stupid, and also why this mistake could be made by even the most intelligent of programmers.
Since the mistake was early on in the name, it wasn't appearing in the intellisense class listing when I began typing.
e.g.
Class name:
Message.cs
Declaration:
public class Massage
{
//code here
}
At a glance and in a small font, Massage looks identical to Message.
Typing M listed too many classes, so I typed e, which didn't appear in the mistyped version, which gave the impression that the class wasn't being picked up by the compiler.
I had a similar issue in VS 2010, when creating a test project for an MVC 2 application.
The symptoms were identical.
The message from ReSharper was somewhat misleading. For a moment I completely ignored ReSharper and did it the "manual VS way":
I cleaned the solution.
I manually added the reference to the MVC project.
I manually added the using directives.
ctrl-shift-b
At this stage I got a compilation error: I should have referenced the System.Web.Mvc assembly in my test project (sigh). Adding this reference causes the project to compile. The ReSharper issues remain, but the ReSharper test runner works.
When I restart VS, the ReSharper errors are gone too. I'm not sure if the restart is required - simply closing the .cs file might be enough.
From now on, when I see the ReSharper message
Failed to reference module. Probably,
reference will produce circular
dependencies between projects.
I'll read
Failed to reference module. Probably,
reference will produce circular
dependencies between projects,
or you are missing some references to dependencies of the reference's dependencies.
Another possible fix that just worked for me:
If you have Assembly A, which references Assembly B, both of which reference a non-project (external) assembly X, and Assembly B's code will not recognize that you have referenced X, then try the following steps in order:
Drop reference to X from BOTH A and B
Recreate reference to X in B
Recreate reference to X in A
Apparently, VS will not recognize a reference to an external assembly in a project that is a dependency of another project that already references the external. By setting up the references again from the ground up, you overcome this. It's just very odd.
I faced this problem, and I solved it by closing visual studio, reopening visual studio, cleaning and rebuilding the solution. This worked for me.
If using TFS, performing a Get latest (recursive) doesn't always work. Instead, I force a get latest by clicking Source control => Get specific version then clicking both boxes. This tends to work.
If it still doesn't work then deleting the suo file (usually found in the same place as the solution) forces visual studio to get all the files from the source (and subsequently rebuild the suo file).
If that doesn't work then try closing all your open files and closing Visual studio. When you next open Visual studio it should be fixed. There is a resharper bug that is resolved this way.
I had stumbled upon a similar issue recently. I am working in Visual Studio 2015 with Resharper Ultimate 2016.1.2. I was trying to add a new class to my code base while trying to reference a class from another assembly but Resharper would throw an error for that package.
With some help of a co-worker, I figured out that the referenced class existed in the global namespace and wasn't accessible from the new class since it was hidden by another entity of same name that existed in current namespace.
Adding a 'global::' keyword before the required namespace helped me to reference the class I was actually looking for. More details on this can be found on the page listed below:
https://msdn.microsoft.com/en-us/library/c3ay4x3d.aspx
If both projects are contained within the same solution, it will be more apropiate if you add the reference for the project you need, not its compiled dll.
I had the exact same problem.
I tried closing Visual Studio numerous times, I tried deleting and adding a new class library.Checked if I had the right version, if I had referenced it in the target project. Nothing worked.
Then I thought maybe, just maybe I cannot reference the library because it was empty... and that was it.
As soon as I added a class to it the problem was fixed. So if you have tried everything and you are close to losing your sanity. Just try adding something to the class library.
the solution for was just adding the access modifier
my class didnt have any access modifier then i just added public and it worked!
Contracts class library:
namespace Contracts
{
public interface ILoggerManager
{
void LogInfo(string message);
void LogWarn(string message);
void LogDebug(string message);
void LogError(string message);
}
}
Logger service class library:
using Contracts;
using NLog;
public class LoggerManager : ILoggerManager
{
private static NLog.ILogger logger = LogManager.GetCurrentClassLogger();
public LoggerManager()
{
}
}
I tried various solutions for this issue. An old WebForms application refused to acknowledge the existence of a library even though a reference existed.
Oddly, what worked was to add and reference the class library in Visual Studio 2022, safe the project, then reopen in an earlier version of Visual Studio.
My solution was simple, but I'll share it in case someone else has the same issue and finds this question by googling like I did.
It turns out that the most recent build of the supporting DLL was done in Debug mode, and my code was looking at the Release version of the DLL. I rebuilt the DLL in Release mode and all is working properly.
Unfortunately the only thing that worked for me was completely deleting and recreating the class library project, after having temporarily copied the class files in it elsewhere. Only then would the ASP.Net web project recognise the using statements that referred to the class library project. This was with Visual Studio 2010, not using ReSharper.
I had similar issue. What worked for me is that I had added wrong Class Library from visual studio. I added by using the search feature of visual studio.
What I needed to do was Add New Project > Visual C# > Class Library. And this newly added class library is the right one and can now be added as reference to any project.
You may forget to add reference the class library which you needed to import.
Right click the class library which you want to import in (which contains multiple imported class libraries), -->Add->Reference(Select Projects->Solution->select the class library which you want to import from->OK)

Categories