Porting .Net Assemblies to Mono using MoMA

For those who have not heard about it, Mono is a platform designed to allow porting of .Net-based applications to nearly every computing platform available (including Linux and Mac). It is open-source (sponsored by Novell) and is an essential tool for any developer who wishes to run .Net code on a non-Windows OS.

I am right now in the middle of a Desktop project being written with VS.net 2005, C# and Windows Forms technology. The powers-that-be (ie: the clients) have inquired to the feasibility of potentially porting over the code to Mac or Linux. My answer has been that if it is possible, we will have to use Mono to do it, but I cannot say anything more about its compatibility until more of the programming work is completed.

The process of porting over a completed .Net Assembly to Mono just got a bit easier. A tool called MoMA (Mono Migration Analyzer) has been released (written by Jonathan Pobst) that will do the following: given any .Net assembly (.dll or .exe file) it will go through the file and report back any potential issues that may arise using the assembly with Mono (most likely a .Net 2.0 feature that has not yet been implemented, or a calls to Win32 APIs that are not documented in the .Net API). Definitely a very helpful tool in debugging a .Net aseembly that refuses to compile in Mono.

Miguel de Icaza gives a more thorough step-by-step guide and review of his experiences using MoMA (though it doesn’t seem to be too complicated).

Error when sending Html Mail from ASP.net WebApp

On an ASP.net site (1.1), I was trying to send an email message using good old SmtpMail.Send(MailMessage message). When I did so, I got the following message “could not access CDO.message object“. After some Googling, I tried out all of the different security/smtp/relary/permissions related suggestions (most can be found on the systemwebmail.com site, a very handy reference if you have some questions regarding use of the System.Web.Mail library in ASP.net 1.1). Still not working. I checked the InnerException. It looked something like this:

InnerException: {“Unknown Error” }
Message: “Exception has been thrown by the target of an invocation.”
Source: “mscorlib”
” at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)\r\n
at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)\r\n
at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)\r\n
at System.Web.Mail.LateBoundAccessHelper.SetProp(Type type, Object obj, String propName, Object propValue)\r\n
at System.Web.Mail.LateBoundAccessHelper.SetProp(Object obj, String propName, Object propValue)”

But nothing apparently wrong there. The one weird thing that I could find is that if I set MailMessage.BodyFormat = MailFormat.Html, it would not work. If I set it to MailFormat.Text, it would work fine. Very suspicious.

In the end, the following solution worked for me. It was posted by Kyle Parker on the DotNetNuke forums:

  1. Close Visual Studio
  2. Open a Command Window
  3. regsvr32 cdosys.dll /u
  4. iisreset /restart
  5. regsvr32 cdosys.dll
  6. resume work in VS

After unregistering and reregistering this DLL, suddenly I was able to send Html mail again from my site. Kyle reported on his post that this only worked as a temporary solution. It is working for me so far.

Anyone know why this happened? Some other program messed up the dll that handles Html mail?

Programatic access to the ConnectionStrings section of your Web.Config file in ASP.net 2.0

Back with ASP.net 1.1, if you set a connection string in your Web.config file, you could set it with something like this:

  <add key="ConnectionStringName" value="ConnectionStringData" />

and get access to the string in your code with something like this:

string connString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionStringName"];

With ASP.net 2.0, while you can still use appsettings if you so desire, there are now subsections allowed in the Web.config, one of which is set aside for database connection strings. Here is how to use it:

  <add name="ConnectionStringName" connectionString="ConnectionStringDetails"/>

The good news with this is that the connection string within your Web.config file is no longer just some string (that while you may know it is a connection string, your application has no intrinsic knowledge of this). Your website can now access this string in a number of different ways, in general making your life easier (especially when using the Website Configuration screens, or any of the built-in data access controls).

All of this is old news. However, while the process for retrieving a connection string in 2.0 is well-documented when you are doing it from within the setup wizard of a DataAccess control, I had some trouble figuring out how to retrieve it solely within the code. Eventually (with some help from Google) I was able to find the exact syntax, and I am passing it on here so that it might help someone else facing the same problem.

string conn =  System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;

Visual Assist X

When I started getting into more of a development role in my previous job, and was using Visual Studio, C# and ASP.net more and more, I was a frequest visitor on sites devoted to .Net programming like Code Project and 4Guys. One day on CP, I saw a review of an extension for Visual Studio 2003 called Visual Assist X. The review descibed how this product helped improve the native intellisense in VS, and in general added shortcuts and other things to make the program friendlier to use. They offered a 30 day trial, so I downloaded and installed.

Within a couple of days, I was hooked. I got my boss to approve it, and sent $130 to Whole Tomato Software in exchange for a license to use their program.

I did not notice how much I relied on its features to help me speed up my overall development time until I had to switch to a different computer recently (one without Visual Assist X installed). As I started to code in Visual Studio, I was waiting for the extremely helpful (and actually intelligent) intellisense that I was used to to pop up with suggestions as to what variable I was looking for. The program is so well-integrated into VS that I had forgotten that it was separate. Suffice to say, I right away went to the site and downloaded a copy of the most recent build (and extended support with them in the process). Now that it is installed, Visual Studio seems much more familiar again (and I have made my coding at least 30% faster).
Note: I have no affiliation with Whole Tomato, nor do I receive any kickbacks or referral fees. I am just writing to let you know about a product that will almost certainly make Visual Studio friendlier, improve your overall productivity in the IDE (and pay back the investment within a few days).

Technorati Tags: , , , , , , , ,

Items of Interest: 2006.04.05

Things I found interesting on April 5, 2006:

  • Contract Changes – Keith Casey tells about some seemingly “draconian” additions he has made to his standard consulting contracts.
  • C# Tivia Quiz Part 1 – From Eric Gunnerson, a list of (some serious, some not serious) questions about C# (via the Daily Grind)
  • 01:02:03 04/05/06 – The way the clocks looked this morning, if you count days with mm/dd/yy. This was from the JOS Discussion group, but it looks like it was moderated out. (I got it from RSS)
  • How I work: Bill Gates – Read about the tools that Bill uses in the office every day. (Wow, three monitors helps productivity? Who woulda thunk it?)
  • Microsoft Says Recovery from Malware Becoming Impossible – “a Microsoft security official said businesses should consider investing in an automated process to wipe hard drives and reinstall operating systems as a practical way to recover from malware infestation.” Ouch.
  • TIOBE Programming Community Index – See what programming languages are most popular (who would have thought that BASIC is more popular than C#) in this search-engine-based unscientific study
  • Fire your Boss! The Successful Home Freelancer’s Guide – From Neil Flanagan and Jarvis Finger @ Sitepoint.

Technorati Tags: , , , , , , ,

Items of Interest: 2006.04.03

Technorati Tags: , , , , , , , , , , ,