With the MimeKitLite NuGet include I am no longer able to use MailKit library #542

Closed
opened 2025-12-29 08:29:47 +01:00 by adam · 16 comments
Owner

Originally created by @sprudel79 on GitHub (Aug 8, 2023).

Originally assigned to: @StefH on GitHub.

Describe the bug

I have just updated to latest WireMock.Net version 1.5.34 and my local project returned build errors in one of my classes where I have used MailKit (version 4.1.0) library that in itself contains "MimeKit" library.
Since WireMock.Net references "MimeKitLite" now, I got e.g. the following error:

error CS0433: The type 'MimeMessage' exists in both 'MimeKit, Version=4.1.0.0, Culture=neutral, PublicKeyToken=bede1c8a46c66814' and 'MimeKitLite, Version=4.1.0.0, Culture=neutral, PublicKeyToken=bede1c8a46c66814'

Test to reproduce

Create a sample project and add a reference

and

Now in a class try to use e.g.
var mimeMessage = new MimeMessage();

I am using .NET 6.0.20

I could perhaps work with an alias to reference MimeKit assembly directly in my code but I would like to ask for any feedback if this is now the expected behavior or not, thank you.

Originally created by @sprudel79 on GitHub (Aug 8, 2023). Originally assigned to: @StefH on GitHub. ### Describe the bug I have just updated to latest WireMock.Net version 1.5.34 and my local project returned build errors in one of my classes where I have used MailKit (version 4.1.0) library that in itself contains "MimeKit" library. Since WireMock.Net references "MimeKitLite" now, I got e.g. the following error: **error CS0433: The type 'MimeMessage' exists in both 'MimeKit, Version=4.1.0.0, Culture=neutral, PublicKeyToken=bede1c8a46c66814' and 'MimeKitLite, Version=4.1.0.0, Culture=neutral, PublicKeyToken=bede1c8a46c66814'** ### Test to reproduce Create a sample project and add a reference <PackageReference Include="MailKit" Version="4.1.0" /> and <PackageReference Include="WireMock.Net" Version="1.5.34" /> Now in a class try to use e.g. var mimeMessage = new MimeMessage(); ### Other related info I am using .NET 6.0.20 I could perhaps work with an alias to reference MimeKit assembly directly in my code but I would like to ask for any feedback if this is now the expected behavior or not, thank you.
adam added the bugdoc labels 2025-12-29 08:29:47 +01:00
adam closed this issue 2025-12-29 08:29:47 +01:00
Author
Owner

@StefH commented on GitHub (Aug 9, 2023):

@sprudel79
I understand your issue.

In the 1.5.33 version, I included the MimeKitLite as "private". However this had a side effect that the application could not work anymore.

So, please check if you use an alias.

Else I need to think on a different solution.

@StefH commented on GitHub (Aug 9, 2023): @sprudel79 I understand your issue. In the 1.5.33 version, I included the MimeKitLite as "private". However this had a side effect that the application could not work anymore. So, please check if you use an alias. Else I need to think on a different solution.
Author
Owner

@StefH commented on GitHub (Aug 10, 2023):

@sprudel79
Another option is to use WireMock.Net.Testcontainers which runs WireMock.NET inside a docker container, so it's completely separate from your unit test + source projects.

Would this be an option?

