Unable to log to console with Uno Platform / UWP Head - c#

How is (cross-platform) logging achieved with Uno? (to console, mainly)
I'm using Visual Studio, starting the UWP Head, and when i try to write something to the log, I'm expecting it to appear in Visual Studio Output windows / Uno Platform output, but nothing shows up there.
I'm using the following code (that i found in various repositories, as a supposed 'standard' way to log), in a UWP page 'code behind' code:
this.Log().LogInformation("My log");
but, as I said, nothing appears in the output windows.
The documentation says that to enable console logging you should use the following code:
Uno.Logging.LogManager.LoggerSelector = Uno.Logging.ConsoleLogger.Instance.GetLog;
Uno.Logging.ConsoleLogger.Instance.LogLevel = Uno.Logging.LogLevel.Warn;
Uno.Logging.ConsoleLogger.Instance.Filter = (level, name, message, exception) =>
{
// Provides a list of loggers that should be displayed to the console
var passList = new[] {
"Windows.UI.Xaml.VisualStateManager",
"Windows.UI.Xaml.VisualStateGroup",
"Windows.UI.Xaml.Controls.RadioButton",
};
return passList.Any(n => name.StartsWith(n))
? Uno.Logging.ConsoleLogger.FilterResult.Pass : Uno.Logging.ConsoleLogger.FilterResult.Ignore;
};
but the types Uno.Logging.LogManager and Uno.Logging.ConsoleLogger are not existent. Are they defined in additional libraries/nuGet packages? And where does this code should be placed?
EDIT:
This happens only with the UWP head. With the Wasm head, the log messages show correctly in browser's console, and with Android head (running in an emulator) they show up in Visual Studio's Output/Debug window. Can't try the iOS head, sorry.
Environment:
Visual Studio 2019 16.7.3
Uno.Core 2.0.0
Uno.UI 3.0.17
Uno.UI.RemoteControl 3.0.17
Uno.UI.WebAssembly 3.0.17
Uno.UniversalImageLoader 1.9.32
Uno.Wasm.Bootstrap 1.3.4
Uno.Wasm.Bootstrap.DevServer 1.3.4

When you are calling this.Log(), it will capture the fully qualified named of the this's type.
If you add the namespace of this type to the passList, it should work.
When you create a project using the template, you'll see a ConfigureFilters method in the App.xaml.cs file. Add you namespace there in the .WithFilter() call.
Example of such call here.

Related

Changing assemblyVersion adds version to Application.LoadComponent causing compile errors

I have a C# WPF application. It uses a small commercial framework (https://www.inosoft.com/en/product/product-features/).
I'm building this application both locally and via a buildserver (Azure pipelines). I use a marketplace task to change the assemblyinfo.cs before building: https://marketplace.visualstudio.com/items?itemName=bleddynrichards.Assembly-Info-Task
The build server executes the following tasks:
NuGet restore
Inject/Edit assemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion with the right version info
Build
Now when I run this application, it starts up and runs for a while.
Quickly after starting I hook the VS debugger into the process.
Then all of the sudden the application crashes:
This is weird, because when I build locally, this runtime error does not occur.
Note that i set all properties to the same values for testing:
AssemblyVersion: 1.2.3.4
AssemblyFileVersion: 5.6.7.8
AssemblyInformationalVersion: 9.10.11.12
I then use Telerik justAssembly to compare the build output from my local build and the buildserver:
As we can see the local output (on the left) does not have a version added to the Application.LoadComponent(..) whilst the build server output (on the right) does.
public void InitializeComponent()
{
if (!this._contentLoaded)
{
this._contentLoaded = true;
Application.LoadComponent(this, new Uri("/HmiMetis;component/views/app.xaml", UriKind.Relative));
}
}
This means that this is the root cause of the runtime exception.
I find it weird that the build process on my local machine differs from the build server output. Both (should) use visual studio 2017 to build. Why does the buildserver add the version to the uri of loadComponent and my local machine does not?
Anyways, I need this exception gone.
Therefore I think the easiest way would be to force the buildserver to not add the version information under any circumstances. Is this possible and how?
Edit:
I Found a relating issue report that may have something to do with this:
https://github.com/dotnet/core/issues/3189

Syncfusion Datagrid crashes Xamarin IOS application due to initiallising of control

