(Android) Xamarin Forms shell app crash after latest Xamarin update - xamarin.forms

So I have a Xamarin Forms Shell App, with Shellcontents set as like this:
<Shell etc etc>
<ShellContent ContentTemplate="Temp1" Route="routeA" Title="titleA" />
<ShellContent ContentTemplate="Temp2" Route="routeB" Title="titleB" />
<MenuItem Text="{x:Static rx:AppResources.Logout}" Command="{Binding LogoutCommand}"/>
</Shell>
When launched, ShellContent A shows up all good. But the moment I touch titleB, I get this stupid error.
I have not been able to figure it out, where is this error coming from. Any ideas where should I look?
No package ID ff found for ID 0xffffffff.
[AndroidRuntime] Shutting down VM
[AndroidRuntime] FATAL EXCEPTION: main
[AndroidRuntime] android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff
[AndroidRuntime] at android.content.res.ResourcesImpl.getResourceTypeName(ResourcesImpl.java:334)
[AndroidRuntime] at android.content.res.Resources.getResourceTypeName(Resources.java:2300)
[AndroidRuntime] at androidx.fragment.app.FragmentAnim.loadAnimation(FragmentAnim.java:79)
[AndroidRuntime] at androidx.fragment.app.DefaultSpecialEffectsController$AnimationInfo.getAnimation(DefaultSpecialEffectsController.java:774)
[AndroidRuntime] at androidx.fragment.app.DefaultSpecialEffectsController.startAnimations(DefaultSpecialEffectsController.java:144)
[AndroidRuntime] at androidx.fragment.app.DefaultSpecialEffectsController.executeOperations(DefaultSpecialEffectsController.java:120)
[AndroidRuntime] at androidx.fragment.app.SpecialEffectsController.executePendingOperations(SpecialEffectsController.java:294)
[AndroidRuntime] at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2190)
[AndroidRuntime] at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2088)
[AndroidRuntime] at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1990)
[AndroidRuntime] at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
[AndroidRuntime] at android.os.Handler.handleCallback(Handler.java:938)
[AndroidRuntime] at androidx.fragment.app.DefaultSpecialEffectsController.startAnimations(DefaultSpecialEffectsControlleer.dispatchMessage(Handler.java:99)
[AndroidRuntime] at android.os.Looper.loop(Looper.java:246)
[AndroidRuntime] at android.app.ActivityThread.main(ActivityThread.java:8430)
[AndroidRuntime] at java.lang.reflect.Method.invoke(Native Method)
[AndroidRuntime] at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)
[AndroidRuntime] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

I do not have the Temp1 and Temp2. I create a Shell tenplate to test. It works on myside. You could check the code below.
Xaml:
<ShellContent
Title="titleA"
ContentTemplate="{DataTemplate local:ItemsPage}"
Route="routeA" />
<ShellContent
Title="titleB"
ContentTemplate="{DataTemplate local:AboutPage}"
Route="routeB" />
<MenuItem Command="{Binding LogoutCommand}" Text="Page1" />
Code hebind:
public partial class AppShell : Xamarin.Forms.Shell
{
public ICommand LogoutCommand => new Command(async () => await Shell.Current.GoToAsync("page1"));
public AppShell()
{
InitializeComponent();
Routing.RegisterRoute("page1", typeof(Page1));
this.BindingContext = this;
}
}

I was able to correct this bug when I downgraded Xamarin.Google.Android.Material to v1.2.1.1 following a tip from here:
https://github.com/xamarin/Xamarin.Forms/issues/13843

Related

Set default tab on Xamarin Forms Shell

