Hi,@Iris Smilovic .Welcome Microsoft Q&A.
The issue you are facing with MimeKit and MailKit in your Release version is likely related to the build configuration and how the required assemblies are being included in the output.
To ensure that the required assemblies (MimeKit.dll and MailKit.dll) are included in the Release build and avoid having to manually copy them to every PC, you could try to do the following steps:
NuGet Package References: First, ensure that both MimeKit and MailKit are installed as NuGet packages in your project. NuGet will automatically handle the dependencies and copy the required DLLs to the output folder.
Check Project References: Verify that the project references for MimeKit and MailKit are set to "Copy Local = True." This ensures that the required DLLs will be copied to the output folder during the build.
To do this, right-click on your project in Visual Studio, choose "References," find MimeKit and MailKit references in the list, and check their properties in the "Properties" window. Make sure that "Copy Local" is set to "True."
Check Build Configuration: Confirm that you are building the correct configuration for Release (e.g., Release or Any CPU). Sometimes, if you are testing in Debug mode and then switch to Release mode, you might forget to update the build configuration.
To change the build configuration, go to the top toolbar in Visual Studio, click on the dropdown next to the "Start" button, and select "Release" instead of "Debug."
Clean and Rebuild: It's a good practice to clean the solution and then rebuild it. This ensures that any old files in the output folder are removed, and the latest versions of the assemblies are copied to the correct location.
To clean the solution, right-click on the solution in the Solution Explorer and select "Clean Solution." Then, rebuild the solution by right-clicking on the project and selecting "Rebuild."
If you have followed the steps above and still encounter issues, try creating a new clean project, installing the required NuGet packages (MimeKit and MailKit), and testing whether the Release build works correctly.
As for why the Release build blocks at the line var email = new MimeMessage();
:
The FileNotFoundException occurs when the required assembly (MimeKit.dll) cannot be found at runtime. This could happen if the assembly is not properly included in the build output or is missing from the specified location.
In your Release build, it's likely that the MimeKit.dll is not being copied to the output folder, causing the runtime to fail when trying to create a new instance of MimeMessage.
You could also refer to the documentation here. Alternatively, if it's a quick sample application you don't intend to distribute, you can copy the entire bin/debug or bin/release folder to another machine and run the application.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.