Xamarin Forms - webkit in a content page - xamarin.forms

I'm trying to display a page in a Xamarin.Forms content page. I have the webview setup on a Xaml page.
My Xaml page is literally just a WebView. I can't paste it in because its getting caught in the editor.
My .cs file looks like:
iHud hud;
Int64 _TournamentId;
public Scoreboard(Int64 TournamentId)
{
InitializeComponent();
_TournamentId = TournamentId;
hud = DependencyService.Get<iHud>();
}
protected async override void OnAppearing()
{
base.OnAppearing();
if (String.IsNullOrEmpty(Convert.ToString(wv.Source)))
{
hud.Show();
var sUrl = await MobileSupport.ws.ScorecardScoreboardAsync(_TournamentId); // this returns the url that I need to load.
hud.Dismiss();
Device.BeginInvokeOnMainThread(() =>
{
wv.Source = sUrl.Uri;
});
}
}
private void wv_Navigated(object sender, WebNavigatedEventArgs e)
{
hud.Dismiss();
}
private void wv_Navigating(object sender, WebNavigatingEventArgs e)
{
hud.Show();
}
My first error occurs when I try to load the web content the first time:
2020-11-30 13:14:09.000519-0500 Scorecards.iOS[33822:2847938] SecTaskLoadEntitlements failed error=22 cs_flags=200, pid=33822
2020-11-30 13:14:09.000842-0500 Scorecards.iOS[33822:2847938] SecTaskCopyDebugDescription: Scorecards.iOS[33822]/0#-1 LF=0
2020-11-30 13:14:09.043613-0500 Scorecards.iOS[33822:2847141] [unspecified] container_system_group_path_for_identifier: error = ((container_error_t)98) NOT_CODESIGNED
2020-11-30 13:14:09.043748-0500 Scorecards.iOS[33822:2847141] [MC] Error getting system group container for systemgroup.com.apple.configurationprofiles: 98
2020-11-30 13:14:09.043968-0500 Scorecards.iOS[33822:2847141] [MC] Failed to get profile system group container path. Overriding with expected path: /Users/wallym/Library/Developer/CoreSimulator/Devices/EF5F2DBD-1B4F-4DEC-88C2-A4D5F94D0406/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
The next time that I try to load the scoreboard, I get this error:
2020-11-30 13:14:12.947337-0500 Scorecards.iOS[33822:2847141] [Process] 0x7ffa1cc49a20 - [pageProxyID=6, webPageID=7, PID=33840] WebPageProxy::processDidBecomeUnresponsive:
2020-11-30 13:37:23.995271-0500 Scorecards.iOS[33822:2847141] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}>
2020-11-30 13:37:23.995461-0500 Scorecards.iOS[33822:2847141] [ProcessSuspension] 0x11ccfebc0 - ProcessAssertion: Failed to acquire RBS Background assertion 'WebProcess Background Assertion' for process with PID 33840, error: Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}
The one thing that I want to mention is that I am returning a url that will then redirect the web browser to the appropriate place. The url is secure. It is on azure.
https://wallytest.azurewebsites.net/PublicScores/ScoreboardRouter?TournamentId=5.
I've tried just about every dumb trick that I can think of to get this to display in a WebView, and it won't. There is a request for geolocation that comes up sometimes in the webview, so I know that something is working. Please don't mention the 404, that is after the page is loaded.
Any suggestions on getting this page to display are appreciated.
TIA

I am still not sure why this issue is occurring. However, I played with how I am loading up the web browser. I decided to play with the Xamarin Essentials Browser.OpenAsync(url); method. It works perfectly. Content loads, and I think it is ok. I have to figure out how to display the hud during the load, but the content itself loads, which is good.
I'm putting the comment in here to provide an alternative option for future readers.

Related

Cancel Navigating event in Xamarin Forms webview

