Xamarin.Forms iOS crash on XAML pages with custom controls - c#

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.

Related

Could not load the nibName issue (xamarin)

We start to prepare project with generic solution for few apps using Xamarin studio (the idea is to let all our apps use same "Core" components).
We started from preparing general "Core" with base functionality. Also we add "subCore" - libraries with functionality specific to each platform (iOS, android, windows etc).
Currently setup such structure for Android and iOS.
During second step of implementation for macOS, we faced with few blocking points.
The problem appear when we try to configure (in way described above) structure for macOS platform.
I was able to create macOS class Library with components that should be reused in apps (for now this is just 1 class with xib file). But, when I want to use this package (with xib inside) in macOS target, got exception:
External Modification Warnings: Debugger attached to process.
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[NSNib
_initWithNibNamed:bundle:options:] could not load the nibName: MainViewController in bundle (null).' terminating with uncaught
exception of type NSException abort() called
After some investigating, found that Mac Build server is not converting xibs into nibs, so this nib file is just missing in package created by Xamarin.
Additional testing info, based on proposed solutions found in Xamarin forum:
rename, recreate, reposition of xib file in project - not resolve the issue
recreate project - not resolve the issue
check Build action in property is set to InterfaceDefinition (also check all other possible variants) - not resolve the issue
I found this post, with root cause exactly as I have:
Mac Build server is not converting xibs into nibs.
According to discussion on this post, issue should be fixed, but I still faced with this.
Can some one advice how to fix described problem?
To anyone who faced same issue, please install
xamarin.ios-10.13.0.27.pkg
and
xamarin.mac-3.7.0.27.pkg
This build include fix for described problem.
For more, visit this page.

Newly created xamarin solution getting errors on xamarin.forms and application inherited type

Every time I create a new solution in vs2017, I get errors on the using Xamarin.Forms directive and also on the app.axml.cs class definition when Application is inherited (which causes errors on the On methods), see image.
Is there a way of modifying the way vs configures solutions upon creation.
![Xamarin Errors](https://drive.google.com/drive/my-drive/xamarin errors.jpg)
I did a repair on the IDE, and everything is working now. I wish this version of studio was more stable. All I did was create a new cross platform solution and the errors were present. I could open a solution I had already worked on and it works fine. Go figure!

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

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.

Runtime error referencing VBA assembly from C#

I have a C# .NET 3.5 project that unfortunately relies on a couple of VB6 ActiveX controls.
Up until now I have been able to happily access the data containers and methods defined in the ActiveX controls by simply adding a reference to the controls in my project and referencing them as normal.
However I hit a snag today when I had to call a method that returns a VBA.Collection.
My code will compile with no problem, but at runtime I get the following error:
Could not load file or assembly 'Interop.VBA, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
I have references to Interop.VBA (version 6.0.0.0) and Interop.VBRUN (version 6.0.0.0) in my project, any thoughts?
I can't give specific code, it is covered under an NDA.
However, here is sample code from object browser with names changed to protect the not so innocent ;)
I can reference the following properties and methods from my code:
ReturnConstants GoodMethod();
string prop1
ReturnConstants prop2
If I try can call this method I get the error message above at runtime:
Collection BadMethod();
So it the call to the method that returns a VBA.Collection that causes the issue.
These are 3rd party controls that I have no control over and they will not be rewritten in .net
edit: Out of interest I went and tried a quick dummy project in VS2010 and worked perfectly as expected, so it appears that this may be an issue with VS2012. I've seen some posts that hint at 2012 not creating interops for VBA correctly, so I'll go see what I can find there ...
Thanks to #Jeremy Thompson for putting me on the right track, running process monitor showed me that my application was unable to locate the interop.VBA.dll file, once that was fixed everything works as expected. No idea why this works out of the box on 2010 and not 2012, but happy to have a solution

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