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

Autofac.Extras.CommonServiceLocator doesn't work with Autofac 4.3.0+ #859

Closed
justinyoo opened this issue Jul 3, 2017 · 5 comments
Closed
Labels

Comments

@justinyoo
Copy link

justinyoo commented Jul 3, 2017

Hi, Team.

Wonder if this is a known issue or not. I'm using Autofac.Extras.CommonServiceLocator 4.0.0 at my project. If I upgrade the Autofac version higher than 4.2.1, it throws an exception (xxxx masking intended):

Exception while executing function: xxxx. mscorlib: Exception has been thrown by the target of an invocation. xxxx: The type initializer for 'xxxx' threw an exception. xxxx: Method not found: 'Void Autofac.Extras.CommonServiceLocator.AutofacServiceLocator..ctor(Autofac.IComponentContext)'.

I tried 4.3.0, 4.4.0, 4.5.0 and 4.6.0 but all threw the same exception. Therefore I have to stay on 4.2.1 until this is fixed. Could you please let me know a workaround? I suspect that Autofac.Extras.CommonServiceLocator hasn't been updated for about a year, which resulted in failing to support .NET Standard.

Cheers,

@tillig
Copy link
Member

tillig commented Jul 3, 2017

The CommonServiceLocator package, last published in 2014, itself doesn't support .NET Standard/.NET Core. There's an unofficial fork that appears to be compatible, but that's not the official one and isn't something we support.

The PCL profile targeted by CommonServiceLocator looks like: portable-net40+sl5+win8+wp8+wpa81.

Looking at the netstandard docs under the PCL compatibility section I don't see any with the sl5 (Silverlight 5) support or net40 support. .NET 4.5 is the lowest it goes along with wp8 (Windows Phone 8).

I was able to create a .NET 4.5.2 app and a .NET 4.6.2 app using

  • CommonServiceLocator 1.3.0
  • Autofac 4.6.0
  • Autofac.Extras.CommonServiceLocator 4.0.0

and it works.

I tried getting a console app targeting netcoreapp1.1 to work but you get into some odd hacky package target fallback stuff and VS starts telling me to add a reference to mscorlib 2.0.5.0 which is a weird retargetable placeholder thing used in Portable Class Libraries.

Short version is: CommonServiceLocator itself doesn't really support the scenario so there's not much we can do about that.

Do you have some repro where you are targeting .NET Core / .NET Standard where you didn't have to manually hack package references in and it was working? I can't find the magic combination that will fool NuGet into allowing me to even add CommonServiceLocator to a netstandard/netcoreapp project.

@tillig tillig added the question label Jul 3, 2017
@justinyoo
Copy link
Author

@tillig Thanks for your kind explanation! So, basically it's because the CommonServiceLocator library doesn't support .NET Standard and the library is apparently not being maintained any longer.

I have a toy project (Azure Functions) that relies on Autofac.Extras.CommonServiceLocator. Many of dependencies that my project is using are based on .NET Standard. If you don't mind, you can have a look at the repo and find out some workaround.

https://github.com/aliencube/yarm

@tillig
Copy link
Member

tillig commented Jul 4, 2017

Unfortunately I don't really have time to offer deep individualized help like that. Without even looking, though, I can tell you the replacement will be one of these:

  • Use Autofac directly rather than the CSL wrapper.
  • Replace CSL with Microsoft.Extensions.DependencyInjection and Autofac.Extensions.DependencyInjection.
  • Roll your own CSL and adapt Autofac to that.
  • Use the unofficial fork of CSL that supports .NET Core and adapt Autofac to that.
  • Stop using service location to avoid the issue altogether.

You'll have to choose the best option for you.

You might also see if you can submit a PR to CSL but if they're not maintaining it anymore that may be hard.

@tillig tillig closed this as completed Jul 4, 2017
@justinyoo
Copy link
Author

justinyoo commented Jul 4, 2017

@tillig Sorry for asking the individualised help. I might have misinterpreted your last paragraph:

Do you have some repro where you are targeting .NET Core / .NET Standard where you didn't have to manually hack package references in and it was working?

However, your suggestion is invaluable! I'll have a look one of those options that can be applied to my situation.

@tillig
Copy link
Member

tillig commented Jul 5, 2017

Oh, yeah, sorry for confusion. On mobile over the long holiday weekend here in the US. When I was asking for a repro I meant "a small, very simple reproduction showing a project where NuGet allowed you to somehow add the packages in the unsupported configuration" rather than "link to a repo full of projects to navigate through." Apologies for the confusion, but glad I could help. Good luck!

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

No branches or pull requests

2 participants