I'm trying to open tel links in my xamarin forms application webview using the Navigating event:
public async void WebViewNavigating(object sender, WebNavigatedEventArgs args)
{
if (args.Url.StartsWith("tel:"))
{
await Xamarin.Essentials.Launcher.OpenAsync(args.Url);
}
}
But I have two issues, first on IOS it gives an error 500 and next in Android as the navigation is not cancelled, I have a not found error and going back to the app after the call.
I read that args.cancel=true is the way to go but the variable doesn't seem to exist no more.
At first, you can use the Xamarin.Essentials: Phone Dialer to open the telephone number. Furthermore you need to test on the physical device for the ios, because the ios simulator can't call number and will throw an exception.
Open the AndroidManifest.xml file under the Properties folder and add the following inside of the manifest node:
<queries>
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel"/>
</intent>
</queries>
Use the following code:
public void WebViewNavigating(object sender, WebNavigatingEventArgs args)
{
if (args.Url.StartsWith("tel:"))
{
string number = args.Url.Split(':')[1];
Xamarin.Essentials.PhoneDialer.Open(number);
args.Cancel = true;
}
}
In adition, you can also use the custom renderer to do that, for more information, you can check my answer in this case.

Can't get access to the Events in Visual Studio Community Toolkit

I'm trying to migrate my old Visual Studio extension to the new 2022 Studio. Found some fancy solution named 'Community Visual Studio Toolkit', but got some issues. When I use the ProvideAutoLoad attribute for loading my extension when a user opens some solution, I can't get access to the WindowEvents which I need to sign my event handlers. This is the error on debugging: https://snipboard.io/yUXIed.jpg
So this is the code I use, and here I have the error:
[ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
public sealed class MyPackage : ToolkitPackage
{
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await this.RegisterCommandsAsync();
VS.Events.WindowEvents.ActiveFrameChanged += WindowEvents_ActiveFrameChanged;
}
}
And the thing is my old implementation works with this code:
[ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
public sealed class MyPackage : ToolkitPackage
{
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await this.RegisterCommandsAsync();
// Getting `DTE2 dte` trough standard way...
dte.Events.WindowEvents.WindowActivated += WindowEvents_WindowActivated;
}
}
But I don't want to use old kinds of code in the new extension version, so, how to fix this issue in first example of implementation?
Well, I'm not sure about the "perfection" of this solution, but with this line of code added before access to the events - it works.
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
Seems like you have to be in main thread to access these events.

.NET Core Error 1053 the service did not respond to the start or control request in a timely fashion

I created a Windows Service starting from my .NET Core project following this
After this, I installed correctly it on my working machine and started it.
This is my service class:
using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading.Tasks;
namespace xxx
{
public class WindowsService
{
static void Main(string[] args)
{
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
using (var service = new Service())
{
ServiceBase.Run(service);
}
}
}
internal class Service : ServiceBase
{
public Service()
{
ServiceName = "...";
}
protected override void OnStart(string[] args)
{
try
{
base.OnStart(args);
Task.Run(() => xxxx);
}
catch (Exception ex)
{
EventLog.WriteEntry("Application", ex.ToString(), EventLogEntryType.Error);
}
}
protected override void OnStop()
{
base.OnStop();
}
protected override void OnPause()
{
base.OnPause();
}
}
}
So, I copied the file and installed it also on a server. Here, when I try to start it, I get:
After this, I start a lot of googling... for example, I tried the following steps :
Go to Start > Run > and type regedit
Navigate to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
With the control folder selected, right click in the pane on the right and - select new DWORD Value
Name the new DWORD: ServicesPipeTimeout
Right-click ServicesPipeTimeout, and then click Modify
Click Decimal, type '180000', and then click OK
Restart the computer
The weird point here is that the voice ServicesPipeTimeout didn't exist and I created it. Comparing the server with my working machine, there are also other value not present in the server. They are:
ServicesPipeTimeout
OsBootstatPath
Here the screenshot of regedit from the server:
Are these relevant?
I also tried to reinstall the service, recompile my files... how can I fix this problem? The error appears immediatly, it doesn't wait any timeout!
I had this problem when I switched my project to another location.
When I moved the project, I had copied the files in bin/debug folder too. The issue was resolved after I cleared the debug folder and created a new build.
See if this works!
It's a bit old question but someone may find this useful.
So I had the following code in Program.cs:
builder.SetBasePath(Environment.CurrentDirectory).AddJsonFile("appsettings.json")
Changed it to:
builder.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)).AddJsonFile("appsettings.json")
This seemed to fix the problem for me.
The problem with this error is that it is super generic.
Hopefully MS will give us some log in the future.
if you check the windows event viewer under applications it tells you what exactly is the exception that causes this error.
in my case the problem was i published the service in net6 and tried to run it on a pc with net7 installed. apparently it requires the exact major version that was used to publish the app.

