Failed to resolve type MvvmCross.Platform.UI.IMvxNativeColor - mvvmcross

I am trying to use the MvvmCross.Plugin.Color library so that I can use a converter for colors. Here is my converter:
public class MyColorValueConverter : MvxColorValueConverter<bool>
{
protected override MvxColor Convert(bool value, object parameter, CultureInfo culture)
{
return value ? new MvxColor(19, 119, 51) : new MvxColor(171, 8, 16);
}
}
And in the .xml:
<MyView
android:layout_width="match_parent"
android:layout_height="40dp"
local:MvxBind="BackgroundColor MyColor(MyBool)" />
But when I raise the property change of MyBool, I get an exception with this message:
MvvmCross.Platform.Exceptions.MvxIoCResolveException: Failed to
resolve type MvvmCross.Platform.UI.IMvxNativeColor at
MvvmCross.Platform.IoC.MvxSimpleIoCContainer.Resolve

Make sure that the plugin gets registered against the IoC container and is install in the platform projects as well as your core project.
This can would normally be done via the plugin bootstrap class. Which is normally included when you install the MvvmCross.Plugin.Color in your platform project. However, if you are using Nuget via project.json the additional bootstrap class will no automatically get included.
Create a folder Bootstrap of the root of your android project and a ColorPluginBootstrap.cs
using MvvmCross.Platform.Plugins;
namespace {{Your name space}}.Bootstrap
{
public class ColorPluginBootstrap
: MvxPluginBootstrapAction<MvvmCross.Plugins.Color.PluginLoader>
{
}
}

You can also add this to your MvxAndroidSetup of your Android project instead:
protected override IEnumerable<Assembly> ValueConverterAssemblies
{
get
{
var toReturn = base.ValueConverterAssemblies.ToList();
toReturn.Add(typeof(MvxNativeColorValueConverter).Assembly);
return toReturn;
}
}

Related

