xsharp.eu • system.net.mail reference
Page 1 of 1

system.net.mail reference

Posted: Thu Jun 22, 2017 12:08 pm
by info@task.si
I am trying to import small DLL from Vulcan (Visual Studio) and to test X# using XIDE 1.09.
I can't add reference system.net.mail in order to use SMTP functions with authentcation. Why is this namespace (reference) missing in the list offered by XIDE ?
/* ----- a part of imported code
// OK
#using System.Windows.Forms
// OK
#using System.Runtime.InteropServices
// OK
#USING System.Net
// not in the list --- error
#USING System.Net.Mail

BEGIN NAMESPACE SMTP_X#_Lib
*/

---
TIA, Andrej

system.net.mail reference

Posted: Thu Jun 22, 2017 1:03 pm
by FFF
Andrej,
just made a new X# basic app.
"Using System.Net" is suggested by intellisense, as ist System.Net.Mail
Albeit, the latter took some time to "appear" ;) - but i simply typed and compiled without any error.

Karl

system.net.mail reference

Posted: Thu Jun 22, 2017 4:36 pm
by Chris
Hi Andrej,

References and namespaces are completely different things, unfortunately MS has messed up bigtime in this area and made it needlessly complicated, but in short:

- Namespace is the part of a class name that appears before the last dot (if any). So, in class name "System.Windows.Forms.CheckBox", the part "System.Windows.Forms" is called the "namespace". Similarly, in System.Collections.ArrayList, the "System.Collections" part is the namespace. Namespaces are nothing concrete, they are just a naming convention, a way to logically group together many classes with similar scope. Also a class can have no namespace at all (like all classes did in VO).


- References are practically just simple (.Net) dll files (usually called "Assemblies" in .Net) and you choose which ones to use in your apps with the Add References option. Typical such system dll files include "System.dll", "System.Windows.Forms.dll", "mscorlib.dll" (contains all the most important classes like simple data types etc) etc.

The names of the system dlls probably sound like they imply that there's a 1:1 relevance to the namespace of the classes they contain, but unfortunately this is far from true. So for example, System.Windows.Forms.dll indeed contains a class named "System.Windows.Forms.CheckBox", and System.drawing.dll contains "System.Drawing.Point" which makes sense, but System.Windows.Forms.dll also contains class "System.Drawing.BitmapSelectot". And System.Drawing.dll contains a class named "System.Windows.Forms.DpiHelper"! I know it looks very weird, it just needs some getting used to.

In your case, you need to use some classes like "System.Net.Mail.MailMessage", "System.Net.Mail.Attachment" etc. If you search about those classes in msdn:

https://msdn.microsoft.com/en-us/librar ... .110).aspx

you will see in the top of the page:

Attachment Class: Represents an attachment to an e-mail.
Namespace: System.Net.Mail
Assembly: System (in System.dll)

which tells us that this class is defined inside the assembly (dll) System.dll. So, first thing you need to make sure is your app has a reference to this dll, you can open the Application Properties, References page and add this (from the "GAC" list) if it is missing. Alternatively you can press the "Select from template" button and select "Standard Full Framework" to automatically add some commonly used references.

After doing that, now you can use "USING System.Net.Mail" in your code. This tells the compiler to go through all the dlls in the references list and search for classes with names that have this namespace. If no such class is found, then an error is reported (as in your case earlier, because there was no reference to System.dll, so no class was found with that namespace), otherwise the compiler let's you use the "short" names of those classes, for example simply "LOCAL oMessage AS MailMessage" instead of "LOCAL oMessage AS System.Windows.Forms.MailMessage".

Well, this turned out much longer than the "in short" I said in the beginning :) Hope I helped making things clearer and not even more complicated!

Chris

system.net.mail reference

Posted: Fri Jun 23, 2017 10:10 am
by info@task.si
Thanks Chris and Karl.
Using "System" regerence solves the problem.
My intention with this message was also to clarify why in the GAC list "system.net.mail " reference
SMTP_Lib.png
SMTP_Lib.png (27.27 KiB) Viewed 535 times
SMTP_Lib.png
SMTP_Lib.png (27.27 KiB) Viewed 535 times
is missing.
See attachment.
Best regards, Andrej
SMTP_Lib.png
SMTP_Lib.png (27.27 KiB) Viewed 535 times

system.net.mail reference

Posted: Fri Jun 23, 2017 10:28 am
by Chris
Hi Andrej,

There does not exist a references "System.Net.Mail" because there does not exist a file System.Net.Mail.dll. Most of the email related code is located inside System.dll (not even in System.Net.dll, I think you don't need this reference at all), this is why you needed to add the reference to System.

Chris

system.net.mail reference

Posted: Fri Jun 23, 2017 10:38 am
by wriedmann
Hi Andrej,

please let me add something: when programming, you will need a Microsoft reference anyway, and look at the "Assembly" information.

Only with this information you have a guarantee to add the right reference DLL.

For the correct namespace in XIDE: a right click on the name of the class should open the context menu. Select "Search for type named xx in namespaces" and in most cases XIDE will find the correct namespace and add it on the of your file.
Most of the time this is faster than typing a long using like "using System.Collections.Generic".

Wolfgang