Question

I have existing code that compiled and worked fine with Caliburn Micro 1.4:

private static readonly Lazy<IShell> shellLazy = new Lazy<IShell>(IoC.Get<IShell>, true);

I removed the 1.4 version and installed through NuGet the 1.5 version and without changing anything this line now throws an error:

Error 1 The best overloaded method match for 'System.Lazy.Lazy(System.Func, System.Threading.LazyThreadSafetyMode)' has some invalid arguments C:\Users\User\Documents\Visual Studio 2012\Projects\Arnova\Src\CShellCore\Shell.cs 35 58 CShellCore

The only way I have found the get rid of this error is to avoid using Lazy<> at all:

private static readonly IShell shellLazy = IoC.Get<IShell>();

I have searched for anything related to IoC.Get<> and Lazy<> and what may have changed from version 1.4 to 1.5 and cannot find anything to explain what has changed in Caliburn Micro between these versions and how to work around this.

Was it helpful?

Solution

I think your problem is that IoC.Get<T> is a static method that returns an instance of type T, in other words it is not a Func<T> so to solve the problem you will have to modify your code like so:

private static readonly Lazy<IShell> shellLazy = new Lazy<IShell>(() => IoC.Get<IShell>(), true); 

That is the reason for the compilation error that there is no constructor on type Lazy<> accepting an IShell instance.

OTHER TIPS

Found it, not sure why this needed to be changed this way? The intellisense shows the same info for both the 1.4 and 1.5 caliburn micro versions, these functions look to be expecting the same parameters.

This appears to work so far though:

private static readonly Lazy<IShell> shellLazy = new Lazy<IShell>(() => { return IoC.Get<IShell>(); }, true);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top