I have a Xamarin application in which I have included the Syncfusion Datagrid control. I am trying to deploy this to an IOS simulator in visual studio. I have added the NuGet package and included a community license. However, it wasn't displaying on the screen. To fix this I added the following line of code, as advised by https://www.syncfusion.com/forums/137574/no-visible-data-grid-on-ios-platform-only.
Syncfusion.SfDataGrid.XForms.iOS.SfDataGridRenderer.Init();
However, this now results in my application crashing with the only debugger info being:
main.cs:
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, "AppDelegate"); #System.NullReferenceException: 'Object reference not set to an instance of an object'
}
AppDelegate.cs:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
Syncfusion.SfDataGrid.XForms.iOS.SfDataGridRenderer.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
If I haven't given you enough info about my setup please just ask and I will happily provide it. :)
Thanks in advance!
I don't know what the cause of the problem was, however, by downgrading my Xamarin.Forms and Xamarin.Essentials package to versions 4.5.0.495 and 1.3.1 respectively I no longer got the error and the screen was displayed properly.
I figured this out by making a new test project and trying to recreate my code. Then I tried running it and it worked. Thus I changed the versions of my original code to the versions that worked in the project that was generated by a Xamarin template.
Thanks everyone for their help :)
I too have experienced this same issue; after recent updates, my app crashed with a null exception on the main.cs in iOS. I finally isolated and resolved what was triggering the issue.
The problem occurred when I populated a SfDataGrid with more rows than could fit on a (cross platform, iOS) simulator screen; this would trigger a crash as soon as I tried to scroll vertically or horizontally. If the number of rows was less than the screen size, however, it didn't crash. The app also worked fine a week or so ago.
It turns out that there appears to be a bug in the latest release of Xamarin.Forms version 4.6.0.968. By downgrading Xamarin.Forms to version 4.6.0.847, the problem was resolved.
The following link provides further details On this issue:
https://www.syncfusion.com/forums/155376/sfdatagrid-crashes-app-when-user-start-to-scroll-the-content-18-1-0-57
https://github.com/xamarin/Xamarin.Forms/issues/11132
You do not need the renderer initialization if you are using Xamarin.iOS platform and not the cross-platform.
In case, if you are using the iOS version of Xamarin.Forms, then refer the getting started documentation here to know the step by step configuration of the DataGrid component. Confirm that you have installed the Syncfusion.Xamarin.SfDataGrid NuGet package.
In case, if you are using the Xamarin.iOS platform itself, then please refer the documentation here for the step by step configurations and be sure that you have installed the Syncfusion.Xamarin.SfDataGrid.IOS package.
I hope that helps.

Visual Studio 2017 publish ASP.NET Core app with C# 7.2

I have a Asp.Net MVC Core website that's using public static async Task Main(). For that to work I've set the language version to C# 7.2 (in the properties -> build -> advanced dialog, double checked in the csproj) for both Debug and Release build configurations.
App builds and starts fine in both Debug and Release mode.
Now, I'm trying to publish it to an Azure Website directly from Visual Studio 2017 15.5.2 (with WebDeploy) and I get this:
Program.cs(17,29): Error CS8107: Feature 'async main' is not available
in C# 7.0. Please use language version 7.1 or greater. CSC(0,0): Error
CS5001: Program does not contain a static 'Main' method suitable for
an entry point
In the output window I see it's running C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\csc.exe with some flags, probably one of them is wrong?
Anyone know if this is a known issue or I'm doing something wrong?
This appears to be a bug in Visual Studio.
Adding this line to main property group in the .csproj file resolved the issue for me:
<LangVersion>latest</LangVersion>
The issue was also reported here in the ASP.NET Home repository.
Not an answer, per se, but for what it's worth async Main is just syntactic sugar. Behind the scenes Roslyn just adds the standard void Main wrapper construction:
static void Main(object[] args)
{
MainAsync(args).GetAwaiter().GetResult();
}
static async Task MainAsync(object[] args)
{
// your code
}
It's probably not worth your time trying to get the server on the same page C# version-wise, just to save literally three lines of code.

Are there any dependencies for UI Automation?

