Xamarin.UWP 错误
Xamarin.UWP bug
DotNetNativeToolChain 应该有错误。在 project_name.UWP.csproj 文件中,我有
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
在xaml,我有
<Image x:Name="testimage"></Image>
在代码隐藏文件中,我有
testimage.Source = ImageSource.FromResource("project_name.testimage1.png");
testimage1.png输入project_name.csproj为
<EmbeddedResource Include="testimage1.png" />
项目可以编译但崩溃并报错"Unhandled exception at 0x(Windows.UI.Xaml.dll) in .exe. 0xC000027B: An application-internal exception has occurred."
如果我注释掉 project_name.UWP.csproj 文件中的 "UseDotNetNativeToolchain",应用程序运行顺利。
public ImageSource GetImageSource(string resource)
{
ImageSource imagesource = null;
Assembly assembly = GetType().GetTypeInfo().Assembly;
MemoryStream ms = new MemoryStream();
using (Stream stream = assembly.GetManifestResourceStream(resource))
{
if (stream != null)
{
stream.CopyTo(ms);
imagesource = ImageSource.FromStream(() => new MemoryStream(ms.ToArray()));
}
}
return imagesource;
}
在代码中,我使用
testimage.Source = GetImageSource("project_name.testimage1.png");
DotNetNativeToolChain 应该有错误。在 project_name.UWP.csproj 文件中,我有
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
在xaml,我有
<Image x:Name="testimage"></Image>
在代码隐藏文件中,我有
testimage.Source = ImageSource.FromResource("project_name.testimage1.png");
testimage1.png输入project_name.csproj为
<EmbeddedResource Include="testimage1.png" />
项目可以编译但崩溃并报错"Unhandled exception at 0x(Windows.UI.Xaml.dll) in .exe. 0xC000027B: An application-internal exception has occurred."
如果我注释掉 project_name.UWP.csproj 文件中的 "UseDotNetNativeToolchain",应用程序运行顺利。
public ImageSource GetImageSource(string resource)
{
ImageSource imagesource = null;
Assembly assembly = GetType().GetTypeInfo().Assembly;
MemoryStream ms = new MemoryStream();
using (Stream stream = assembly.GetManifestResourceStream(resource))
{
if (stream != null)
{
stream.CopyTo(ms);
imagesource = ImageSource.FromStream(() => new MemoryStream(ms.ToArray()));
}
}
return imagesource;
}
在代码中,我使用
testimage.Source = GetImageSource("project_name.testimage1.png");