Silverlight error while calling a service

I am trying to call a service from a silverlight application, but I am getting the following error.
Uncaught Error: Unhandled Error in Silverlight Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details.
This works fine locally. I don't know if it make any sense, but locally if I add the url of the webservice on a browser, I am getting the details page of the service. In the other hand, on production server, it prompts me to download it.
Does anyone know something about this?
Thanks
public MainPage() {
InitializeComponent();
Loaded += new System.Windows.RoutedEventHandler(MainPage_Loaded);
}
private void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e) {
var newsFeedWcfClient = new NewsFeedWCFClient();
newsFeedWcfClient.GetNewsFeedItemsCompleted += newsFeedWcfClient_GetNewsFeedItemsCompleted;
newsFeedWcfClient.GetNewsFeedItemsAsync();
}
void newsFeedWcfClient_GetNewsFeedItemsCompleted(object sender, GetNewsFeedItemsCompletedEventArgs e) {
var source = (IList<NewsFeed>)e.Result;
IList<CustomNewsFeed> customNewsFeeds = new List<CustomNewsFeed>();
foreach (var item in source) {
customNewsFeeds.Add(new CustomNewsFeed() {
ProductID = item.Products.ProductID,
ProductTitle = item.Products.Title,
Status = item.Text,
Thumb = string.Format("{0}/{1}", item.Products.Product_Photos.Select(pp => pp.PhotoPath).FirstOrDefault(), item.Products.Product_Photos.Select(pp => pp.PhotoName).FirstOrDefault()),
UserID = item.User.Id,
UserName = item.User.Username
});
}
NewsFeedLB.ItemsSource = customNewsFeeds;
}
The fact that on the production server it "prompts you to download" would suggest that the production web server doesn't know what to do with your .svc or .asmx file. It is treating it like a normal file (.txt, .pdf etc).
Have you got all of the required items installed in production. For instance, you need the correct .NET runtime to be installed. Also, ASP.NET needs to be installed and then enabled.
To determine exactly what is happening I would recommend installing Fiddler and using it to trace what is happening when the Silverlight app calls the server. I have found this approach to be invaluable when troubleshooting Silverlight to Web Service communication problems.

Handling report exceptions using the ASP.NET ReportViewer in Remote and Async mode

I have a report page that uses the Microsoft.Reporting.WebForms.ReportViewer component to render Report Server (SSRS) reports asynchronously. At the moment if an error occurs a message is displayed inside the ReportViewer control.
I want to add custom error handling logic so that the user gets a friendly message. How can I achieve this and still run the viewer in Async mode, rendering the reports on the SSRS server?
Listening to the ReportViewer.HandleError event won't work as the page postback has already completed.
After inspecting the ReportViewer JavaScript, I came up with the following solution. It's prone to breaking things if Microsoft changes this particular method. The following code would be added to the header of the page to make sure it runs after the ReportViewer javascript is loaded, but before an instance of the RSClientController is created.
// This replaces a method in the ReportViewer javascript. If Microsoft updates
// this particular method, it may cause problems, but that is unlikely to
// happen.The purpose of this is to redirect the user to the error page when
// an error occurs. The ReportViewer.ReportError event is not (always?) raised
// for Remote Async reports
function OnReportFrameLoaded() {
this.m_reportLoaded = true;
this.ShowWaitFrame(false);
if (this.IsAsync)
{
if(this.m_reportObject == null)
{
window.location =
'<%= HttpRuntime.AppDomainAppVirtualPath %>/Error.aspx';
}
else
{
this.m_reportObject.OnFrameVisible();
}
}
}
RSClientController.prototype.OnReportFrameLoaded = OnReportFrameLoaded;
The original code from the Microsoft ReportViewer script file (inside the Microsoft.ReportViewer.WebForms, 8.0.0.0, .Net Framework 3.5 SP1) is:
function OnReportFrameLoaded()
{
this.m_reportLoaded = true;
this.ShowWaitFrame(false);
if (this.IsAsync && this.m_reportObject != null)
this.m_reportObject.OnFrameVisible();
}
RSClientController.prototype.OnReportFrameLoaded = OnReportFrameLoaded;

Resources