XamlReader official code snippet throwing exception for me - c#

I'm building a Windows 8 app, and want to parse some XAML from a web service to put in a RichTextBlock. I'm trying to use XamlReader to use this, but this code from Microsoft's documentation is throwing an exception in my environment.
string xaml = "<Ellipse Name=\"EllipseAdded\" Width=\"300.5\" Height=\"200\" Fill=\"Red\" \"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"/>";
object ellipse = Windows.UI.Xaml.Markup.XamlReader.Load(xaml);
When executing the second line, I get the exception:
An unhandled exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in mscorlib.dll
WinRT information: illegal qualified name character [Line: 1 Position: 68]
Additional information: Unspecified error
My version of VS is Microsoft Visual C# 2012 (Microsoft Visual Studio Premium 2012 Version 11.0.51106.01, Microsoft .NET Framework Version 4.5.50709). The documentation says Windows 8 should support the load method. Any ideas?

It looks like there's a typo in their XAML - they're missing an xmlns= before the namespace URI:
string xaml = "<Ellipse"
+ " Name=\"EllipseAdded\" Width=\"300.5\" Height=\"200\" Fill=\"Red\""
+ " xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"/>";
(Line wrapped for readability.)

Related

Xamarin Forms Could not load type Plugin.SharedTransitions.SharedTransitionShell while decoding custom attribute: (null) occurred

I develop a mobile app on Xamarin forms using visual studio.
I am using Xamarin forms 4.5+ and Android 9.0- API 28.
I am using Panacake view and shared transions when I run my app I get this error below:
Unhandled Exception:
System.TypeLoadException: Could not load type Plugin.SharedTransitions.SharedTransitionShell while decoding custom attribute: (null) occurred
Please use Xamarin.Forms version.4.8.0.1560, Xamarin.Forms.PancakeView 2.3.0.759 and Xamarin.Plugin.SharedTransitions 2.4.0, My target Framework set it to Android 9.0. it could run normally.

Xamarin C# empty project exception: Culture not supported

Just downloaded Xamarin Studio 5.9.6 (build 23), and went into Tools - Options - Language, and selected "English" as the "User interface language".
When I created a new C# "empty project", Xamarin complained, a dialog box displayed saying: "An error has occurred - The project could not be created".
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException:
The type initializer for 'Microsoft.FSharp.Compiler.SourceCodeServices.FSharpChecker' threw an exception. ---> System.TypeInitializationException:
The type initializer for '<StartupCode$FSharp-Compiler-Service>.$Service' threw an exception. ---> System.TypeInitializationException:
The type initializer for '<StartupCode$FSharp-Compiler-Service>.$Reactor' threw an exception. ---> System.Globalization.CultureNotFoundException: Culture is not supported.
Parameter name: culture
4096 (0x1000) is an invalid culture identifier.
Kinda of a strange little annoyance. Running Windows 10 x64. I have tons of Visual Studios on this PC as well, including VS2015.
This is a bug in Xamarin Studio's language selection on Windows 10. It is fixed in Xamarin Studio 5.10.
This is normally seen when English is selected, typically this would be done with Windows 10 using a non-English language, and configuring Xamarin Studio to use English would not change the UI text but would still show the language used by Windows.
The problem is that on Windows 10 a lot of the English non-neutral cultures returned from CultureInfo.GetCultures have an unspecified custom locale ID (LCID) which is 0x1000. Earlier versions of Windows do not have this problem. One of these cultures was being used to set the current UI culture and it was ignored since it is invalid. According to the MSDN documentation before Windows 10 unspecified custom locale ids were assigned to custom cultures created by the user. In Windows 10 this unspecified custom locale id is assigned to any culture that does not have a unique locale identifier and does not have complete system provided data. So Windows 10 returns more locales with this unspecified locale id.
Since Xamarin Studio was using an invalid culture this caused the F# exception.
Now these cultures with unspecified custom locale ids are ignored by Xamarin Studio 5.10 and above.
The interesting thing about this error is it is complaining about the F# compiler. Yet, my intent was to create a new C# empty project. ...and I do have F# loaded due to my Visual Studio instance(s). And I am in the USA, it's not like I was attempting to load a different language.
So the quick fix for this was to go back into Xamarin Tools - Options - Language, and change it back to (default).
User error (?) by selecting English.

NReco.ImageGenerator failed to generate image from file

i'm trying to create jpg files from html using NReco.ImageGenerator nuget.
i'm using function 'GenerateImageFromFile', in most cases the generation works fine, in other cases the dll throws me:
'An unhandled exception of type 'System.Exception' occurred in NReco.ImageGenerator.dll
Additional information: Image generation failed: Exit with code 1 due to network error: ContentNotFoundError'
i'll be glad to hear your opinion, any solution will be appreciated.
Thanks guys.
NReco uses an open source program called "wkhtmltopdf" (you can find it on https://github.com/wkhtmltopdf/wkhtmltopdf).
After run your application the .dll puts the "wkhtmltoimage.exe" in the path, in my case when I run the "wkhtmltoimage.exe" it asks for a .dll, in the majority of the cases you just need install the Visual C++ redistributable package (http://www.microsoft.com/en-us/download/confirmation.aspx?id=40784)
Since ImageGenerator is a .net wrapper for wkhtmltoimage you can apply the following command line option to ignore content load errors:
var htmlToImage = new NReco.ImageGenerator.HtmlToImageConverter();
var htmlToImage.CustomArgs = " --load-error-handling ignore ";
With this option wkhtmltoimage will ignore errors when referenced resource (js,css,images etc) cannot be downloaded.
Ederson's answer about VC++ runtime libs is correct for case if ImageGenerator throws an exception for any input (error message is "The pipe has been ended" or "Image generation failed: (exit code: 255)").

Use pages from a Windows Phone App inside another Phone App

I have a Windows Phone 8 Solution which consisted of 3 projects (2 class libraries and one WP8 app).
This project has some XAML pages like (MyMainPage, MySearchPage, MyResultPage, etc..) with their ViewModel classes.
Now i have created a new Windows Phone 8 solution from scratch.
Is there a way in Visual Studio to reference the first App so I can re-utilize those pages without having to copy the source code to my new solution?
I've tried referencing the 2 dlls from the class libraries and the .exe from the WP8 project. But i get exceptions when starting the new App.
When doing something like MySearchPage page = new MySearchPage() i get this exception:
An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in MyFirstWP8App.EXE but was not handled in user code
and sometimes thi one too on startup:
An exception of type 'System.Exception' occurred in PivotTest.EXE but was not handled in user code
Additional information: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred

I use VS 2012 to do this tesseract code project.
I created WPF(C# project) import tesseractengine3.dll set using tesseract;
and created variable:
TesseractProcessor test = new TesseractProcessor() ;
and then compile the code in debug mode (x86 , with target .net 4)
It shows Error message dialog
"An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: 'The invocation of the constructor on type 'Recog.OcrTest' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'."
I searched on tesseractdotnet blog, and also google a lot of website and found nothing.
PS. I can run this code succesfully on VS2008. But when I code in VS2012 is occured error.
I cannot do my project in VS2008 because I have to some code of kinect which cannot work with VS2008.
Please anyone guide my how to solve this problem. I stuck with this problem for 1 week.

Categories

Resources