Skip to content

Commit

Permalink
Updated FAQ.md to add a Q/A for TypeLoadException issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Sep 6, 2024
1 parent ee34ac4 commit f2eeaa0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
```

### <a name="type-load-exception">Q: Why do I get a `TypeLoadException` when I try to create a new MimeMessage?</a>

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
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
```

## Messages

### <a name="create-attachments">Q: How do I create a message with attachments?</a>
Expand Down

0 comments on commit f2eeaa0

Please sign in to comment.