Frame.Navigate to a Page-derived class in a different assembly - c#

I'd like to keep my Windows Phone 8 Blank App template based view in a different assembly than the assembly containing the application manifest and App.xaml.
I keep receiving a cryptic exception which doesn't help at all in figuring out how to fix it:
Create a new project from the template Visual C# > Store Apps > Windows Phone Apps > Blank App (Windows Phone).
Build and deploy, works great. The properties of the MainPage.xaml state the Build Action is Page, which is correct.
Create a new project based on the Class Library (Windows Phone) template from the same category within the solution containing the original project, call it MyApp.Views.
Move the MainView.xaml file to the newly created project using Cut and Paste commands.
Add a reference to MyApp.Views to the original project.
Build, deploy, see the app start and fail to locate the view only to propagate this exception back to the developer's box: ComException: Error HRESULT E_FAIL has been returned from a call to a COM component. This doesn't say absolutely anything at all useful and the top stack frame is Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter) following the first one, which is TheOriginalProject.App.OnLaunched(LaunchActivatedEventArgs e).
The solution is not to use NavigationService with pack URI since it seems to be absent in Windows Phone 8, or at very least the assembly containing it is not referenced by default in the Blank App template. In any event, I'd vastly prefer strongly typed view names over pack URIs.
I imagine someone must've run into this issue already, what's the catch? Is there an API or a tool that will give me an insight on what the latest E_FAIL coming from COM is?
Edit: When using Window.Current.Content = new MainPage() as the only content of OnLaunched, the XAML parser exception pops up. It is unable to populate an exception message, but definitely gives a better hint to what's going on. Still no solution, though, the problem only moved to the this.InitializeComponent() in the MainPage constructor.
What I see now is Windows.UI.Xaml.Markup.XamlParseException with WinRT information of Parser internal error: Object writer '%0' and Additional information unable to load. x:Class attribute is present at the position 128 hinted on by the exception dialog window and this thread seems relevant, but I can't work out how.
Please note that I'll also find values in people confirming not receiving the error I do. If you've tried the steps to reproduce and failed to reproduce the problem, please write a comment so I can pin down what it is that causes the error I'm struggling with.

Alternative solution to externalizing views to a separate project while avoiding this problem is to use a Shared project project type, put the views there and reference it from the main project.
This does not produce a separate assembly for the views, instead the files are just grouped within their custom project, but behave as if they were part of the main project during compilation. The error goes away because from the compiler point of this, there's no difference between a file in a shared project and a file directly in the main project. During runtime, the type of the view doesn't need to be resolved from a different assembly, it's right there in the same assembly.

Related

Xamarin.Forms iOS crash on XAML pages with custom controls

I am working on a Xamarin.Forms project, for which I recently upgraded the shared projects from PCL to .NETStandard.
At that point, I encountered build issues coming from several of my UI XAML files, with the error being:
Failed to resolve assembly: ‘MyAssembly, Version 0.0.0.0,
Culture=neutral, PublicKeyToken=null’
The problem files were found to be those that referenced custom XAML controls. After finding several people with similar issues online, I eventually found that I could get past this issue by setting the XamlCompilationOptions for those pages from Compile to Skip. The project now builds for iOS and Android.
The Android version works normally, however for the iOS version crashes when one of those pages tries to load, due to the presence of the custom control, with an error such as:
Xamarin.Forms.Xaml.XamlParseException … Type shared.SharedControl not
found in xlmns clr-namespace: …
Has anyone encountered this issue, and if so, did you solve it? Is it a code issue or a Xamarin / Visual Studio Mac bug?
Ideally I would like to not have to set the XamlCompilationOptions for those pages to Skip, but either way I don't see why it should affect iOS but not Android.
Firstly, XamlCompilationOptions.Compile means Compile the XAML for the class or project when the application is built.While XamlCompilationOptions.Skip do the same thing when the application is run on the device.
In addition ,I suggest that you can do following steps:
Delete and Re-generate all share files
Remove ;assembly:xxx from App.xaml
Clean and build again.
Here is a similar thread for you referring toXamarin.Forms.Xaml.XamlParseException has been thrown
PS:There is a link about how to Upgrade PCL to .NET Standard Class Library
You need to load that assembly before using it. On Xaml it does not load, just try to reach, and crashes if its not loaded. Before using it you need to load assembly by calling a method, or creating an object belong MyAssembly.
There should be a Init method for the assembly to init things. you should call it.

IBackgroundTask with ControlChannelTrigger, project manifest errors

I have a separate component project (BackgroundWorkers) within my solution that encapsulates my IBackgroundTask. My main ui project (SufaceHubMonitoring) has a reference to it and is also its own separate project within the solution.
Since my Im going to be using these background task I need to declare them in my manifest
but as you can see in the image there is an error because neither Executable nor Start page is populated.
However I get neither when building my component (BackgroundWorkers) project. The only thing it outputs is
C:\SurfaceHubMonitoring\trunk\BackgroundWorker\bin\x86\Debug\BackgroundWorkers.winmd
How should my background task be declared in the manifest file?
the error went away after I put
$targetnametoken$.exe
in the Executable field
NOTE:
also had an access error, which was resolved via this SO post

