From f2eeaa01df6a7066a2f84161170fe38d1977a5c4 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Fri, 6 Sep 2024 10:34:46 -0400 Subject: [PATCH] Updated FAQ.md to add a Q/A for TypeLoadException issues --- FAQ.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/FAQ.md b/FAQ.md index ed952e2126..91102c9874 100644 --- a/FAQ.md +++ b/FAQ.md @@ -6,6 +6,7 @@ * [Are MimeKit and MailKit completely free? Can I use them in my proprietary product(s)?](#completely-free) * [Why do I get `NotSupportedException: No data is available for encoding ######. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.`?](#register-provider) +* [Why do I get a `TypeLoadException` when I try to create a new MimeMessage?](#type-load-exception) ### Messages @@ -47,6 +48,34 @@ the following line of code to your program initialization (e.g. the beginning of System.Text.Encoding.RegisterProvider (System.Text.CodePagesEncodingProvider.Instance); ``` +### Q: Why do I get a `TypeLoadException` when I try to create a new MimeMessage? + +This only seems to happen in cases where the application is built for .NET Framework (v4.x) and seems to be most +common for ASP.NET web applications that were built using Visual Studio 2019 (it is unclear whether this happens +with Visual Studio 2022 as well). + +The issue is that some (older?) versions of MSBuild do not correctly generate `\*.dll.config`, `app.config` +and/or `web.config` files with proper assembly version binding redirects. + +If this problem is happening to you, make sure to use MimeKit and MailKit >= v4.0 which include `MimeKit.dll.config` +and `MailKit.dll.config`. + +The next step is to manually edit your application's `app.config` (or `web.config`) to add a binding redirect +for `System.Runtime.CompilerServices.Unsafe`: + +```xml + + + + + + + + + + +``` + ## Messages ### Q: How do I create a message with attachments?