Quantcast
Channel: CommonServiceLocator
Viewing all 118 articles
Browse latest View live

New Post: Is the strong naming key for Microsoft.Practices.ServiceLocation dll available?

$
0
0
I have a .NET 4 application that uses Prism 4.0 and MEF.

We have a weird application crash (intermittent) where there is a NullReferenceException inside Prism code while accessing ServiceLocator.Current.

I wanted to do some changes in that code to introduce Interlocked.Exchange to see if it helps. However, the source code does not include the strong named key which means that I have to create a new key and rebuild everything that refers to Microsoft.Practices.ServiceLocation. (e.g. Prism dlls, my application dlls etc)

Hence the question, can the strong named key for Microsoft.Practices.ServiceLocation be shared here?

Also the exception call stack is:

A first chance exception has occured: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Practices.ServiceLocation.ServiceLocator.get_Current()

Which lead to:
System.ComponentModel.Composition.Primitives.ComposablePartException: An exception occurred while trying to create an instance of type 'GE.Energy.Framework.UI.Shell.Shell'. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Practices.Prism.Regions.RegionManager.CreateRegion(DependencyObject element)
at Microsoft.Practices.Prism.Regions.RegionManager.OnSetRegionNameCallback(DependencyObject element, DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.Baml2006.WpfMemberInvoker.SetValue(Object instance, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(XamlMember member, Object obj, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
at MS.Internal.Xaml.Runtime.PartialTrustTolerantRuntime.SetValue(Object obj, XamlMember property, Object value)
at System.Xaml.XamlObjectWriter.SetValue(Object inst, XamlMember property, Object value)
at System.Xaml.XamlObjectWriter.Logic_ApplyPropertyValue(ObjectWriterContext ctx, XamlMember prop, Object value, Boolean onParent)
at System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.Logic_AssignProvidedValue(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.WriteEndMember()
at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at GE.Energy.Framework.UI.Shell.Shell.InitializeComponent()
at GE.Energy.Framework.UI.Shell.Shell..ctor()
at GE.Energy.Framework.UI.Shell.Shell..ctor(IRegionManager regionManager, IEventAggregator eventAggregator)
--- End of inner exception stack trace ---
at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.CreateInstance(ConstructorInfo constructor, Object[] arguments)



This should not happen because:
Configuring ServiceLocator singleton had happened just before that which means that the ServiceLocator is set.

Created Issue: Spelling Errors in Microsoft.Practices.ServiceLocation.Resources.resx [16054]

$
0
0
__ActivationExceptionMessage__

Activation error __occured__ while trying to get instance of type {0}, key "{1}"

__occured__ should be __occurred__

__ActivateAllExceptionMessage__

Activation error __occured__ while trying to get all instances of type {0}

__occured__ should be __occurred__

New Post: Question about use of MefServiceLocator

$
0
0
Why doesn't the compositionContainer get resolved in Class Foo shown below?
    class Program
    {
        static void Main(string[] args)
        {
            Test mytest = new Test();
        }
    }

    public class Test
    {
        public Test()
        {
            ComposeMefContainer();

            Foo foo = new Foo();
        }

        private void ComposeMefContainer()
        {
            CompositionContainer _container;
            var catalog = new AggregateCatalog(new DirectoryCatalog("."),
                          new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            _container = new CompositionContainer(catalog);
            _container.ComposeParts(this);

            var mef = new MefServiceLocator(_container);
            ServiceLocator.SetLocatorProvider(() => mef);
        }
    }

    public class Foo
    {
        [Import]
        Bar abar;

        public Foo()
        {
            //I know I can do the following
            var bar = ServiceLocator.Current.GetInstance<Bar>();

            //Why doesn't this work?
            var compositionContainer = ServiceLocator.Current.GetInstance<CompositionContainer>();
            compositionContainer.SatisfyImportsOnce(this);
        }
    }

    [Export]
    public class Bar
    {
        public string Name {get; set;}

        public Bar()
        {
            Name = "Tom";
        }
    }

}

Released: Common Service Locator 1.0 (Sep 30, 2008)

$
0
0
This is a signed binary of the Microsoft.Practices.ServiceLocation DLL and associated PDB and XML Doc comment files. This provides a common assembly to implement IServiceProvider.

New update: Signed assemblies for Silverlight 2.0. The interface definition is the same.

Newer update: Signed Portable Class Library version of assembly. The interface definition is the same. The Portable Class Library version of the CSL targets the following platforms:
  • .NET Framework 4 and higher
  • Silverlight 4 and higher
  • Windows Phone 7 and higher
  • .NET for Windows Store apps
  • Xbox 360

Updated Release: Common Service Locator 1.0 (Sep 30, 2008)

$
0
0
This is a signed binary of the Microsoft.Practices.ServiceLocation DLL and associated PDB and XML Doc comment files. This provides a common assembly to implement IServiceProvider.

New update: Signed assemblies for Silverlight 2.0. The interface definition is the same.

Newer update: Signed Portable Class Library version of assembly. The interface definition is the same. The Portable Class Library version of the CSL targets the following platforms:
  • .NET Framework 4 and higher
  • Silverlight 4 and higher
  • Windows Phone 7 and higher
  • .NET for Windows Store apps
  • Xbox 360

New Comment on "Autofac Adapter"

$
0
0
Since there doesn't seem to be any documentation on how to use the adapter and everything links here, here's how: You need to install CSL, Autofac, *and* Autofac.Extras for CSL (https://nuget.org/packages/Autofac.Extras.CommonServiceLocator/3.0.1). Once you do that, you have access to the Autofac.Extras.CommonServiceLocator namespace. An example of initializing is below. Dim builder = New ContainerBuilder() builder.RegisterType(GetType(BlahBlahBlahMyClass)) Dim c = builder.Build() Dim locator = New Autofac.Extras.CommonServiceLocator.AutofacServiceLocator(c) ServiceLocator.SetLocatorProvider(Function() locator) Hope that helps!

Edited Issue: ServiceLocator.Current throws NullReferenceException [9676]

$
0
0
When no IoC container is registered using ServiceLocator.SetLocatorProvider(ServiceLocatorProvider) the Current property will throw a NullReferenceException. Throwing a NullReferenceException is always a bad thing for a reusable framework such as CSL, or to quote the Framework Design Guidelines: "DO NOT allow publicly callable APIs to explicitly or implicitly throw NullReferenceException".
 
The Current property should check if the currentProvider delegate is null and if so, throw an InvalidOperationException with an expressive exception message, explaining what is wrong and what should be done to resolve this issue.

New Comment on "Project Rationale"

$
0
0
I actually find this to be a simple, but very powerful idea. It allows the use of IoC ServiceLocator implementation today and another tomorrow if you find a better one. It also lets you port classes and frameworks from one IoC to another without refactoring the ServiceLocator code. I would actually like to see P&P take the lead for some other incredibly common frameworks like logging.

New Comment on "Project Rationale"

$
0
0
I don't agree with dot_NET_Junkie regarding the fact that the interface being useless. Having written LOB applications that use numerous 3rd party frameworks on the market, its often a mess trying to integrate every frameworks IoC/DI requirements. And that is the very thing this interface is trying to address, and does so rather well (provided those third party libraries support it). For a LOB application, it also protects your investment. I've been developing LOB since the 90s and frameworks come and go. From that experience I often wrap 3rd party frameworks so they can be easily replaced in the future.

Source code checked in, #106765

$
0
0
Added IsLocationProviderSet property on ServiceLocator static class

Released: Common Service Locator 1.2 (Feb 05, 2014)

$
0
0
This release fixes issue 9676 in the portable class library assembly.

Created Release: Common Service Locator 1.2 (Feb 05, 2014)

$
0
0
This release fixes issue 9676 in the portable class library assembly.

Commented Issue: ServiceLocator.Current throws NullReferenceException [9676]

$
0
0
When no IoC container is registered using ServiceLocator.SetLocatorProvider(ServiceLocatorProvider) the Current property will throw a NullReferenceException. Throwing a NullReferenceException is always a bad thing for a reusable framework such as CSL, or to quote the Framework Design Guidelines: "DO NOT allow publicly callable APIs to explicitly or implicitly throw NullReferenceException".
 
The Current property should check if the currentProvider delegate is null and if so, throw an InvalidOperationException with an expressive exception message, explaining what is wrong and what should be done to resolve this issue.
Comments: ** Comment from web user: fcheung **

We addressed this issue by adding an IsLocationProviderSet property to the static ServiceLocator class. If the LocationProvider is not set using the SetLocationProvider method, IsLocationProviderSet will return false and Current will throw an InvalidOperationException.

Closed Issue: ServiceLocator.Current throws NullReferenceException [9676]

$
0
0
When no IoC container is registered using ServiceLocator.SetLocatorProvider(ServiceLocatorProvider) the Current property will throw a NullReferenceException. Throwing a NullReferenceException is always a bad thing for a reusable framework such as CSL, or to quote the Framework Design Guidelines: "DO NOT allow publicly callable APIs to explicitly or implicitly throw NullReferenceException".
 
The Current property should check if the currentProvider delegate is null and if so, throw an InvalidOperationException with an expressive exception message, explaining what is wrong and what should be done to resolve this issue.
Comments: Fixed in changeset 106765:
https://commonservicelocator.codeplex.com/SourceControl/changeset/106765

Commented Issue: ServiceLocator.Current throws NullReferenceException [9676]

$
0
0
When no IoC container is registered using ServiceLocator.SetLocatorProvider(ServiceLocatorProvider) the Current property will throw a NullReferenceException. Throwing a NullReferenceException is always a bad thing for a reusable framework such as CSL, or to quote the Framework Design Guidelines: "DO NOT allow publicly callable APIs to explicitly or implicitly throw NullReferenceException".
 
The Current property should check if the currentProvider delegate is null and if so, throw an InvalidOperationException with an expressive exception message, explaining what is wrong and what should be done to resolve this issue.
Comments: ** Comment from web user: MichaelKetting **

Thank you for addressing this issue.

I do have a question in regard to the naming: The rest of the API on "ServiceLocator" is using "Locator" but the new API is using "Location". I would like to better understand the naming convention behind this.

Best regards, Michael


New Post: Query methods

$
0
0
Today a new version of the CSL has been released. It's nice to see that old issues are being addressed

I'm curious if you have any intentions to address the issue I described above and was confirmed by @gblock?

Commented Issue: ServiceLocator.Current throws NullReferenceException [9676]

$
0
0
When no IoC container is registered using ServiceLocator.SetLocatorProvider(ServiceLocatorProvider) the Current property will throw a NullReferenceException. Throwing a NullReferenceException is always a bad thing for a reusable framework such as CSL, or to quote the Framework Design Guidelines: "DO NOT allow publicly callable APIs to explicitly or implicitly throw NullReferenceException".
 
The Current property should check if the currentProvider delegate is null and if so, throw an InvalidOperationException with an expressive exception message, explaining what is wrong and what should be done to resolve this issue.
Comments: ** Comment from web user: fcheung **

Hello Michael,

Looks like an oversight on my part. You're right that IsLocatorProviderSet is probably more consistent with other parts of the API. In my defense, however, the assembly is called "Microsoft.Practices.ServiceLocation".

Cheers,
-Francis

Released: Common Service Locator 1.2 (Feb 05, 2014)

$
0
0
This release of the Common Service Locator includes a portable class library that targets the following platforms:
  • .NET 4 and higher
  • Windows Phone 8
  • Windows Store apps (Windows 8) and higher
  • Silverlight 5

This release fixes issue 9676 in the portable class library assembly.

Updated Release: Common Service Locator 1.2 (Feb 05, 2014)

$
0
0
This release of the Common Service Locator includes a portable class library that targets the following platforms:
  • .NET 4 and higher
  • Windows Phone 8
  • Windows Store apps (Windows 8) and higher
  • Silverlight 5

This release fixes issue 9676 in the portable class library assembly.

Commented Issue: ServiceLocator.Current throws NullReferenceException [9676]

$
0
0
When no IoC container is registered using ServiceLocator.SetLocatorProvider(ServiceLocatorProvider) the Current property will throw a NullReferenceException. Throwing a NullReferenceException is always a bad thing for a reusable framework such as CSL, or to quote the Framework Design Guidelines: "DO NOT allow publicly callable APIs to explicitly or implicitly throw NullReferenceException".
 
The Current property should check if the currentProvider delegate is null and if so, throw an InvalidOperationException with an expressive exception message, explaining what is wrong and what should be done to resolve this issue.
Comments: ** Comment from web user: MichaelKetting **

Hello Francis!

Thanks for clearing that one up.

Best regards, Michael

Viewing all 118 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>