How to set the default selected Tab inside the tab bar on Xamarin forms shell?
<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestApp.NavigationShell"
xmlns:pages="clr-namespace:TestApp.Pages"
xmlns:pageModels="clr-namespace:TestApp.PageModels">
<TabBar Route="testapp">
<Tab Title="Saved" Icon="tabDashboard" Route="dashboard"><ShellContent ContentTemplate="{DataTemplate pages:DashBoardPage}"/></Tab>
<Tab Title="Calendar" Icon="tabCalendar" Route="calendar"><ShellContent ContentTemplate="{DataTemplate pages:CalendarPage}"/></Tab>
<Tab Title="Search" Icon="tabSearch" Route="search"><ShellContent ContentTemplate="{DataTemplate pages:SearchPage}"/></Tab>
<Tab Title="Support" Icon="tabSupport" Route="support"><ShellContent ContentTemplate="{DataTemplate pages:SupportPage}"/></Tab>
<Tab Title="Profile" Icon="tabAccount" Route="account"><ShellContent ContentTemplate="{DataTemplate pages:AccountPage}"/></Tab>
</TabBar>
According to the Xamarin Forms documentation, the first Shell Content will be the default content on the screen. However; I'm trying to set the "Search" page as the default tab rather than "Saved".
I tried to set Tab Index - no luck
I also tried to call routing on onAppearing method of Shell but seems like Shell's on appearing method never gets fired.
I tried to navigate to Search as well:
public partial class NavigationShell : Shell
{
public NavigationShell()
{
InitializeComponent();
//Shell.Current.TabIndex = 2;
}
protected override async void OnAppearing()
{
base.OnAppearing();
//await Shell.Current.GoToAsync("testapp/search");
}
}
What could be the best solution that when app opens need to set the default tab?
Thank you.
Here, how I fix it by using the Name field attribute.
I assigned the name to the TabBar and the tab which I want to assign in the first place.
AppShell.xaml
<TabBar x:Name="main_tab_bar" Route="main">
<Tab Title="History">
<Tab.Icon>
<FontImageSource FontFamily="MaterialIconsRegular" Glyph="{x:Static Emojis:MaterialRegFont.List}"/>
</Tab.Icon>
<ShellContent ContentTemplate="{DataTemplate Views:CallLogPage}" />
</Tab>
<Tab x:Name="main_tab_bar_dial" Title="Dial" >
<Tab.Icon>
<FontImageSource FontFamily="MaterialIconsRegular" Glyph="{x:Static Emojis:MaterialRegFont.Dialpad}"/>
</Tab.Icon>
<ShellContent ContentTemplate="{DataTemplate Views:MainDialerPage}" />
</Tab>
<Tab Title="Settings">
<Tab.Icon>
<FontImageSource FontFamily="MaterialIconsRegular" Glyph="{x:Static Emojis:MaterialRegFont.Settings}"/>
</Tab.Icon>
<ShellContent ContentTemplate="{DataTemplate Views:MainSettingsPage}" />
</Tab>
</TabBar>
AppShell.cs
public AppShell() {
InitializeComponent();
Init();
}
private void Init() {
main_tab_bar.CurrentItem = main_tab_bar_dial;
}
Nevermind, I think I found a solution.
public Page Init(Shell root)
{
CurrentShell = root;
root.CurrentItem.CurrentItem = root.CurrentItem.Items[2];
return CurrentShell;
}
Becase my shell have ONLY one root item which is tabbar itself. I just get the search tab and assigned to the first child's current item and it worked.
Please post your answers if you found another way around.
Thank you.
On the constructor of your Shell class you can set the CurrentItem
in my case I have an <ShellItem> with some <tab>
public PrivateShell()
{
InitializeComponent();
this.CurrentItem.CurrentItem = homeTab; //tab defined by x:Name on XAML
}
As far as I could check it does not pre-render the first shellcontent in case you're using ContentTemplate pattern

Creating UWP app package results in errors