system.invalidoperationexception sequence contains no elements at system.linq.enumerable.first[TSource]{IEnumaberable`1 source}

I installed an updated visual studio in 2019. After that, I opened my xamarin application and ran the app. It's built successfully. Before opening the application in the emulator I got the below issue.
I was helped by the exclusion of using an inherited classes without overridden methods.
for example base class defined in net standard lib:
public class DFStorage
{
public virtual bool SaveAppTextFile(...)
{
...
}
public virtual string GetAppTextFile(...)
{
...
}
}
inherited in platform specific lib:
(without any overrides)
public class DFStorageIOS : DFStorage
{
}
App use platform class.
Overriding of one method was enough:
public class DFStorageIOS : DFStorage
{
public override bool SaveAppTextFile(...)
{
return base.SaveAppTextFile(...);
}
}

Startup.cs error (ASP.Net Core configuration)

I am trying to set up an ASP.Net Core application to read in configuration settings from a json file. I am using VS2015 and .NetCore 1.0 (with .Net Core Tools preview 2). I am having problems getting a simple piece of boiler plate code to compile.
I am using the following code, which was published at
http://asp.net-hacker.rocks/2016/03/21/configure-aspnetcore.html
public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();
if (env.IsDevelopment())
{
// This will push telemetry data through Application Insights
// pipeline faster, allowing you to view results immediately.
builder.AddApplicationInsightsSettings(developerMode: true);
}
Configuration = builder.Build();
}
However, the IDE/compiler complains that 'the name "Configuration" does not exist in the current context' (last line of code). The only suggestion from the IDE is to include Microsoft.Extensions.Configuration. However this is a namespace which does not contain an object or property named "Configuration".
In addition 'AddApplicationInsightsSettings' fails with does IConfigurationBuilder not contain a definition for AddApplicationInsightsSettings and no extension method AddApplicationInsightsSettings accepting a first argument of type IConfigurationBuilder could be found
Any suggestions please ?
Thanks
Simply add Configuration property to your Startup class, tutorial has missed this 'step':
public IConfigurationRoot Configuration { get; set; }
ConfigurationBuilder.Build() method just returns instance of IConfigurationRoot, that you should save, if need to get settings further in Startup class (in ConfigureServices method for example).
Regarding second error, looks like you didn't add the Application Insights dependency:
{
"dependencies": {
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0"
}
}

Resolve caste windsor failing

Recently upgraded to version 3.2.1 of castle windsor and receiving an error when attempting to resolve a service that previously didn't occur in version 3.0 of the windsor framework.
IWindsorContainer container = new WindsorContainer();
The following code no longer works
// Throws component not found exception
InstallerHelper.ProcessAssembliesInBinDirectory(
assembly => container.Register(
Classes
.FromAssembly(assembly)
.BasedOn<IWindsorInstaller>()
.WithService.FromInterface()
.LifestyleSingleton()
));
var installers = container.ResolveAll<IWindsorInstaller>();
container.Install(installers);
// Fails here, is it related to a hashcode mismatch in SimpleTypeEqualityComparer?
var credentialCache = container.Resolve<ICredentialCache>()
// works fine if explicity install installers individually
container.Install(new CredentialsInstaller());
var credentialCache = container.Resolve<ICredentialCache>()
Where ProcessAssembliesInBinDir is:
public static void ProcessAssembliesInBinDirectory(Action<Assembly> action)
{
var directoryName = GetDirectoryName();
foreach (var dll in Directory.GetFiles(directoryName, "*.dll"))
{
var fileInfo = new FileInfo(dll);
if (!IgnoreList.Any(x=>fileInfo.Name.StartsWith(x)))
{
var assembly = Assembly.LoadFile(dll);
action(assembly);
}
}
}
Where credential installer is:
public class CredentialsInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For<ICredentidalCache>()
.ImplementedBy<CredentidalCache>()
.LifestyleSingleton()
);
// This works fine
var credentialCache = container.Resolve<ICredentialCache>()
}
}
Class implementation
public interface ICredentidalCache {}
public class CredentidalCache : ICredentidalCache{}
This is being run from an MVC application
version 4.5 of the .net framework
the credential installer lives inside another assembly, referenced by the website
using the Windsor source, the successful attempt to resolve occurs when the typeof(ICredentialCache).GetHashCode() is the same as what has been registered. For some reason when returning out of the installer the hashcode has changed for the type. Putting a debug line inside SimpleTypeEqualityComparer.GetHashCode(Type obj) shows that hashcodes are different for the same Type.
inspecting the container inside the debugger shows the ICredentialCache successfully installed.
Edit
Manage to move forward by manually registering installers, ie. not relying on the resolve<IwindsorInstaller>() and use container.install(new Installer(), ...). If i find out more I'll update the SO question.
This works fine for me:
public sealed class AppServiceFactory
{
...
public T Create<T>()
{
return (T)container.Resolve(typeof(T));
}
...
}
AppServiceFactory.Instance.Create<IYourService>();
The problem is caused by the InstallerHelper and how it goes about loading an assembly. This SO post pointed me in the right direction,
https://stackoverflow.com/a/6675227/564957
essentially the way the assembly was loaded was failing using Assembly.LoadFile(string fileName) was causing the problem, changing this to be Assembly.Load(string assemblyName) rectified the issue.
#Eric Lippert does a good job explaining
[when] loading an assembly by its path, and one via loading the same
assembly by its assembly name... reflection will
consider types from the two loadings of the same assembly to be
different types. Any assembly loaded from its path is considered to be
distinct from an assembly loaded by its assembly name.

Custom SSIS task - Version property

We have a custom SSIS task (not component), and need to add new property. It would be good to support SSIS upgrade feature, so all clients have to do with existing packages is to upgrade them.
We already implemented Update and CanUpdate methods, but we can't find the way to update Version property of custom task, since it is read-only.
Is there any way to set Version property?
Thanks everyone!
The Task.Version property is virtual (as are the Update and CanUpdate methods), so you can override it in the same manner:
[DtsTask (/* whatever your task attributes are */)]
public class MyDemoTask : Task
{
public override bool CanUpdate(string CreationName)
{
// your code here
}
public override void Update(ref string ObjectXml)
{
// your code here
}
public override int Version
{
get
{
return 42;
}
}
}

The type or namespace name 'MicroKernel' does not exist in the namespace 'Castle' (are you missing an assembly reference?)

I'm new to castle windsor and wanted to learn it.
I downloaded Windsor 2.5.3 for .net4 from here http://www.castleproject.org/castle/download.html
I built my first console app using vs2010 and try to play around.
The following are my code(very simple)
using Castle.Windsor;
using Castle.MicroKernel.Registration;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
WindsorContainer wc = new WindsorContainer();
wc.Register(Component.For<I>().ImplementedBy<C>());
var v = wc.Resolve<I>();
var result = v.M();
}
}
public class C : I
{
public string P1 { get; set; }
public int M()
{
return 100;
}
}
public interface I
{
int M();
}
}
But it didn't get compiled, error msg says:
The type or namespace name 'MicroKernel' does not exist in the namespace 'Castle' (are you missing an assembly reference?)
The type or namespace name 'Windsor' does not exist in the namespace 'Castle' (are you missing an assembly reference?)
I actually referenced castle.core and castle.windsor dlls and intellisense was working fine until compile....
I also noticed that when I double click the castle.windsor in reference, it's not showing the namespace hierarchy in object browser window.
I even commented out all my code, it still can't compile, says the same error msg.
Can you please advise what can I do to make it run. really appreciate it!!
The problem is likely the target framework of your project.
Open project properties, and look for the target framework dropdown. If it says .Net Framework 4.0 Client Profile, change it to .Net Framework 4.0.