mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
With the MimeKitLite NuGet include I am no longer able to use MailKit library #542
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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();
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.
@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 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?
@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.
@StefH commented on GitHub (Aug 10, 2023):
I unlisted that version because it introduced issues for users.
@StefH commented on GitHub (Aug 15, 2023):
@sprudel79
Did you fix it using alias?
@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 (Sep 1, 2023):
Hi @StefH ,
here's the code that works:
In the csproj file I have these references:
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:
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
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?
@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?
@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.
@StefH commented on GitHub (Sep 4, 2023):
No, as far as I can see, I don't expose MimeKit in an api.
@StefH commented on GitHub (Sep 4, 2023):
https://github.com/WireMock-Net/WireMock.Net/pull/999
@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
@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...".
@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):
https://github.com/WireMock-Net/WireMock.Net/wiki/MimeKit-and-MimeKitLite
@StefH commented on GitHub (May 24, 2025):
https://github.com/wiremock/WireMock.Net/pull/1300