I created cross platform project for android having dependencies xamarin.essentials\1.5.3.2 and xamarin.forms\4.8.0.1451 (the defaults) with tabbed layout. Then I added TestMasterDetailPage using MasterDetailPage template. AppShell.xaml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MasterDetailTest.Views"
Title="MasterDetailTest"
x:Class="MasterDetailTest.AppShell">
<TabBar>
<ShellContent Title="About" Icon="icon_about.png" Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}" />
<ShellContent Title="Browse" Icon="icon_feed.png" ContentTemplate="{DataTemplate local:ItemsPage}" />
<ShellContent Title="TestMasterDetailPage" Route="TestMasterDetailPage" ContentTemplate="{DataTemplate local:TestMasterDetailPage}" />
</TabBar>
</Shell>
I removed some unused code and added 3rd tab in TabBar. When launching it and pressing on new tab I get error in external code: System.InvalidCastException: 'Specified cast is not valid.'
I found this question which looks identical, however it's 2yo and I'm not sure if shell was used for template at that time. Also, like mentioned before, crash happens somewhere in external code.
Related
I am trying to connect my webcam from my cell phone through xamarin, however, it is not working, when using my front camera and my back camera it works, however when I use CameraOptions = "External" it does not detect the webcam This is my code with which I create the camera view:
<xct:CameraView
Grid.Column="0"
x:Name="cameraView"
CaptureMode="Photo"
CameraOptions="External"
FlashMode="Off"
HorizontalOptions="FillAndExpand"
MediaCaptured="CameraView_MediaCaptured"
OnAvailable="CameraView_OnAvailable"
VerticalOptions="FillAndExpand" />
In my main activity I defined this intent filter and this meta data for the detection of usb devices:
[IntentFilter(new[] { Android.Hardware.Usb.UsbManager.ActionUsbDeviceAttached })]
[MetaData(name: "Android.Hardware.Usb.UsbManager.ActionUsbDeviceAttached", Resource = "#xml/device_filter")]
In the application path Android \ Resources I defined a folder called xml where I created a file called device_filter.xml to be able to define the properties of my camera
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<usb-device vendor-id="2431" product-id="4653" class="33" subclass="33" protocol="1"/>
</resources>
Also in the BuildAction property of device_filter.xml I defined as parameter AndroidResource
And request the camera permissions and record audio:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
What could I do to make it detect my webcam?
I have a WPF desktop application that I have packaged into an MSIX package. In the package manifest I have defined a windows.protocol extension to launch the main executable when a specific protocol is used. This protocol activation works fine when I install using the MSIX package directly.
The application should be auto-updating, so I created a .appinstaller file that references the MSIX. That also works well, but when the application is installed using the .appinstaller file, the protocol activation does not work. In fact Windows prompt for an application when the custom protocol is used. I have not changed the MSIX package in any way, just referenced it. The MSIX package is signed using a valid bought signing certificate.
The protocol in question provides deep links into the application that users can share using email.
For the moment I have to choose to either have protocol activation (install the MSIX directly) or auto-updating (install using the .appinstaller file), but I can't get both to work.
appmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap uap3 rescap">
<Identity
Name="MyApp"
Publisher="CN=CompanyName, O=CompanyName, L=City, S=Province, C=BE"
Version="1.0.0.0"
ProcessorArchitecture="x64"/>
<Properties>
<DisplayName>MyApp</DisplayName>
<PublisherDisplayName>CompanyName</PublisherDisplayName>
<Logo>Images\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="MSIXCore.Desktop" MinVersion="6.1.7601.0" MaxVersionTested="10.0.10240.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.18362.0" />
</Dependencies>
<Resources>
<Resource Language="en-us"/>
</Resources>
<Applications>
<Application Id="App"
Executable="MyApp\MyApp.exe"
EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements
DisplayName="MyApp"
Description="MyApp"
BackgroundColor="transparent"
Square150x150Logo="Images\Square150x150Logo.png"
Square44x44Logo="Images\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" />
<uap:SplashScreen Image="Images\SplashScreen.png" />
</uap:VisualElements>
<Extensions>
<uap3:Extension Category="windows.protocol">
<uap3:Protocol Name="myprotocol" Parameters="-s "%1"">
<uap:DisplayName>MyProtocol Scheme</uap:DisplayName>
</uap3:Protocol>
</uap3:Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust" />
<Capability Name="privateNetworkClientServer"/>
<uap:Capability Name="userAccountInformation"/>
</Capabilities>
</Package>
myapp.appinstaller
<?xml version="1.0" encoding="utf-8"?>
<AppInstaller Uri="\\someserver\someshare\myapp.appinstaller" Version="1.0.0.0" xmlns="http://schemas.microsoft.com/appx/appinstaller/2018">
<MainPackage Name="MyApp" Version="1.0.0.0" Publisher="CN=CompanyName, O=CompanyName, L=City, S=Province, C=BE" ProcessorArchitecture="x64" Uri="\\someserver\someshare\myapp.msix" />
<UpdateSettings>
<OnLaunch HoursBetweenUpdateChecks="0" ShowPrompt="true" UpdateBlocksActivation="true"/>
<AutomaticBackgroundTask/>
</UpdateSettings>
</AppInstaller>
I am trying to use Visual studio project template for desktop bridge to add to wpf app and it will not build successfully and shows this strange warning that i have attached.
warning when building desktop bridge project template
i had followed this post on official documentation :
https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-packaging-dot-net
and before that i had used this blog post to add winmd and runtime to my project:
https://blogs.windows.com/buildingapps/2017/01/25/calling-windows-10-apis-desktop-application/
and here is the code form Package.appxmanifest file:
<?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" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10" IgnorableNamespaces="uap mp rescap iot">
<Identity Name="09b95fbd-84cc-426f-9fd2-2c1d3d304fab" Publisher="CN=SO-PC-005" Version="1.0.0.0" />
<Properties>
<DisplayName>WapProjTemplate</DisplayName>
<PublisherDisplayName>SO-PC-005</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
<uap:VisualElements DisplayName="WapProjTemplate" Description="WapProjTemplate" BackgroundColor="transparent" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
</uap:DefaultTile>
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<iot:Capability Name="systemManagement" />
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>
I also would like to mention that i am trying to use windows.graphics.display for brightness override in a wpf app and it requires systemManagement capapbility. And also that my project builds successfully without packaging project but when I add packaging project to my wpf solution it will not build.
I am new to using NLog with ASP.NET Core, so I have followed the guide here:
https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-(project.json)
I have created the following nlog.config file at the root of the project directory:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Warn"
internalLogFile="c:\temp\internal-nlog.txt">
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
<!-- define various log targets -->
<targets>
<!-- write logs to file -->
<target xsi:type="File" name="allfile" fileName="${basedir}\nlog-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}|${message} ${exception}" />
<target xsi:type="File" name="ownFile-web" fileName="${basedir}\nlog-own-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}| ${message} ${exception}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
<target xsi:type="Null" name="blackhole" />
</targets>
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="allfile" />
<!--Skip Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" />
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
</rules>
</nlog>
Inside a controller, I call a line like this one:
_logger.LogInformation("Entered CustomerRange method");
which returns the following in the output window in Visual Studio:
CustomerMgmtAPI.Controllers.CustomerController:Information: Entered CustomerRange method
However, the actual log files are never created by NLog. I was wondering if someone can point out the error in the NLog configuration here, since I have been reviewing the documentation of NLog for ASP.NET Core project and I can't find the error myself.
So the actual fix to the problem was the remove the first line from the nlog.config file:
<?xml version="1.0" encoding="utf-8" ?>
I remove this line and everything started working as expected. I also noticed that Visual Studio was giving me these errors when that line was present:
Invalid token 'Text' at root level of document.
Unexpected XML declaration. The XML declaration must be the first node in the document and no white space characters are allowed to appear before it.
It seems in this case that the NLog tutorial is broken, as I just took over this file from the sample for ASP.NET Core. I am using VS2017, so perhaps there is an incompatibility with this version of VS?
The dirty little secret about using NLog with ASP.NET Core is that you can configure and create logs just as you did in ASP.NET and ASP.NET MVC. You just use the regular NLog Nuget package like you normally would.
Just create an NLog.config in your root, etc. You don't even have to make any extra configurations in the config or elsewhere to get it to work. You just reference NLog in your class and then create a logger with the LogManager.
What this means is that you don't have all of the wireup in Program.cs etc.
I'm using Visual Studio 2017 RC. I started to use it because deploying an Android app with Visual Studio 2015 was frustrating.
I premise my app was working fine. In a page I use a style for a BoxView. The style is define in the App.xaml as:
<?xml version="1.0" encoding="UTF-8" ?>
<Application
x:Class="myApp.App"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<Application.Resources>
<ResourceDictionary>
<Style x:Key="WarmGreyLine" TargetType="BoxView">
<Setter Property="HeightRequest" Value="2" />
<Setter Property="HorizontalOptions" Value="Fill" />
<Setter Property="Color" Value="#EEE9E5" />
<Setter Property="Margin" Value="0,10,0,10" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
and in a XAML page I call this style (for two boxview) as
<BoxView Style="{StaticResource WarmGreyLine}" />
With this line the app goes in error as following image:
Is this a bug or my fault? Thanks in advance