Reputation: 1898
I'm trying to migrate my PCL project to the new "net standard" but for now I failed.
Currently I got the following exception :
System.MissingMethodException: 'Method not found: 'Void Xamarin.Forms.Xaml.Internals.SimpleValueTargetProvider..ctor(System.Object[], System.Object, Xamarin.Forms.Internals.INameScope)'.'
It happend directly from the 'InitializeComponent' of a page where I have the following xaml tag:
<Image Source="{ns_uc:ImageResource i_home_on.png}"/>
where the 'ImageResource' is an extension marker, this one works like a charm in my PCL project. Here is a part of the definition :
public class ImageResourceExtension : IMarkupExtension
But this class is not called from my new .NET Standard project !
In the .csproj I have the following references, it should be enough ?
<PackageReference Include="System.ComponentModel" Version="4.3.0" />
<PackageReference Include="Xamarin.Forms" Version="3.4.0.1008975" />
So, if someone have an idea because I have already spend 2 days in this migration, without success :-(
BTW, it seems I'm not alone : https://forums.xamarin.com/discussion/101999/cant-use-imarkupextension-in-a-net-standard-library
Thanks for your help
Upvotes: 1
Views: 199
Reputation: 1856
I would follow James Montemagno's steps:
https://montemagno.com/how-to-convert-a-pcl-library-to-net-standard-and-keep-git-history/
I followed this video from the Xamarin show: https://channel9.msdn.com/Shows/XamarinShow/Snack-Pack-15-Upgrading-to-XamarinForms-to-NET-Standard
I tried it on my own the first go around and failed miserably. The second go around I followed the instructions from the video exactly and everything worked.
Upvotes: 0
Reputation: 15786
1.System.ComponentModel is a NuGet package in some NetStandard versions.Try to install it if it doesn't exist.
2.You can use <Image Source="myImage.png"/>
directly instead of using IMarkupExtension
in .net standard project.
3.The implement of ImageResourceExtension
maybe different in PCL project and .net standard 2.0 project. Here is an implement in official demo you can refer:
[ContentProperty("Source")]
class ImageResourceExtension : IMarkupExtension<ImageSource>
{
public string Source { set; get; }
public ImageSource ProvideValue(IServiceProvider serviceProvider)
{
if (String.IsNullOrEmpty(Source))
{
IXmlLineInfoProvider lineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
IXmlLineInfo lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
throw new XamlParseException("ImageResourceExtension requires Source property to be set", lineInfo);
}
string assemblyName = GetType().GetTypeInfo().Assembly.GetName().Name;
return ImageSource.FromResource(assemblyName + "." + Source, typeof(ImageResourceExtension).GetTypeInfo().Assembly);
}
object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
{
return (this as IMarkupExtension<ImageSource>).ProvideValue(serviceProvider);
}
}
You can refer the demo below to fix your project.
Refer:Demo of ImageResourceExtension
Documents of Markup Extensions
Upvotes: 1