Using WinRT API in WPF application for Orientation (Windows 8.1, VS issues)

I have followed this tutorial.
My first issue is that when I want to add the reference to Windows, I have a full list of references
As you can see, I added all to my project to make it works, and the other references of the tutorial.
But my application won't compile :(
I have this error :
Not implemented (Exception HRESULT : 0x80004001 (E_NOTIMPL))
And this one
Cannot resolve dependency to Windows Runtime type 'Windows.Foundation.Metadata.PlatformAttribute'. When using the ReflectionOnly APIs, dependent Windows Runtime assemblies must be resolved on demand through the ReflectionOnlyNamespaceResolve event.'
I have seen this post but it seems that the issue the author encounter is not the same as mine, because he had it to runtime (exception thrown), whereas I have to compile-time.
Is anyone have an idea how to proceed ?
For information : the main purpose of this is to have access to Windows.Devices.Sensor to have the screen orientation, cause we have an application that takes photo from WebCam in WPF, and when we use it on Surface tablet, the picture display on screen didn't follow the orientation of the tablet, which makes picture really hard to take.
Thanks all
This works fine for me - not sure why you're getting the runtime metadata (one winmd per top-level namespaces) rather than the design-time metadata (single winmd). This is what I did on my 8.1 machine:
File -> New Project -> C# WPF
Unload the project and edit it
Add <TargetPlatformVersion>8.1</TargetPlatformVersion> directly below the existing <TargetFrameworkVersion>4.5</TargetFrameworkVersion> element
References -> Add Reference -> Windows -> Core -> Windows
Then I added the following code to MainWindow.InitializeComponent:
var sos = Windows.Devices.Sensors.SimpleOrientationSensor.GetDefault();
Debug.WriteLine(sos == null ? "No sensor" : sos.GetCurrentOrientation().ToString());
It compiles and runs correctly, but there is no sensor on my desktop, so prints "No sensor".
If you can't get the references UI to show you the design-time metadata, browse to C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd

Error trying to access converted C# project from VB

Beginner here. I'm trying to move over to C# for the future, so I want to convert my main project to it. I'm tried using SharpDevelop 4.4, but after converting attempting to open my forms in Visual Studio results in:
To prevent possible data loss before loading the designer, the following errors must be resolved:
The designer could not be shown for this file because none of the classes within it can be designed.
and the error:
Instances of this error (1)
1. Hide Call Stack
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)
Is there a way I can manually convert the files? I know there are code converters online, but I have no idea how you would change the entire solution.
Edit: Getting this error after trying to run the program:
Error 5 The OutputPath property is not set for project 'Skype.Converted.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='AnyCPU'. This error may also appear if some other project is trying to follow a project-to-project reference to this project, this project has been unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Configuration or Platform. Skype.Converted
And an info message:
Message 4 The designer could not be shown for this file because none of the classes within it can be designed.
I would recommend this code converter, as it's the one I've used when I've only been able to find solutions to my answers in C# and need them in VB.
I'm sure you could use it for the reverse action to manually convert your code.
Link: http://converter.telerik.com/
As far as the designer bits are concerned, I'm relatively certain you can select all of your controls on one project, copy, and then paste them onto the other project. Re-associating them with their functions/handles will be annoying though.

Strange exception suddenly appears when trying to install a setup project, need help big time

Using Visual Studio 2010 to build a setup project that installs a Windows Forms application .Net 4.0 C#. It has worked fine for ages but now when I'm trying to install the finished setup file, I'm getting this error message:
Error 1001. Unable to get installed types in the "Path" assembly. -->
Unable to load one or more of the requested types. Retrieve the
LoaderExceptions property for more information.
I have been searching for answers for over 4 hours now without finding anything. This problem just came without me doing anything. Last time I build the install file was like 2 weeks ago and there was NO problem at all. I haven't deleted any reference or any code that have anything to do with the setup project.
How could this problem appear from nothing and more important, how do I fix it?
Based on the error message in your second comment, it appears that your SysDir.exe assembly has been added as a Custom Action with the InstallerClass property set to true, but either no installer classes could be found in the exe or the exe could not be loaded due to missing dependencies.
You can see the list of Custom Actions by right-clicking on the installer project, selecting View and then Custom Actions.
If your exe does not can an installer class, then you can remove it from the list of custom actions.
If it does contain an installer class, then the issue is going to be missing dependencies. If fuslogvw doesn't work for you (it has always helped resolve this kind of issue for us), you can carefully review the list of references in the exe's project and compare them to what is listed in the installer project.
The other trick that we use is to examine the install directory while the error message is displayed on the screen. We can often see that DLLs are missing by doing this, usually because the path was entered incorrectly in the DLL entry within the installer project or because a condition was set incorrectly.
Have the same error today. For me it was the project type of the class library.
I noticed that the pucture on the guide I was following had selected Class Library (.NET Framework) instead of just Class Library.
Creating the correct project type fixed the error.
https://nhvu1988.com/posts/how-to-create-msi-installer-using-vs-installer/

Categories

Resources