Cannot resolve System.Linq namespace - linq

Working in a standard visual studio 2013 web app, I realized that it seems not possible to resolve the System.Linq namespace, e.g. on
mylist.Sum(...)
in a class when using System.Linq is missing in the code. You have to add
using System.Linq
manually, which is possible (references are added to project). What is the reason for this?

All the LINQ methods are extension methods. The compiler only knows which extension methods you're interested based on which using directives are present in your code, e.g.
// Imports extension methods from all static classes in the
// System.Linq namespace
using System.Linq;
// C# 6 only: imports extension methods from System.Linq.Enumerable only
using static System.Linq.Enumerable;
That's just how extension methods work... it's not LINQ-specific.

Related

How to fix namespace path after renaming a folder in visual studio?

I've been practicing Caliburn.micro with mvvm pattern.. till I noticed that I have named the folder"ViewModels" ModelViews which in regards to caliburn doesn't work unless you specify the standard names, but after renaming it I noticed it that visual studio still uses the old path for example when I try to call the class LoginViewModel it automatically calls this path:
using Login2.ModelViews;
event if I try to manually type using Login2.ViewModels;
it doesn't recognize it.
Any suggestion would be appreciated I don't want to restart my project.
I just solved the problem by naming the namespace of the ViewModel classes
from namespace Login2.ModelViews to namespace Login2.ViewModels hopes this will help someone in the future ^-^

System.Data.Linq not loaded in MVC .NET 4.5

I have an ASP.NET MVC4 Web Application project in .NET 4.5 (VS 2012). It is in VB.
It fails loading System.Data.Linq namespace (with all classes and sub-namespaces).
Project has a reference set to System.Data.Linq.dll.
Any ideas where is the problem?
When I try to add Linq2Sql classes, I get such warning:
Namespace or type specified in the Imports 'System.Data.Linq' doesn't contain
any public member or cannot be found. Make sure the namespace or the type is
defined and contains at least one public member. Make sure the imported element
name doesn't use any aliases.
and such errors:
System.Data.Linq.DataContext
But this is just a beginning: if I try to use anything from System.Data.Linq namespace I get an error, for example if I try to use System.Data.Linq.Mapping.DatabaseAttribute, I get such error:
Type 'System.Data.Linq.Mapping.DatabaseAttribute' is not defined.
I had this same problem - and was able to get past it. I'm not entirely sure which of these steps resolved the issue - but this is what I did.
I had originally created the dbml under app_code/gcm
I removed references to System.Data.DataSetExtensions
I deleted the dbml and recreated it outside of the app_code folder
I built the project (no errors/warnings)
I moved the dbml back to the app_code folder and rebuilt (again no errors/warnings)
Hope that helps you get around this.

ASStream extension method not found

I am trying to write a metro style application to read data from a TCP stream. I am using Visual C++.
The problem is that the ASStream extension method cannot be found.
I have the following directives:
#using <System.Runtime.InteropServices.WindowsRuntime.dll>
using namespace System::IO;
using namespace System::Runtime::InteropServices::WindowsRuntime;
ASStream is supposed to be part of WindowsRuntimeBuffer class in the System.Runtime.InteropServices.WindowsRuntime namespace. But object browser clearly does not show that class in the System.Runtime.InteropServices.WindowsRuntime namespace.
Only native C++ is supported for Metro style applications. C++/CLI is not supported and the .NET Framework is not directly supported from a native C++ component.

Accessing Classes from an external project folder in C#

First off here is my file structure
Services.Abstraction.Common
Services.Abstraction.Claims
Services.Abstraction.Clearance
In Visiual Studio 2010, I am in the Claims project and I want to access classes from the Common layer which is on the same level as both Claims and Clearance. I use the namespace below in the Claims project. However it is saying the Common doesn't exists and all the functions that are in the Common folder also don't exist.
using System.Collections.Generic;
using System;
using System.Xml;
using System.Xml.Serialization;
using Services.Abstraction.Common;
How do I fix this? Do I have it wrong in the namespace or do I have to add something to my assembly?
http://msdn.microsoft.com/en-us/library/7314433t(v=vs.80).aspx
There is not much to say here... this link explain you how to add a reference in visual studio, probably you problem is that you are missing a reference to the other dll or project, am I wrong?

Adventures on Enterprise Library 5.0: Who moved my cheese (namespace)

Jesus, Krishna, Budda!
I've migrated to EntLib 5.0, but classes like ISymmetricCryptoProvider are not recognized anymore. Funny to say that Data, Logging and other blocks are working compiling fine.
Here's the problematic class:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;//-->it's not working anymore
using Microsoft.Practices.EnterpriseLibrary.Security.Cryptography;//-->it's not working anymore
namespace MyClassLibrary.Security.EnterpriseLibrary
{
public sealed class Crypto
{
public static ISymmetricCryptoProvider MyProvider
{
get
{
//IConfigurationSource is not recognized either, neither SystemConfigurationSource
IConfigurationSource cs = new SystemConfigurationSource();
SymmetricCryptoProviderFactory scpf = new SymmetricCryptoProviderFactory(cs);
ISymmetricCryptoProvider p = scpf.CreateDefault();
return p;
}
}
The references are fine on project too. I really don't know why this particular project it's causing too many trouble on VS2010! Older references were deleted, project was cleaned, rebuilt, but can't make it compile :-(
The references are:
Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.EnterpriseLibrary.Logging
Microsoft.Practices.EnterpriseLibrary.Logging.Database
Microsoft.Practices.EnterpriseLibrary.Security
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography
Why some namespaces can be found while others can't?
Based on the 4.1 references that you have, you are still referencing the Enterprise Library 4.1 assemblies. You need to remove those references and add references to the Enterprise Library 5.0 assemblies.
The cryptography block should be usable as is without changing your code. Also make sure to update the "references" in all of your configuration files.
Share the command-line when building (output window, csc.exe command line with all the -r's to see what references are going to the compiler)? It might suggest the problem.

Resources