@StefH commented on GitHub (Aug 10, 2023): @sprudel79 Another option is to use [WireMock.Net.Testcontainers](https://github.com/WireMock-Net/WireMock.Net/wiki/Using-WireMock.Net.Testcontainers) which runs WireMock.NET inside a docker container, so it's completely separate from your unit test + source projects. Would this be an option?
Author
Owner

@sprudel79 commented on GitHub (Aug 10, 2023):

Thank you very much @StefH for proposing potential solutions. Indeed a docker based approach might help in this case, however it would also add more complexity to my CI/CD process. Right now I have reverted my code to use an older version of WireMock.Net and I don't have any pressure to adjust anything.
Btw. you mention version 1.5.33 which is also shown on the release page, however on nuget there's no 1.5.33 version but 1.5.34.

@sprudel79 commented on GitHub (Aug 10, 2023): Thank you very much @StefH for proposing potential solutions. Indeed a docker based approach might help in this case, however it would also add more complexity to my CI/CD process. Right now I have reverted my code to use an older version of WireMock.Net and I don't have any pressure to adjust anything. Btw. you mention version 1.5.33 which is also shown on the release page, however on nuget there's no 1.5.33 version but 1.5.34.
Author
Owner

@StefH commented on GitHub (Aug 10, 2023):

I unlisted that version because it introduced issues for users.

@StefH commented on GitHub (Aug 10, 2023): I unlisted that version because it introduced issues for users.
Author
Owner

@StefH commented on GitHub (Aug 15, 2023):

@sprudel79
Did you fix it using alias?

@StefH commented on GitHub (Aug 15, 2023): @sprudel79 Did you fix it using alias?
Author
Owner

@sprudel79 commented on GitHub (Aug 19, 2023):

Hi @StefH, I am on vacation right now and will be back on that project beginning of September...I'll let you know, thanks.

@sprudel79 commented on GitHub (Aug 19, 2023): Hi @StefH, I am on vacation right now and will be back on that project beginning of September...I'll let you know, thanks.
Author
Owner

@sprudel79 commented on GitHub (Sep 1, 2023):

Hi @StefH ,
here's the code that works:

In the csproj file I have these references:

 <PackageReference Include="MailKit" Version="4.1.0" />
 <PackageReference Include="MimeKit" Version="4.1.0">
   <Aliases>MimeKitAlias</Aliases>
 </PackageReference>
 <PackageReference Include="WireMock.Net" Version="1.5.35" />

I had to add a reference to MimeKit directly since I was not able to get things working with an alias for MailKit directly.

Next in my C# code I have these lines:

extern alias MimeKitAlias;

namespace MyNamespace
{
    public class MyClass
    {
        public void MyMethod()
        {
            var mail = new MimeKitAlias::MimeKit.MimeMessage();           
        }
    } 
}

At least I am able to build my code now without getting the error I had mentioned on top.
However, it's still cumbersome because e.g. in my VSCode environment I see

image

with the error:
The type or namespace name 'MimeKit' does not exist in the namespace 'MimeKitAlias', so it seems the Omnisharp C# plugin is not able to handle the alias properly and consequentially there's no intellisense anymore.
What do you think?

@sprudel79 commented on GitHub (Sep 1, 2023): Hi @StefH , here's the code that works: In the csproj file I have these references: ``` xml <PackageReference Include="MailKit" Version="4.1.0" /> <PackageReference Include="MimeKit" Version="4.1.0"> <Aliases>MimeKitAlias</Aliases> </PackageReference> <PackageReference Include="WireMock.Net" Version="1.5.35" /> ``` I had to add a reference to MimeKit directly since I was not able to get things working with an alias for MailKit directly. Next in my C# code I have these lines: ``` csharp extern alias MimeKitAlias; namespace MyNamespace { public class MyClass { public void MyMethod() { var mail = new MimeKitAlias::MimeKit.MimeMessage(); } } } ``` At least I am able to build my code now without getting the error I had mentioned on top. However, it's still cumbersome because e.g. in my VSCode environment I see ![image](https://github.com/WireMock-Net/WireMock.Net/assets/10754010/3d48f9ec-3199-450f-b104-3c9ad98c6da5) with the error: The type or namespace name 'MimeKit' does not exist in the namespace 'MimeKitAlias', so it seems the Omnisharp C# plugin is not able to handle the alias properly and consequentially there's no intellisense anymore. What do you think?
Author
Owner

@StefH commented on GitHub (Sep 3, 2023):

@sprudel79
Thanks for the research.

I was wondering, will this fix also work the other way around, so if I define that Alias in the code from WireMock?

@StefH commented on GitHub (Sep 3, 2023): @sprudel79 Thanks for the research. I was wondering, will this fix also work the other way around, so if I define that Alias in the code from WireMock?
Author
Owner

@sprudel79 commented on GitHub (Sep 4, 2023):

Thanks to you for taking this up.
I am not sure if this helps, is there any API in WireMock.Net that exposes any type of MimeKit (which I doubt)?
We can definitely give this a try if you like, I can test this approach from my side.

@sprudel79 commented on GitHub (Sep 4, 2023): Thanks to you for taking this up. I am not sure if this helps, is there any API in WireMock.Net that exposes any type of MimeKit (which I doubt)? We can definitely give this a try if you like, I can test this approach from my side.
Author
Owner

@StefH commented on GitHub (Sep 4, 2023):

is there any API in WireMock.Net that exposes any type of MimeKit (which I doubt)?

No, as far as I can see, I don't expose MimeKit in an api.

@StefH commented on GitHub (Sep 4, 2023): > is there any API in WireMock.Net that exposes any type of MimeKit (which I doubt)? No, as far as I can see, I don't expose MimeKit in an api.
Author
Owner

@StefH commented on GitHub (Sep 4, 2023):

https://github.com/WireMock-Net/WireMock.Net/pull/999

@StefH commented on GitHub (Sep 4, 2023): https://github.com/WireMock-Net/WireMock.Net/pull/999
Author
Owner

@StefH commented on GitHub (Sep 4, 2023):

@sprudel79
Can you try preview 1.5.35-ci-17784 ?

https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

@StefH commented on GitHub (Sep 4, 2023): @sprudel79 Can you try preview 1.5.35-ci-17784 ? https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Author
Owner

@sprudel79 commented on GitHub (Sep 5, 2023):

Thank you very much @StefH, I have updated my environment to use the preview version of WireMock.Net. Furthermore I have removed my local alias handling.
Unfortunately I get again the error from my first post about "The type 'MimeMessage' exists in both...".

@sprudel79 commented on GitHub (Sep 5, 2023): Thank you very much @StefH, I have updated my environment to use the preview version of WireMock.Net. Furthermore I have removed my local alias handling. Unfortunately I get again the error from my first post about "The type 'MimeMessage' exists in both...".
Author
Owner

@StefH commented on GitHub (Sep 6, 2023):

@sprudel79
In that case there is no solution (yet) in WireMock, so I'll create a wiki page from this issue and close it.

@StefH commented on GitHub (Sep 6, 2023): @sprudel79 In that case there is no solution (yet) in WireMock, so I'll create a wiki page from this issue and close it.
Author
Owner
@StefH commented on GitHub (Sep 6, 2023): https://github.com/WireMock-Net/WireMock.Net/wiki/MimeKit-and-MimeKitLite
Author
Owner

@StefH commented on GitHub (May 24, 2025):

https://github.com/wiremock/WireMock.Net/pull/1300

@StefH commented on GitHub (May 24, 2025): https://github.com/wiremock/WireMock.Net/pull/1300
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#542