Sending mail with ASP.Net vNext - c#

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

Related

Is it possible to use both Microsoft.Graph and Microsoft.Graph.Beta in the same app?

I'm writing some C# code targeting .NET 4.8, which needs to use Microsoft Graph. It works OK with Microsoft.Graph SDK (V1), however when I try to switch to Beta, I'm getting compilation errors like
Error CS0433 The type 'GraphServiceClient' exists in both 'Microsoft.Graph.Beta, Version=0.29.0.0 <...>' and 'Microsoft.Graph, Version=1.19.0.0 <...>'
The reason being that one other nuget I'm using, namely SharePointPnPCoreOnline, unfortunately depends on Microsoft.Graph 1.19.
It would seem that there should be no problem using both assemblies, as - according to the current documentation (https://learn.microsoft.com/en-us/graph/sdks/use-beta) - Beta should use its own namespace:
using Microsoft.Graph.Beta;
Unfortunately it is wrong, both libraries share the same namespace Microsoft.Graph. The code above results in
Error CS0234 The type or namespace name 'Beta' does not exist in the namespace 'Microsoft.Graph' (are you missing an assembly reference?)
I'm trying to use compiler options to resolve the assembly, but it's extremely convoluted under VS2019 - so far no luck.
But I'm wondering why can't I find anything on this issue, I'm surely not the only one - can it be that I miss something obvious? Please help :)
Not sure if you solved this, but I solved this by adding an alias to Microsoft.Graph.Beta package. Then when referencing, add this to be able to reference your beta-endpoints or resources. Change MSGraphBeta to whatever you added as an alias to your package.
extern alias MSGraphBeta;
using GraphBeta = MSGraphBeta.Microsoft.Graph;

How to solve CS0246 The type or namespace name 'TypeNameSerializer' could not be found (are you missing a using directive or an assembly reference?

I have a .net framework class library project which is absolutely working fine with the .net framework projects, Now I need to refer it in .net core application also. so I am trying to create a new .net standard project and copied all the .cs files to this project from the existing project. and started fixing the compilation errors. I have fixed many but still getting a few.
_rabbitBus = RabbitHutch.CreateBus(
ConfigurationManager.ConnectionStrings[queueName].ConnectionString,
serviceRegister => serviceRegister.Register<ISerializer>(
serviceProvider => new JsonSerializer(new TypeNameSerializer())
)
);
I am getting the below error with the code mentioned above.
CS0246 The type or namespace name 'TypeNameSerializer' could not be
found (are you missing a using directive or an assembly reference?)
So How to solve this issue?
Note: I have fixed the compilation error b using this code new JsonSerializer(new Newtonsoft.Json.JsonSerializerSettings()) , but I don't know whether its correct way or not, So please guide me how to solve this issue.
Looks like different versions of EasyNetQ are being used in .NET Framework and .NET Core.
The latest version of EasyNetQ does not have any class with name TypeNameSerializer that's why you are getting this error.
Also class JsonSerializer in latest version of EasyNetQ does no have a constructor which accepts TypeNameSerializer as a parameter.
You can refer to Git Repo of EasyNetQ and also the Source Code of JsonSerializer class.
You need to use the same version of EasyNetQ in .NET Core as it is being used in .NET Framework project in order to use TypeNameSerializer.

.NET Code System.Web install source

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

The type or namespace name 'Core' does not exist in the namespace

I encounter this kind of error when I debug a project
I already have EntityFramework.dll, System.Core.dll, System.Data.Entity but still Core is not referenced.
Can someone help me?
I'm having error in this Line
using System.Data.Entity.Core.Objects;
This is the error:
The type or namespace name 'Core' does not exist in the namespace 'System.Data.Entity' (are you missing an assembly reference?)
Enrique, I had this problem crop up when I started opening a project on my desktop that I had normally been opening on my VM. Masoud's answer is not helpful... I don't think he read your original post.
What I did to clear this compile error up was to open NuGet package manager and install the update that was available for EntityFramework. I had version 6.1.1 installed in the project and I upgraded to 6.1.3. I should not have had the error to start with, but upgrading the version appeared to jiggle whatever it was loose because I started compiling fine after that.
Sometimes, when you add references from other sources than nuget manager (example: Local source) you need to verify the HintPath of that reference before moving your application in another environment

Tweetinvi namespaces are not recognized although dll's are present

I'm using creating a .Net 4.0 application to post stuff to Twitter using the Tweetinvi API. I can't use packages, so I've downloaded the dll's and added them to my project:
Yet my includes are showing errors:
My error console shows:
Error 423 The type or namespace name 'Core' does not exist in the
namespace 'Tweetinvi' (are you missing an assembly
reference?) {...file...}.cs 10 17 ApiProviders
Can anyone tell me why this happens and how I could fix this?
Tweetinvi requires the Bcl.Async package. You need to add that too.
Check all the dependencies and make shure all are installed.
BUT as already said I highly recommend using NuGet for this. If you are not allowed to use the "public feed" you can download the packages and put them in a local folder and add this folder as a new feed in Visual Studio.
Have you tried downloading the project from the download page?
https://tweetinvi.codeplex.com/downloads/get/852208

Categories

Resources