1
I Use This!
Very Low Activity

News

Analyzed 1 day ago. based on code collected 2 days ago.
Posted almost 9 years ago by bzuillsmith
It's hard to know if this is a Visual Studio bug or a CommonServiceLocator bug but I decided to post here first.I'm having an issue where if I call ```ServiceLocator.Current.GetInstance(type)``` anywhere in my project, it causes UserControls ... [More] throughout my project to stop instantiating within other controls at design-time in Visual Studio (tried 2013 and 2015). These controls work fine at run-time however. The line of code doesn't even have to be connected to any other code in anyway. If it's anywhere in the project, it causes problems. It does not happen with other function calls such as ```ServiceLocator.Current.GetInstance<AnyType>()```It is reproducible by creating a simple WpfApplication with the following 3 classes. The first build will succeed, and the designer will show fine. If you rebuild, however, it throws the error and the designer stops instantiating the UserControls within other controls. Because of this behavior, it seems like a Visual Studio bug, but I'm not sure.When uncommented, the ```#GetInstance(Type type)``` function of ServiceLocator causes an Error in the error list ```Cannot locate resource 'controls/test.xaml``` and the designer shows an error ```Cannot create an instance of "Test"``` where the Test UserControl should be. When commented, there are no errors.Test xaml class.```<UserControl x:Class="XamlTest.Controls.Test" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d"> <Grid> <Label Content="Test"/> </Grid></UserControl>```MyView xaml class. (uses Test)```<UserControl x:Class="XamlTest.Views.MyView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mycontrols="clr-namespace:XamlTest.Controls" mc:Ignorable="d"> <Grid> <mycontrols:Test/> </Grid></UserControl>```A class unrelated to the UserControls that uses ServiceLocator.Current.GetInstance(type);.using Microsoft.Practices.ServiceLocation;```namespace XamlTest.SomeClasses{ class SomeClass { public void SomeFunction() { // Causes Test xaml class to not instantiate at design time within MyView. // Does not matter what parameters you give the function. // Notice this class isn't even associated with any other class, // and is never called, but it still causes problems. ServiceLocator.Current.GetInstance(null); } }}```You can also find a ready-made example project of this issue on github at [https://github.com/bzuillsmith/xamltest/tree/master/XamlTest](https://github.com/bzuillsmith/xamltest/tree/master/XamlTest) [Less]
Posted almost 9 years ago by Togakangaroo
They are no longer in google code but in github. Since the Autofac integration link takes people directly to the downloads page they will not even see the message about this move.
Posted almost 9 years ago by Togakangaroo
This is no longer accurate. The correct adapter is https://www.nuget.org/packages/Autofac.Extras.CommonServiceLocator/
Posted about 9 years ago by jalalx
While testing the ServiceLocator.Current.GetInstance method, I passed a null to verify the libraries design correctness (we use Microsoft Basic Design Guidelines Rules, and try to test our external libraries for them). I ran into this exception when ... [More] calling: ServiceLocator.Current.GetInstance(null); Stack Trace:  at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.FormatActivationExceptionMessage(Exception actualException, Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 149 at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 53 at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 34 at DiscoveryPrototype.ClientApp.Program.Main(String[] args) in D:\Projects\DiscoveryPrototype\DiscoveryPrototype.ClientApp\Program.cs:line 19 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state)  The ServiceLocatorImplBase should really have null checks in all methods for all used parameters. Although it is an edge case, you could ask for an instance of an object passing in the type that came from the return of a method that DOES return null, and then the exception is not caught at the proper place.Comments: And now I'm going insane for that problem! [Less]
Posted about 9 years ago by sukumarvg
Hi 1)IStudyService studyService3 = ServiceLocator.Current.GetInstance<IStudyService>(); What would be the StructureMap.IContext.RequestedName in the above call , when we go with empty key? Will it be null or wmpty? Key Note: ... [More] IStudyService studyService2 = ServiceLocator.Current.GetInstance<IStudyService>"localhost"); In the above condition StructureMap.IContext.RequestedName will be "localhost" which was given as key. But in the first condition what would be the RequestedName? The question is raised due to this below situation If(context => { return (String.IsNullOrEmpty(context.RequestedName) || context.RequestedName.Equals("localhost", StringComparison.OrdinalIgnoreCase) || }). when we are checking the context.RequestedName with null or empty the above check fails as i mentioned earlier. Thanks in advance Regards Sukumar [Less]
Posted about 9 years ago by Korijn
This warning keeps showing up in a .NET 4.5.1 MVC application I'm working on that uses the Unity application block for dependency injection, which references your project.```Warning 10 Found conflicts between different versions of the same dependent ... [More] assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.```After setting build log verbosity to detailed:```There was a conflict between "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes".4> "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was chosen because it was primary and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes" was not.References which depend on "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes" [].4> C:\Development\Projects\.....\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll4> Project file item includes which caused reference "C:\Development\Projects\.....\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll".......(removed some application specific lines for brevity)4> Unity.WebApi4> Microsoft.Practices.Unity.Mvc4> Microsoft.Practices.Unity.Configuration, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL4> Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL4> Microsoft.Practices.Unity.RegistrationByConvention4> Microsoft.Practices.Unity.WebApi4> Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL```Are you planning on releasing a version that targets the newer mscorlib? Is this related to issue [12616](https://commonservicelocator.codeplex.com/workitem/12616)? [Less]
Posted about 9 years ago by sukumarvg
Hi We have an extension method to register the service as shown below expression.MissingNamedInstanceIs.Conditional(configuration => { configuration. If(context => { return ... [More] (String.IsNullOrEmpty(context.RequestedName) || context.RequestedName.Equals("localhost", StringComparison.OrdinalIgnoreCase) || context.RequestedName.Equals(ServerInfo.HostName, StringComparison.OrdinalIgnoreCase)); }). ThenIt.Is.Type<TService>(); configuration.TheDefault.Is.ConstructedBy(buildContext => { return buildContext.GetInstance<IServiceBuilder>().GetOutOfProcService<TContract>(buildContext); }); }); we are saying return me the out of proc instance only if the key is remote host name. in detail we expected to receive in proc instance for all three calls mentioned below IStudyService studyService = ServiceLocator.Current.GetInstance<IStudyService>(Stentor.Server.ServerInfo.HostName) IStudyService studyService2 = ServiceLocator.Current.GetInstance<IStudyService>("localhost"); IStudyService studyService3 = ServiceLocator.Current.GetInstance<IStudyService>() The first two calls are working as expected but when we go with empty key for third call highlighted one we are getting out of proc instead the in proc If(context => { return (String.IsNullOrEmpty(context.RequestedName) || context.RequestedName.Equals("localhost", StringComparison.OrdinalIgnoreCase) || context.RequestedName.Equals(ServerInfo.HostName, StringComparison.OrdinalIgnoreCase)); }). ThenIt.Is.Type<TService>(); we have condition mentioned like if the requested key empty or localhost or hostanme return ThenIt.Is.Type<TService>(); but for empty key condition it's not working. (String.IsNullOrEmpty(context.RequestedName) this condition is not wokring and the below code is getting executed configuration.TheDefault.Is.ConstructedBy(buildContext => { return buildContext.GetInstance<IServiceBuilder>().GetOutOfProcService<TContract>(buildContext); }); Can you please suggest what's wrong in this code or how the context has to be registered when the empty key needs to be processed Thanks & regards Sukumar [Less]
Posted over 9 years ago by WestDiscGolf
Can the PCL version of the CommonServiceLocator be added to the official Nuget package please? I need to reference it for cross platform development using Xamarin.Cheers
Posted over 9 years ago by Delirium
```C:\Users\delirium\Documents\Visual Studio 2013\Projects\test_prism_unity\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8>sn -t Microsoft.Practices.ServiceLocation.dllMicrosoft (R) .NET Framework-Dienstprogramm für ... [More] starke Namen, Version 4.0.30319.33440Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.Der Schlüssel konnte nicht zu Token konvertiert werden -- Ungültiger öffentlicher Schlüssel für Assembly.```This may cause assembly redirection to fail - which is a PITA if one uses unity and prism and clicks "update all packages" in nuget package management (which would update CSL to 1.3.0.0, but unity is bound to 1.2.0.0). [Less]
Posted over 9 years ago by VcDeveloper
Cancel that! After much searching and testing I finally got it after reading this posts on the Unity Adapter page. .. private readonly IUnityContainer _container = new UnityContainer(); ... .. . var locator = new UnityServiceLocator(_container); ServiceLocator.SetLocatorProvider(() => locator);