When I attempt to create a release UWP package for side loading I get the following error :-
1>C:\Program Files
(x86)\MSBuild\Microsoft.NetNative\x64\ilc\IlcInternals.targets(936,5):
error : System.NullReferenceException: Object reference not set to an
instance of an object. 1>C:\Program Files
(x86)\MSBuild\Microsoft.NetNative\x64\ilc\IlcInternals.targets(936,5):
error : at
System.Xml.Serialization.XmlSerializationWriterCodeGen.FindXmlnsIndex(MemberMapping[]
members) 1>C:\Program Files
(x86)\MSBuild\Microsoft.NetNative\x64\ilc\IlcInternals.targets(936,5):
error : at
System.Xml.Serialization.XmlSerializationWriterCodeGen.WriteStructMethod(StructMapping
mapping) 1>C:\Program Files
(x86)\MSBuild\Microsoft.NetNative\x64\ilc\IlcInternals.targets(936,5):
error : at
System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateMethod(TypeMapping
mapping) 1>C:\Program Files
(x86)\MSBuild\Microsoft.NetNative\x64\ilc\IlcInternals.targets(936,5):
error : at
System.Xml.Serialization.XmlSerializationCodeGen.GenerateReferencedMethods()
1>C:\Program Files
(x86)\MSBuild\Microsoft.NetNative\x64\ilc\IlcInternals.targets(936,5):
error : at
System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateEnd()
1>C:\Program Files
(x86)\MSBuild\Microsoft.NetNative\x64\ilc\IlcInternals.targets(936,5):
error : at
System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[]
xmlMappings, Type[] types, String defaultNamespace, Evidence evidence,
XmlSerializerCompilerParameters parameters, Hashtable assemblies,
String outputDir, IEnumerable1 referenceDirectories, String
intermediateDir, Boolean loadAssembly) 1>C:\Program Files
(x86)\MSBuild\Microsoft\.NetNative\x64\ilc\IlcInternals.targets(936,5):
error : at
System.Xml.Serialization.XmlSerializer.GenerateSerializer(Type[]
types, XmlMapping[] mappings, CompilerParameters parameters, String
outputDir, IEnumerable1 referenceDirectories, String intermediateDir,
Boolean loadAssembly) 1>C:\Program Files
(x86)\MSBuild\Microsoft.NetNative\x64\ilc\IlcInternals.targets(936,5):
error : at
System.Xml.Serialization.XmlSerializer.GenerateSerializer(Type[]
types, String outputDir, IEnumerable1 referenceDirectories, String
intermediateDir, List1 wcfSerializers, Boolean loadAssembly)
1>C:\Program Files
(x86)\MSBuild\Microsoft.NetNative\x64\ilc\IlcInternals.targets(936,5):
error : at SerializationAssemblyGenerator.Program.Main(String[]
args) 1>C:\Program Files
(x86)\MSBuild\Microsoft.NetNative\x64\ilc\IlcInternals.targets(936,5):
error : Internal compiler error: One or more errors occurred.
My .appxmanifest file looks like:
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
<Identity Name="XXXXXXXXXX" Publisher="XXXXXXXXXX" Version="1.0.4.0" />
<mp:PhoneIdentity PhoneProductId="XXXXXXXXXX" PhonePublisherId="XXXXXXXXXX" />
<Properties>
<DisplayName>XXXXXXXXXX</DisplayName>
<PublisherDisplayName>XXXXXXXXXX</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="XXXXXXXXXX.App">
<uap:VisualElements DisplayName="XXXXXXXXXX" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="XXXXXXXXXX" BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
</uap:DefaultTile>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<uap:Capability Name="phoneCall" />
<uap:Capability Name="picturesLibrary" />
<uap:Capability Name="userAccountInformation" />
<DeviceCapability Name="location" />
<DeviceCapability Name="proximity" />
<DeviceCapability Name="webcam" />
</Capabilities>
</Package>
Does anyone have any ideas why this happens?

NoSuchRendererException: Cannot find a renderer named 'freemarker'

I'm trying to make an application that uses Tiles, Spring, and FreeMarker together. I have the project working with just Tiles and Spring but when I try to use ftl files in my Tiles template I get the error
org.apache.tiles.request.render.NoSuchRendererException: Cannot find a renderer named 'freemarker'
at org.apache.tiles.request.render.BasicRendererFactory.getRenderer(BasicRendererFactory.java:57)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:252)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:397)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:238)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:221)
at org.apache.tiles.renderer.DefinitionRenderer.render(DefinitionRenderer.java:59)
at org.springframework.web.servlet.view.tiles3.TilesView.renderMergedOutputModel(TilesView.java:132)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:745)
This is what my tiles template looks like
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<!-- Default Main Template -->
<definition name=".mainTemplate" template="/templates_ftl/main.ftl" templateType="freemarker">
<put-attribute name="title" value="Permissions Editor" type="string" />
<put-attribute name="footer" value="/templates_ftl/footer.ftl" type="freemarker" />
<put-attribute name="body" value="/templates_ftl/blank.ftl" type="freemarker" />
</definition>
<definition name="login" extends=".mainTemplate">
</definition>
</tiles-definitions>
This is just a small example I'm working on to get FreeMarker working so I can use it with the rest of my project. Here is the controller.
#RequestMapping(value = "/")
public String login(#ModelAttribute("LoginInfo") LoginInfo info, HttpServletRequest request) {
logger.info("First visit to login page");
if (HttpUtility.getInstance().compareSession(request)) {
logger.info("Leaving initial login page with user already logged in, sending to show_roles page");
return "show_roles";
}
logger.info("Leaving initial login page sending to login submit");
return "login";
}
I solved it by adding
<#assign tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"]>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
to the top of my ftl files

