Archived Forum Post

Index of archived forum posts

Question:

The type initializer for '<Module>' threw an exception.

Mar 30 '13 at 16:53

Hi,

I am using the Chilkat.MailMan and every month or so the component start throwing errors on sending emails: The type initializer for '<Module>' threw an exception. Restarting the app IIS pool application seem to fix the issue(running app on windows 2008 R2), but I keep having to do this every month or so, is it a known issue? and how can I fix it permanently?

Thanks,

Alex


Answer

Tough to say without seeing an actual error message or some code.

Usually when things suddenly stop working after an extended period of time it's due to something like running out of memory/resources (are you disposing of all objects properly? in the TaskManager does it appear that your software is using a lot of resources when it dies?), or perhaps an overflow problem (for example, 32-Bit GetTickCount calls roll-over after 49.8 days, and this has been known to cause problems in long running code that hasn't been designed to account for it).

Any additional concrete information you can supply can only help though, such as:

Also make sure that you are using the latest builds of the DLLs (should be Dec 12, 2012)


Answer

Thank you for your response,

it is hard to distinguish which iis worker process the app is, as I have quite a few sites on the server and they all have the name of w3wp.exe*32.

I don't know how to handle the GetTickCount you mentioned.

I am using Chilkat 9.3.2.0

I think you might be right on the resource concern, the snippet below is from the function that calls the chilkat component:

Chilkat.MailMan mailman = new Chilkat.MailMan();

            bool success;
            success = mailman.UnlockComponent("xxxxx");
            if (success != true)
            {
                LogToDB("Chilkat Component unlock failed", "");
                return false;
            }

            //  Use the GMail SMTP server
            mailman.SmtpHost = "xxxx";
            mailman.SmtpPort = 25;

            //  Set the SMTP login/password.
            mailman.SmtpUsername = "something@xyz.com";
            mailman.SmtpPassword = "Password";
            mailman.StartTLS = true;

            string cid;
            //  Create a new email object
            Chilkat.Email email = new Chilkat.Email();

            email.SetHtmlBody(Message);

            email.Subject = Subject;

            email.From = "something@xyz.comm";

            success = mailman.SendEmail(email);

            if (success != true)
            {
                GlobalTracker.LogToDB("Chilkat Send Error", mailman.LastErrorText);
                sent = false;
            }
            else
            {
                sent = true;
            }

I will add the email.Dispose(); mailman.Dispose(); and see if that resolves the problem.


Answer

For questions such as this, the best thing to do is to Google the error message. For example, Googling "type initializer for '<module>' threw an exception" provides many good results.

I suspect this isn't an issue caused by the Chilkat .NET assembly. Please do some research by Googling the error message to understand the meaning of the error message in more detail...