Using Visual Studio Code on my mac book on sort of a Hello World type app. However, when I try to include a reference to System.Web, I get an alert stating:
The type or namespace name 'Web' does not exist in the namespace
'System' (are you missing an assembly reference?) [netcoreapp1.0]
Unnecessary using directive. [netcoreapp1.0]
I obviously supposed to add a reference System.Web, but giving the relative newness of this, I'm not sure of which nuget package I should apply to the project.
Any advice will be helpful.
Removed System.Web dependence is one of the benefit of ASP.NET Core, that by the way allows to build and run cross-platform ASP.NET apps. From ASP.NET Core documentation:
ASP.NET Core has a number of architectural changes that result in a much leaner and modular framework. ASP.NET Core is no longer based on System.Web.dll. It is based on a set of granular and well factored NuGet packages.
Don't know about source with nuget package descriptions, but you can start from searching in https://github.com/aspnet for appropriate project
Related
I've created a .NET 5.0 project, one of the dependencies I have is on this API:
AnalyticsInfo.VersionInfo.DeviceFamily
After installing Microsoft.Windows.SDK.Contracts, I'm able to use this API. Then, I needed to install the Microsoft.Windows.CsWinRT package to resolve this error:
Error NETSDK1130 Referencing a Windows Metadata component directly when targeting
.NETCoreApp,Version=v5.0 is not supported.
Use the C#/WinRT projection tool (https://aka.ms/cswinrt) or a provided projection for this target.
After installing this, I no longer have access to the Windows.System.Profile namespace to call the AnalyticsInfo API:
Error CS0234 The type or namespace name 'System' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
With .NET 5, built-in support for WinRT APIs in .NET is removed (because it's Windows specific) , so we can't use Microsoft.Windows.SDK.Contracts any more.
The solution as explained here Built-in support for WinRT is removed from .NET is to
Remove references to the Microsoft.Windows.SDK.Contracts package.
Instead, specify the version of the Windows APIs that you want to
access via the TargetFramework property of the project. For example:
<TargetFramework>net5.0-windows10.0.19041</TargetFramework>
Note with that in place, there's no need to manually add a reference to C#/WinRT (Microsoft.Windows.CsWinRT) it should be done automatically and shown as "Microsoft.Windows.SDK.NET.Ref" in the list of Frameworks Dependencies.
In legacy ASP.Net and .Net in general, sending mail was accomplished via System.Net.Mail classes which resided in System.dll. Now with KRE, vNext doesn't seem to have System.Net.Mail as a separate package.
Referencing the "net453" framework in project.json
"frameworks": {
"aspnet50": { },
"aspnetcore50": { },
"net453": {} // <<< throws compilation errors
},
causes all hell to break loose with errors like:
.NET Framework 4.5.3 error CS0234: The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
It virtually complains about all vNext dependencies that are part of kpm packages.
So, has anyone figured out a way to send mails using ASP.Net vNext yet?
Note
Even though System appears under References and even though Intellisense shows System.Net.Mail is available for use, the code doesn't compile. E.g., a simple statement like this, although appears valid,
using System.Net.Mail;
var m = new MailMessage();
will throw compilation error such as:
ASP.NET Core 5.0 error CS0234: The type or namespace name 'Net' does not exist in the namespace 'System' (are you missing an assembly reference?)
ASP.NET Core 5.0 error CS0246: The type or namespace name 'MailMessage' could not be found (are you missing a using directive or an assembly reference?)
Update
With latest Visual Studio 2015 CTP 5, they seemed to have fixed the intellisense glitch. Now System.Net doesn't have Mail namespace anymore. On a side note, the vNext project I created with VS 2015 preview is no longer working - I get an 403.3 error on the home page! Ah, the joy of working with beta software!
To use System.Net.Mail your app can target only aspnet50. The aspnetcore50 target has no such support (at least, not right now, as far as I know).
You shouldn't ever have your app target net453 (which, as Luca mentioned in a comment, has since been renamed anyway) because ASP.NET 5 apps don't run on that platform.
An app that targets aspnet50 can generally reference any .NET 4.0+ NuGet package or GAC reference.
So, in your case, remove the net453 and aspnetcore50 targets, and within the aspnet50 target add a framework reference to System.Net.Mail.
A complete alternative would be to find some other existing NuGet package that has support for sending email in both aspnet50 and aspnetcore50, but I doubt such a package exists at this time (though it no doubt will at some point in the future).
To follow up... .NET team has stated that porting System.Net.Mail will be less than straightforward and will likely take a while. That's a bummer since a production website usually does more than a little email sending.
In the meantime, someone just released a Core-Clr compatible email API called MailKit. You can read about it here https://github.com/jstedfast/MailKit/issues/212
I have two projects in the same solution.
One is an ASP.NET MVC 2 Empty Web Application,
the other is a Console Application.
In the first project i create a database with EF and a class to access the database.
What I want to do is add the first project as a reference to the console app project so i can use this class
I included it as a reference already it appears at the References, and after is include a using directive at the top of my console app i can even use code assistance. But when i compile i always get the error:
The type or namespace name 'DBModel' could not be found (are you missing a using directive or an assembly reference?)
How can i compile my projects?
Sincerely,
Zoli
From your description, if I'm getting it right,
That's often the case when you have different target .NET framework (Project properties, Application, Target Framework) - i.e. one is e.g. .NET 4.0 Client Profile - and the lib you're referencing is just .NET 4.0.
It's also possible that you're missing a reference to the Entity Framework in your Console application.
See this post for more info: http://www.dotnetcurry.com/ShowArticle.aspx?ID=617 (just below the middle, step 3).
Why might "using System.Linq" cause the following error?
The type or namespace name 'Linq' does
not exist in the namespace 'System'
Reference System.Core
And then there are others that merge this namespace too - but that's the primary one on .Net 3.5 and above.
If you're project is currently .Net 2.0, say, and you're using the right version of VS (2005 and above) - you can simply right-click on the proejct properties; and change the 'Target Framework Version' to 3.5. System.Core will then become available.
If you don't see that in the options - then I guess you're using an older VS
The most probable reason is that you are using wrong version of .NET Framework.
Try to add System.Core assembly to your project
You'll get this error if you don't have "System.Core.dll" referenced (the assembly which contains the core LINQ APIs).
System.Linq is available in .Net 3.5 and above version.
Maybe you're targeting an older framework, Linq came in with 3.5 IIRC.
You are using lower version of .NET Framework than 3.5 to compile the source code or you don't have added the System.Core assembly to your project.
Manually type using System.Linq in the starting of the project, you will not be able to find this namespace in add reference dialogue box.
If you are still getting error then try to Add Reference System.Core.
If you are getting an error that it has been already referred then you can unload your project and then edit your csproject file, manually copy reference to System tag and paste and change the name to System.Core and reload the project.
In my case the only thing that worked was:
Adding a new Razor item (e.g. MVC 5 View Page)
That automatically pulls in some NuGet packages
The package that makes System.Linq available to Razor Views IntelliSense seems to be Microsoft.AspNet.WebPages.
This question already has answers here:
Getting "type or namespace name could not be found" but everything seems ok?
(44 answers)
Closed 8 years ago.
I have a C# solution with several projects in Visual Studio 2010.
One is a test project (I'll call it "PrjTest"), the other is a Windows Forms Application project (I'll call it "PrjForm"). There is also a third project referenced by PrjForm, which it is able to reference and use successfully.
PrjForm references PrjTest, and PrjForm has a class with a using statement:
using PrjTest;
Reference has been correctly added
using statement is correctly in place
Spelling is correct
PrjTest builds successfully
PrjForm almost builds, but breaks on the using PrjTest; line with the error:
The type or namespace name 'PrjTest' could not be found (are you missing a using directive or an assembly reference?)
I've tried the following to resolve this:
Removed Resharper (since Resharper had no trouble recognizing the referenced project, I thought it might be worth a shot)
Removed and re-added the reference and using statement
Recreated PrjForm from scratch
PrjForm currently resides inside the PrjTest folder, I tried moving it to an outside folder
Loaded the solution on a different computer with a fresh copy of VS 2010
I have done my homework and spent far too long looking for an answer online, none of the solutions has helped yet.
What else could I try?
See this question.
Turns out this was a client profiling issue.
PrjForm was set to ".Net Framework 4 Client Profile"
I changed it to ".Net Framework 4", and now I have a successful build.
Thanks everyone!
I guess it figures that after all that time spent searching online, I find the solution minutes after posting, I guess the trick is knowing the right question to ask..
In my case I had:
Referenced DLL : .NET 4.5
Project : .NET 4.0
Because of the above mismatch, the 4.0 project couldn't see inside the namespace of the 4.5 .DLL. I recompiled the .DLL to target .NET 4.0 and I was fine.
PrjForm was set to ".Net Framework 4 Client Profile" I changed it to ".Net Framework 4", and now I have a successful build.
This worked for me too. Thanks a lot. I was trying an RDF example for dotNet where in I downloaded kit from dotnetrdf.
NET4 Client Profile:
Always target NET4 Client Profile for all your client desktop applications (including Windows Forms and WPF apps).
NET4 Full framework:
Target NET4 Full only if the features or assemblies that your app need are not included in the Client Profile. This includes:
If you are building Server apps, Such as:
ASP.Net apps
Server-side ASMX based web services
If you use legacy client scenarios, Such as:
o Use System.Data.OracleClient.dll which is deprecated in NET4 and not included in the Client Profile.
Use legacy Windows Workflow
Foundation 3.0 or 3.5 (WF3.0 , WF3.5)
If you targeting developer scenarios and need tool such as MSBuild or need access to design assemblies such as System.Design.dll
Another thing that can cause this error is having NuGet packages that have been built with a newer version of .NET.
The original error:
frmTestPlanSelector.cs(11,7): error CS0246: The type or namespace name 'DatabaseManager'
could not be found (are you missing a using directive or an assembly reference?)
Further up in the log I found this:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3275: The primary reference "[redacted]\DatabaseManager\bin\Release\DatabaseManager.dll" could not be resolved because it has an indirect dependency on the assembly "System.Data.SQLite, Version=1.0.94.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" which was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
The solution was to re-install the NuGet packages:
http://docs.nuget.org/docs/workflows/reinstalling-packages
I solved mine because the other project was coded with .NET 4.5 and the other one was coded 4.0
The using statement refers to a namespace, not a project.
Make sure that you have the appropriately named namespace in your referenced project:
namespace PrjTest
{
public class Foo
{
// etc...
}
}
Read more about namespaces on MSDN:
Using Namespaces
I encountered this issue it turned out to be.
Project B references Project A.
Project A compiled as A.dll (assembly name = A).
Project B compiled as A.dll (assembly name A).
Visual Studio 2010 wasn't catching this. Resharper was okay, but wouldn't compile. WinForms designer gave misleading error message saying likely resulting from incompatbile platform targets.
The solution, after a painful day, was to make sure assemblies don't have same name.
It is also possible, that the referenced projects targets .NET 4.0, while the Console App Project targets .NET 4.0 Client Library.
While it might not have been related to this particular case, I think someone else can find this information useful.
The compiled dll should have public Class.
I had the same issue. The target frameworks were fine for me. Still it was not working.
I installed VS2010 sp1, and did a "Rebuild" on the PrjTest. Then it started working for me.
Other problem that might be causing such behavior are build configurations.
I had two projects with configurations set to be built to specific folders.
Like Debug and Any CPU and in second it was Debug and x86.
What I did I went to Solution->Context menu->Properties->Configuration properties->Configuration and I set all my projects to use same configurations Debug and x86 and also checked Build tick mark.
Then projects started to build correctly and were able to see namespaces.
Changing the framework to
.NET Framework 4 Client Profile
did the job for me.
For COM/ActiveX references, VS 2012 will show this error right on using statement. Which is quite funny, since it's saying that may be you are missing a using statement.
To solve this: register the actual COM/ActiveX dll even if it's in the neighbor project, and add a reference through COM channel, not project channel. It will add Interop.ProjectName instead of ProjectName as a reference and this solves this strange bug.
If your project (PrjTest) does not expose any public types within the PrjTest namespace, it will cause that error.
Does the project (PrjTest) include any classes or types in the "PrjTest" namespace which are public?
just changed Application's target framework to ".Net Framework 4".
And error got Disappeared.
good luck;
:D
check your Project Properties, your Reference Paths should be empty like this:
Regards