Log4net not working in IIS7 on windows server 2008

Logs are not created on the server (Windows 2008) and IIS7. I had given absolute path as well as relative path.
I had given all rights to the log folder. I had included network user, IUsr and IIS_IUSRS, and gave permission to every one. also.
It is not writing logs to that folder
the entries on the web config is as follows
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
<log4net>
<logger name="GeneralLogger">
<level value="ALL" />
<appender-ref ref="RollingFile" />
</logger>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="C:\\vhosts\\staging.customerportal.com\\log\\CustomerPortal.log"/>
<appendToFile value="true"/>
<datePattern value="yyyyMMdd"/>
<rollingStyle value="Date"/>
<filter type="log4net.Filter.LevelRangeFilter">
<acceptOnMatch value="true"/>
<levelMin value="DEBUG"/>
<levelMax value="FATAL"/>
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %X{addr} %-22.22c{1} %-18.18M - %m%n"/>
</layout>
</appender>
</log4net>
I had tried giving single slash and well as double slash in the file value in web config nothing works.
The code in the global.asax.cs is
public class MvcApplication : System.Web.HttpApplication
{
private static log4net.ILog log = log4net.LogManager.GetLogger(typeof(MvcApplication));
protected void Application_Start()
{
log4net.Config.XmlConfigurator.Configure();
}
code in assemblyinfo.cs is
[assembly: XmlConfigurator(ConfigFile="web.config", Watch=true)]
I had tried with this code and also without this code in assemblyinfo.cs
It is not working.
Where as When I use absolute path in localhost the logs are written to that folder properly
It fails on the server
I had tried both these options in the controller file
//private static log4net.ILog log =
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType) ;
private static log4net.ILog log = log4net.LogManager.GetLogger("GeneralLogger");
I had tried a path which does not exists, it did not created folder.
Please help me. Please help me how to enable logs using log4net in server
You are initializing your logger before configuring the logmanager (actually you configuring it twice) by calling the Configure on Application_Start.
Option 1:
public class MvcApplication : System.Web.HttpApplication
{
private static log4net.ILog log = log4net.LogManager.GetLogger(typeof(MvcApplication));
protected void Application_Start()
{
//Remove: log4net.Config.XmlConfigurator.Configure();
}
And keep:
[assembly: XmlConfigurator(ConfigFile="web.config", Watch=true)]
Option 2:
public class MvcApplication : System.Web.HttpApplication
{
private static log4net.ILog log;
protected void Application_Start()
{
log4net.Config.XmlConfigurator.Configure();
log = log4net.LogManager.GetLogger(typeof(MvcApplication));
}
And remove:
//Remove: [assembly: XmlConfigurator(ConfigFile="web.config", Watch=true)]

Log4net in a web service

I basically have the same question as
log4net only works when XmlConfigurator.Configure() is called
However, I couldn't comment there as I don't have any reputation (just signed up).
Thanks for any helpful comments.
If I do anything wrong here, please advise.
Thank you very much. Bernd
Update:
Thanks for constructive hints. I've have made some progress and therefore will explain in more detail:
I use log4net within a (VS generated C# web service). I do get the debug information in the debug file, however within VS (2012) I do get the message for every logging call:
log4net:ERROR An exception ocurred while retreiving stack frame information.
System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei log4net.Core.StackFrameItem..ctor(StackFrame frame)
I configured it via XML:
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="Logs/debug.log" />
<encoding value="utf-8" />
<appendToFile value="true" />
<maximumFileSize value="10MB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level (%class#%method:%line):%message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFile" />
</root>
</log4net>
My web service looks like this:
public class ObjectInfo : IObjectInfo
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void DoWork() {
Logging.LoggingUtil.InitializeLogging();
log.Debug("Some message");
}
}
Hope this is quite sufficient. The LoggingUtil- class basically looks like this:
private const String Log4NetConfigurationFilePath = "log4net-config.xml"; //real path looks somewhat different
public static void InitializeLogging()
{
XmlConfigurator.Configure(new FileInfo(Log4NetConfigurationFilePath));
}
I wonder, if the problem is that the stack trace cannot be found out within Cassine as Microsoft doesn't allow this in order to protect their implementation of the web service?
As explained in LOG4NET-393, this error occurs when there is a dynamic method in the call chain.
There they claim to have this error fixed in versions > 1.2.12.

Resources