Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sprudel79 opened this issue Aug 8, 2023 · 15 comments
Assignees
Labels
doc Documentation / WIKI

Comments

@sprudel79
Copy link

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.

@sprudel79 sprudel79 added the bug label Aug 8, 2023
@StefH StefH self-assigned this Aug 9, 2023
@StefH
Copy link
Collaborator

StefH commented 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
Copy link
Collaborator

StefH commented 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
Copy link
Author

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
Copy link
Collaborator

StefH commented Aug 10, 2023

I unlisted that version because it introduced issues for users.

@StefH
Copy link
Collaborator

StefH commented Aug 15, 2023

@sprudel79
Did you fix it using alias?

@sprudel79
Copy link
Author

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
Copy link
Author

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?

@StefH
Copy link
Collaborator

StefH commented 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
Copy link
Author

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
Copy link
Collaborator

StefH commented 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
Copy link
Collaborator

StefH commented Sep 4, 2023

#999

@StefH
Copy link
Collaborator

StefH commented Sep 4, 2023

@sprudel79
Copy link
Author

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
Copy link
Collaborator

StefH commented 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 StefH added doc Documentation / WIKI and removed bug labels Sep 6, 2023
@StefH
Copy link
Collaborator

StefH commented Sep 6, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Documentation / WIKI
Projects
None yet
Development

No branches or pull requests

2 participants