I have a Windows application which captures the details from screen based on the configuration. I am using UI Automation to capture the details from the screen. Everything works fine on the developer's machine where Visual Studio is installed. When I run the same application on another system where we have only .NET Framework 4.5 installed, it started behaving strangely, and it's not able to detect the child element.
My question is why it works fine on the developer's machine where Visual Studio and .NET Framework are installed. What's the difference? Is there anything we are missing as far as prerequisites? Any dependencies of UI Automation or any library we are missing..?
Thanks in advance - please help me out.
It looks like a known bug in .NET wrapper around native UIAutomationCore.dll (yes, its core is not a .NET). And it's included into WinVista+ (.NET Framework also adds it even to WinXP).
Here is a C# example how to use native COM API (UIAutomationCore.dll) from C#. Just copying the code here:
using System;
using interop.UIAutomationCore;
namespace PrintDesktopUiaElementNameViaCom
{
class PrintDesktopUiaElementNameViaComProgram
{
static void Main(string[] args)
{
// Instantiate the UIA object:
IUIAutomation _automation = new CUIAutomation();
// Get the root element
IUIAutomationElement rootElement = _automation.GetRootElement();
// Get its name
string rootName = rootElement.CurrentName;
Console.WriteLine(
"The root automation element's name should be 'Desktop'.");
Console.WriteLine("The actual value is: '{0}'", rootName);
}
}
}
Yeah at last after doing day's reading, i came to know the solution is that der is no dependency on Visual studio.
This behavior is due to lack of privileges to the application. so to overcome this behavior we have to get signed our application and one more thing its very important thing is place your executable file in Program Files
Reference Links : https://msdn.microsoft.com/en-us/library/windows/desktop/ee671610(v=vs.85).aspx

Unable to run Console Application from Visual Studio: System.AccessViolationException

Description
When launching any Console Application, the code stops running immediately on an AccessViolationException (Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt). More info included in the next section.
Technical Symptoms
The Call Stack only contains external code:
Exception:Thrown: "The message filter indicated that the application is busy. >(Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))" (System.Runtime.InteropServices.COMException)
A System.Runtime.InteropServices.COMException was thrown: "The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))"
Time: 12/10/2015 10:59:55 AM
Thread:vshost.NotifyLoad[15344]
I created a new Console Application, containing only Console.WriteLine("Hello world!");
Running the new Hello world app results in the same exception and an identical
call stack.
Background
I suspect this has nothing to do with the issue, as I will explain, but I feel it is important to answer the obvious question, "what were you doing when the issue happend?" The last change I made was adding an extension to my Selenium Driver to hotkey logout from an application:
public static void logout(this IWebDriver Driver)
{
Driver.FindElement(By.TagName("body")).Click();
new Actions(Driver)
.SendKeys(Keys.Control + Keys.Shift + "x")
.Perform();
}
I also made a change in my App.Config file for one of my projects, but reverting this had no impact either.
Removing this code (the Driver extension and/or the App.Config change) does not resolve this issue. Retrieving a previous check-in does not resolve the issue. I am the only person currently working on this solution.
Discoveries
As mentioned, this is happening for an empty Console Application. Windows Form Applications launch fine. Unit Test Projects launch fine as well.
Research
I've spent hours looking into this. It seems like every similar issue I have looked into is pertinent to debugging only or a .NET version. For me, the issue occurs with a Release as well. Additionally, I have been using .NET 4.5 without any issues or changes on that front. I can't find any articles that seem worth posting, but I might be overlooking something.
Visual Studio Info
Microsoft Visual Studio Ultimate 2013
Version 12.0.30501.00 Update 2
.NET Version 4.6.00081 (just noticed it says 4.5 in my project properties, though)
Running as Administrator
Feedback
When Running from devenv.exe /SafeMode, Visual Studio loaded with:
An exception was encountered while constructing the content of this frame. This information is also logged in "C:\Users\UserName\AppData\Roaming\Microsoft\VisualStudio\12.0\ActivityLog.xml".
Exception details:
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Microsoft.VisualStudio.Shell.Interop.IVsShell5.LoadPackageWithContext(Guid& packageGuid, Int32 reason, Guid& context)
at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.GetPackage()
at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.ConstructContent()
Additionally, when trying to run, I get an error message of "Error while trying to run project: Invalid Pointer" (again, VS in devenv.exe /SafeMode - see how to run visual studio without plugin and all third party feature if unfamiliar)
Please let me know if I can provide any additional information.
It may be because when you name the project you can't put spaces, I put them and it gave me a AccessViolationException aswell, try using capitals to separate your words, but only use letters and no spaces to be sure.
I also faced this issue with Visual Studio 2010. More interestingly I had several projects in my solution (Console application, WPF application, Windows Forms application) but it was failing only when, I was setting the project which was of type "Console Application" as start up project. Following change finally helped me nail down the issue: Go to project properties of the console application project -> Go to "Debug" tab -> Go to "Enable Debuggers" section in right pane -> Check the "Enable unmanaged code debugging" check box as shown in the snapshot below. Root cause of why it happened is still not known to me. Only thing which I observed as fishy was that there were lot of windows updates which had got installed on my machine the previous night which mostly constituted of office updates and OS updates (More than a dozen KB articles).

Categories