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

Microsoft.Extensions.DependencyInjection 2.0.0 breaks MQTTnet #93

Closed
ghost opened this issue Nov 9, 2017 · 22 comments
Closed

Microsoft.Extensions.DependencyInjection 2.0.0 breaks MQTTnet #93

ghost opened this issue Nov 9, 2017 · 22 comments
Labels
bug Something isn't working
Milestone

Comments

@ghost
Copy link

ghost commented Nov 9, 2017

Package dependencies specify Microsoft.Extensions.DependencyInjection v1.1.1 or greater. But updating to Microsoft.Extensions.DependencyInjection 2.0.0 breaks MQTTnet. This statement

        var mqttServer = new MqttFactory().CreateMqttServer();

reproduces it.

@chkr1011
Copy link
Collaborator

chkr1011 commented Nov 9, 2017

Hi,
thank you for sharing this issue. If you use the DI library in version 2.0.0 in your project please use the following code for constructing a MQTT server:

var services = new ServiceCollection()
	.AddMqttServer(options =>
	{
	// modify options here
	})
	.AddLogging()
	.BuildServiceProvider();

var mqttServer = services.GetRequiredService<IMqttServer>();

@JanEggers Do we havy any chance to fix this? I found several other tickets for other projects which have the same problem because 2.0.0 of DI has a breaking change (The service provider is no longer returned as an interface).

Best regards
Christian

@JanEggers
Copy link
Contributor

i will update myself then i will get that same error

@chkr1011
Copy link
Collaborator

chkr1011 commented Nov 9, 2017

Here is an interesting post from people having the same problem: OData/WebApi#1082

@JanEggers
Copy link
Contributor

Do we havy any chance to fix this?

shure we can add netstadard2.0 build with updated dependencies. pr incoming

@chkr1011
Copy link
Collaborator

chkr1011 commented Nov 9, 2017

Well for me this not a solution because (as also discussed at the other projects which are affected) this will require all library users to use .net standard 2.0 including ASP.NET Core 2.0 and .NET 4.6+. But my goal is to still support .NET 4.5.2 and to not rely on .net core (standard) 2.0 because it is just released and I will not limit the library to only be usable by cutting edge technologies only.

I am trying to use reflection for service lookup and using object as the type for the service provider field. I will let you know if this works.

@JanEggers
Copy link
Contributor

no sry i didnt put it correctly we can add another targetplatform with updated dependencies but still maintain netstandard 1.3

@JanEggers
Copy link
Contributor

JanEggers commented Nov 9, 2017

im currently working on
<TargetFrameworks>netstandard1.3;netstandard2.0;net452;uap10.0</TargetFrameworks>

@chkr1011
Copy link
Collaborator

chkr1011 commented Nov 9, 2017

Ah OK sorry I don't get that. This is surely OK for me 😄

@JanEggers JanEggers mentioned this issue Nov 9, 2017
@JanEggers
Copy link
Contributor

i also added a new event for server started so there are no messages published in aspnetcore sample until the server is started

@danehnert
Copy link

I'm currently using MQTTnet in a .NET Framework 4.5.2. When I now try to update the package from 2.4 to 2.5, it is showing me dependencies like Microsoft.Extensions.DependencyInjection. Aren't these dependencies specific for .NET Core?

@JanEggers
Copy link
Contributor

@danehnert we use Microsoft.Extensions.DependencyInjection as ServiceProvider for netstandard and netfx

@danehnert
Copy link

So the library went from zero dependencies to this :-(

image

@JanEggers
Copy link
Contributor

im not shure why visual studio picks dotnetstandard as targetframework instead of net452 which should result in less dependencies:

see #80

@chkr1011 we have 2 little issues with the nuspec, can you please verify
this should be 1.3:
https://github.com/chkr1011/MQTTnet/blob/eaf27c1e1268a9417d96fd4d8925969aaaf19fcb/Build/MQTTnet.nuspec#L35

and this should be 452 not 451
https://github.com/chkr1011/MQTTnet/blob/eaf27c1e1268a9417d96fd4d8925969aaaf19fcb/Build/MQTTnet.nuspec#L52

@chkr1011
Copy link
Collaborator

@danehnert These libraries are separate libraries if you use netstandard (v 1.6.1) in your screenshot. The "regular" .net Framework is a fat library with all libraries included. The new approach (decided by MS) is to split up things in separate libraries which can be maintained and released independently (most cases). So we have to accept this. Only the "Extensions" libraries are not part of the .net framework.

@chkr1011
Copy link
Collaborator

@JanEggers Yes you are right. Then let us release a new version soon including the .net standard 2.0 fix.

@JanEggers
Copy link
Contributor

agreed

@chkr1011
Copy link
Collaborator

@JanEggers Yes they are OK.

@JanEggers
Copy link
Contributor

JanEggers commented Nov 12, 2017

il close this issue as 2.5.1 is released which also targets netstandard2.0 with updated dependencies. @danehnert im also investigating why there are more dlls added than needed that is tracked in #100
@ClaudioTF if you still have the issue with 2.5.1 feel free to reopen this issue

@KarloX2
Copy link

KarloX2 commented Nov 12, 2017

Still I'm having this issue. I'm targeting .NET 4.6.1, using MQTTnet 2.5.1 and upgraded to Microsoft.Extensions.DependencyInjection 2.0.0 gives me an

System.MissingMethodException

on doing

var myclient = new MqttFactory().CreateMqttClient();

I'm really wondering why so many people are keen on DI. It never did anything useful for me. Only made things complicated, error prone and hard to understand (just my 2c).

BTW: same problem after changing code to

var svcprov = new ServiceCollection()
.AddMqttClient()
.BuildServiceProvider();
var myclient = svcprov.GetRequiredService<IMqttClient>();

@chkr1011 chkr1011 reopened this Nov 12, 2017
@schtibb
Copy link

schtibb commented Nov 16, 2017

I'm having the same issue, I have reverted to version 2.4 in the meantime.

@chkr1011 chkr1011 added the bug Something isn't working label Nov 16, 2017
@chkr1011 chkr1011 added this to the 2.5.2 milestone Nov 16, 2017
@chkr1011
Copy link
Collaborator

This issue is fixed in the preview version 2.5.2-rc1 (available as nuget). Please let me know if the issue is now fixed.

@KarloX2
Copy link

KarloX2 commented Nov 18, 2017

For me this works with 2.5.2-rc1. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants