Xamarin Forms in Visual Studio 2017 XAML validation - xaml

I am really new to Xamarin.Forms and trying to learn using this nice tutorial.
I have managed to set up everything in Visual Studio 2017 Community Edition and successfully deploy to both emulated and physical devices (Android only).
During various trials, I have noticed that some XAML errors are not highlighted and build is successfully performed, but XAML failed at runtime, crashing the app. E.g. misspell a style name or any an attribute value.
Running in debug mode will just hang the app. Breaking it indicates the following line:
public partial class MainPage : global::Xamarin.Forms.ContentPage { [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private void InitializeComponent() {
// this is the last line from my code that hands when XAML is invalid
this.LoadFromXaml(typeof(MainPage));
}
}
Resuming the execution shows a hint of what is wrong (no fancy details as provided by the new VS2017 exception interface):
Unhandled Exception:
Xamarin.Forms.Xaml.XamlParseException: occurred
Question: Is there a way to catch invalid XAML errors earlier? Or at least obtain more relevant information? Or is this a known limitation of Xamarin.Forms?
To make things worse, autocomplete for attribute values does not seem to work in VS2017 (it works in VS2015), but this is another issue for another question.
Further details about installed software:
Microsoft Visual Studio Community 2017
Version 15.0.26228.9 D15RTWSVC
Microsoft .NET Framework
Version 4.6.01586
Installed Version: Community
Xamarin 4.3.0.795 (aece090)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin.Android SDK 7.1.0.41 (9578cdc)
Xamarin.Android Reference Assemblies and MSBuild support.
Xamarin.iOS and Xamarin.Mac SDK 10.4.0.123 (35d1ccd)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

To catch XAML errors at compilation time you have to add one line to AssemblyInfo.cs :
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
More information on this can be found here.
Unfortunately Xamarin.Forms XAML intellisense support in VS is not like for WPF or SilverLight, it's very limited currently. One suggestion can be to write your ui in code, this way you will get a feedback faster and if you are very new to Xamarin.Forms XAML you can get familiar with it much easier because of intellisense in code behind.
Another option is to use IDE extensions, in your case as I understand it is VS 2017 for Windows so it will not help you, but for Xamarin Studio for MC you have tools like mfractor, that build to solve the issues you addressed.

Related

Visual Studio 2017 not highlighting errors

I recently upgraded from Visual Studio 2012 to 2017 (updated to version 15.3.5) and have some issues with the IDE.
In a certain project, I don't get error underlining.
and in the Error List pane, "Build Only" actually shows more information than "Build + IntelliSense"
Also, with "Build + IntelliSense" selected, I can only see the compiler error in the Output window. Here is the error list after a failed build
but the output window has this:
3>------ Build started: Project: ..., Configuration: Debug Any CPU ------
3>C:\Checkout...\MainForm.vb(454,27): error BC30311: Value of type 'Module1.aClass' cannot be converted to 'Module1.bClass'.
This doesn't happen on all projects. I made a new project to see if I could reproduce, and I can't. Here is a new project with the same code, where the error is underlined in code and "Build + IntelliSense" works.
I have even sorted the xml in the vbproj files and "diffed" the offending project vs the new project, and there is no obvious difference which would cause this. Both reference the same compiler. Both projects target .Net 4.6.2 and are set to compile for x86 only. The offending project references a few other projects (C# and VB.Net) plus a third party dll and a nuget package. Aside from these differences there is nothing else.
Other projects (C# and VB.Net) in the offending project's solution work fine.
I have seen similar issues talked about online but no fixes have worked for me. I have tried the "Repair" option in the installer. I then uninstalled Visual Studio and reinstalled.
Update:
Changing the target framework seems to have some effect. A project with this behavior was targeting 4.6.2 and showing no errors, and when it was changed to 4.7, it showed a compile error. Then changing back to 4.5 it showed an error. Then changing back to 4.6.2 it showed no errors. Repeating the process proved to be non repeatable. 4.7, 4.5, 4.6, 4.6.2 - whatever, now all show no errors.
It's also important to link this Microsoft page https://developercommunity.visualstudio.com/content/problem/7759/no-errors-displayed-in-the-error-list.html as many other people seem to have a similar issue.
I have solved the problem, at least in my solution.
I was playing around with project references, and found that when a particular project was not referenced by another project, I got error underlining. I went through a process of changing framework version targets until something worked.
All my projects had previously been targeting .NET 4.6.2. By targeting 4.7 on all the projects, I now get proper error underlining and reporting in the Error window.
I'm not sure if this is a solution for everyone and it will take some additional work on my end to deploy my project to production but I can accept this.
I guess this is related to targeting 4.6.2 using Visual Studio 2012 and upgrading to 2017. Maybe something was not set properly if/when the projects were upgraded.

Is it possible to execute a vbproj with mono?

I have to continue a program witch have been coded with Visual Studio and the framework .NET framework 4 but the thing is : I have a macbook.
After many researches I have found that by using Mono it was possible to code in vb.net with a mac. However, the project is working on Windows computer but I get this warning:
"warning MSB3256: No assemblies were read in from the redist lists. A TargetFramework profile exclusion list could not be generated."
and this error:
"error MSB6006: "vbnc.exe" exited with code 1"
So I'm guessing that he doesn't recognize that mono should replace .NET framework. I am executing the code with MSbuild, maybe that is the issue?
Unfortunately you are stuck.
Microsoft would like to bring C#/VB and .NET Core to Mac via Visual Studio for Mac, so you should not attempt to bring any .NET Framework projects to Mac via Mono any more.
This warning is more critical to VB developers, as Mono's VB support (vbnc.exe is Mono VB compiler) is experimental and does not support all VB latest features.
However, for .NET Core development, VB is also not yet ready to be used, and should be available in a few months when Microsoft ships .NET Core 2.0.
You can definitely play with VB by using .NET Core 2.0 Preview build,
https://www.infoq.com/news/2017/05/netcore2preview
But then you cannot use VS for Mac, and have to use an editor such as Visual Studio Code.
For some reason, Mono uses vbnc by default although there is a Roslyn-based VB compiler built-in to Mono, vbc. Interestingly, vbnc is even not being installed with mono-devel package and it still being used by default.
If you installed vbnc and started to get this message:
"error MSB6006: "vbnc.exe" exited with code 1"
you need to instruct Mono to use vbc instead and your code will build. The most reliable way to do it is to set it per project, by adding the following XML to your vbproj file:
<PropertyGroup>
<VbcToolExe>vbc</VbcToolExe>
</PropertyGroup>
The code should be placed inside the root <Project> tag.

"Option Strict On disallows implicit conversions" inconsistent enforcement

configuration 1: building ESRI add-ins for ArcMap 10.4 using Visual Studio 2015 targeting the .NET 4.5.2 framework
configuration 2: building ESRI add-ins for ArcMap 10.3 using Visual Studio 2013 targeting the .NET 3.5 framework
configuration 3: building ESRI add-ins for ArcMap 10.4 using Visual Studio 2013 targeting the .NET 4.5.2 framework
I'm trying to understand why the Option Strict On enforcement in VB.NET projects does not raise error BC30512 in two projects and it does in another. Here is an an example line of code that triggers the error using configuration 1 but does not trigger the error with configuration 2 or 3.
Dim bufferedPolygon As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.Polygon
Additionally, if I instantiate the managed class instead of the coclass, the error is not triggered in either configuration (see following line):
Dim bufferedPolygon As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.PolygonClass
The different versions of ArcMap dictate which version of the framework is targeted. For additional background, the COM to .NET Type Conversion of the ArcObjects documentation is relevant:
Using ArcObjects (COM-based) in .NET (ArcObjects .NET 10.4 SDK)
Why is the error triggered in configuration 1 and not in configuration 2 or 3? And why isn't the error triggered in configuration 1 when instantiated with the managed class instead of the coclass?
Link to an issue submitted at the dotnet/roslyn github repository.
https://github.com/dotnet/roslyn/issues/13314
Thanks
Shea
At this time, it appears (as Hans Passant suggested in a comment on the original post) that this is indeed a bug with the Roslyn compiler in Visual Studio 2015. I opened an issue at the dotnet / roslyn GitHub repository, and it has been labeled a bug and assigned to a team member. The status of this could change as the issue is investigated.
The link to the issue and additional troubleshooting information is https://github.com/dotnet/roslyn/issues/13314

ResourceManager is not declared. It may be inaccessible due to its protection level issue

I have a question about importing a National Instruments (NI) library to my Visual Studio 2012 project. (Using Visual Basic .NET, Windows 7 and Visual Studio 2012)
I currently test the FindReources(NI-VISA) example project to apply some of the functions to my project.
The sample project was working fine, and it was returnning resource data corrent.
However, when I tried to apply Find Resource function to "My project" an error message kept appearing such as "ResourceManager is not declared. It may be inaccessible due to its protection level"
What I did was...
First, I added a reference to my project
Second, I imported "Imports NationalInstruments.VisaNS" to my Visual Basic file
However, the error keep appearing, so I can't use function.
And, when I restart Visual Studio and check the Object Browser, there is a NI-VISA reference and the error is gone.
However, when I run the project, NI.VisaNS library just disappear...
I am not really sure why this happens, because the sample project from NI is working without any trouble.
Is there a missing step to import and use the NI library?
I just found a solution.
The functions which I wanted to use was only working for .NET 4.5. However, my system was using .NET 4.0.
After I switched to .NET 4.5 for my project, it worked fine.
Try to find that file/resource in Solution Explorer. It should be there somewhere in the tree. If it has a blank icon next to it, that means that the file is not included in the project. Click the right mouse button over the file and add it.

Silverlight designer unhandled exception

When I create a new Silverlight Application (C# if that matters) using Silverlight 4 (with or without WCF RIA Services Checked) and open the MainPage.xaml in the designer I receive an Unhandled Exception has occurred. Stack is below. This is on an unmodified project.
I have uninstalled all Silverlight and reinstalled the tools listed above. I the same error when I open the App.xaml file as well. When I compile it completes without error, however when I run the application it always comes up that Silverlight is not installed.
I have installed Visual Web Developer Express 2010 (v10.0.30319.1 RTMRel) and Silverlight Tools for VS2010 (v10.0.30319.332) on a 32bit Windows XP machine. The IDE works fine in other regards, only issue seems to be with xaml files.
Anybody run into this?
System.NullReferenceException
Object reference not set to an instance of an object.
at Microsoft.Expression.Platform.Silverlight.SilverlightDomainManager.CreateDomainCore()
at Microsoft.Expression.Platform.Silverlight.SilverlightDomainManager.CreateDomainInitial()
at Microsoft.Expression.Platform.Silverlight.SilverlightPlatformCreator.Initialize()
at MS.Internal.Platform.SilverlightPlatformImpl.Initialize()
at MS.Internal.Package.VSIsolationProviderService.RemoteReferenceProxy.EnsurePlatformInitialized()
at MS.Internal.Package.VSIsolationProviderService.RemoteReferenceProxy.EnsurePlatformInitialized()
at MS.Internal.Package.VSIsolationProviderService.CreateIsolationProvider(String originalIdentifier, Boolean isGlobal, String identity, FrameworkName frameworkName, AssemblyName appAssemblyName, IVsHierarchy hierarchy)
at MS.Internal.Package.VSIsolationProviderService.CreateIsolationProviderWorker(String identifier, IServiceProvider provider)
at MS.Internal.Package.VSIsolationProviderService.CreateIsolationProvider(String identifier, IServiceProvider provider)
at MS.Internal.Providers.VSDesignerContext.CreateIsolationProvider(IServiceProvider provider, IVsHierarchy hierarchy)
at MS.Internal.Providers.VSDesignerContext.<>c__DisplayClass1.b__0(IsolationProviderProxy i)
at MS.Internal.Providers.IsolationProviderProxy.get_RealProvider()
at MS.Internal.Providers.IsolationProviderProxy.add_UnhandledException(UnhandledExceptionEventHandler value)
at MS.Internal.Designer.DesignerPane.LoadDesignerView()
After hours of pulling my hair out I found the following post that led me on the path to solving my problem. I had to uninstall the standard version of silverlight and then install the developer runtime and it solved all my problems. Go Figure.
Posted by Microsoft on 2/26/2010 at
12:40 PM Is what is likely
happening is that you have the
standard version of the Silverlight
runtime and you need to install the
developer runtime for Silverlight.
Blend will install and run with the
standard verison of the silverlight
runtime, but Visual Studio requires
the developer version of the runtime.
This issue is fixed in the RTM version
of Visual Studio.
For now, if you hit this issue, please
install the silverlight developer
runtime from this link:
http://go.microsoft.com/fwlink/?LinkId=146060
download Silverlight_Developer.exe
Did you install the latest Silverlight SDK?
http://www.microsoft.com/downloads/details.aspx?FamilyID=40ef0f31-cb95-426d-9ce0-00dcfabf3df5&displaylang=en