I'm loading a solution at runtime using MSBuild like that:
private Solution LoadSolution(string solutionPath) {
var msw = MSBuildWorkspace.Create();
var solution = msw.OpenSolutionAsync(solutionPath).Result;
return solution;
}
This works when I tried it in a console application however it throws an AggregateException when I try to run it in a WPF application which references the console application in which the LoadSolution method is located.
I tried doing it with async/await but whenever I do that I never receive a result from the thread.
The error I receive states :
First exception :
One or more errors occurred.
Inner exception :
{"Object reference not set to an instance of an object."}
Framework version 4.5.2.
The resolution mentioned in GitHub Roslyn issue tracker, to install Microsoft.CodeAnalysis v1.0.0.0 worked for me. I tried to execute the code mentioned in the question on .NET 4.5.2 console application.
Related
Due to some custom reasons, we have some custom built-in features in the XF (like the XAML-based toolbar button and changing private-internal to the public classes, plus virtualizing some methods). As the result, we are dependent on the custom version of the XF NuGet package.
It worked (almost always) perfectly until the version XF5.0. I have a dedicated virtual machine with Windows and preinstalled VS for those purposes.
When I'm trying to build XF from sources using the next command
.\build.ps1 -Target NugetPack -ScriptArgs '--packageVersion="5.0.0.2013"'
I get the error:
Successfully created package 'L:\src_github\xf_patch_release-5.0.0-sr3.1\artifacts\Xamarin.Forms.Maps.WPF.5.0.0.2013.nupkg'.
NuGet Version: 5.9.1.11
Attempting to build package from 'Xamarin.Forms.temp.nuspec'.
Object reference is not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at NuGet.Packaging.PackageBuilder.<>c.<ValidateReferenceAssemblies>b__173_1(NuGet.Frameworks1204671.NuGetFramework groupFramework)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.HashSet`1.UnionWith(IEnumerable`1 other)
at System.Collections.Generic.HashSet`1..ctor(IEnumerable`1 collection, IEqualityComparer`1 comparer)
at NuGet.Packaging.PackageBuilder.ValidateReferenceAssemblies(IEnumerable`1 files, IEnumerable`1 packageAssemblyReferences)
at NuGet.Packaging.PackageBuilder.Save(Stream stream)
at NuGet.Commands.PackCommandRunner.BuildPackage(PackageBuilder builder, String outputPath, Boolean symbolsPackage)
at NuGet.Commands.PackCommandRunner.BuildFromNuspec(String path)
at NuGet.CommandLine.PackCommand.ExecuteCommand()
at NuGet.CommandLine.Command.ExecuteCommandAsync()
at NuGet.CommandLine.Command.Execute()
at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)
An error occurred when executing task '_NuGetPack'.
Error: One or more errors occurred. (NuGet: Process returned an error (exit code 1).)
NuGet: Process returned an error (exit code 1).
I've tried to use different methods to get rid of this non-understandable issue, but nothing happened. I've tried to use the latest actual release-5.0.0-sr3.1 tag and the latest version of the branch 5.0.0
I've tried to change some settings in the build.cake file, to unload some projects from the solution (like UWP-related ones, which usually caused a lot of errors). I've tried to build the solution on my working computer (and environment) - I got the same result.
Then I switched to building the solution in the VS directly and started getting issues like:
Before calling the main task to build: .\build.ps1 -Target NugetPack... I always call the .\build.ps1 -Target provision to ensure that I haven't missed some required tools on each Windows OS.
Is there something that I have missed?
I've found out that I'm using a different version of the NuGet package manager, which I had to install globally on my OS. The right version can be found in the XF's Pipelines (https://dev.azure.com/xamarin/public/_build, see the Windows-related builds).
After I've changed the global version to 5.6.0, the build script started generating the *.nupkg file for the Xamarin.Forms project itself correctly.
...
I have a C# testing project that uses the Microsoft.PowerShell.SDK NuGet package. I use it to run a cURL command that I can't seem to get to work with an HttpClient (details on that here if you are interested).
It works great, except when I run as a weak user using RunImpersonated. Then I get the following exception:
System.TypeInitializationException : The type initializer for 'Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry' threw an exception.
With an inner exception of:
System.UnauthorizedAccessException : Access to the path 'CreateUniqueUserId' is denied.
I am not sure why my cURL powershell command needs to use Application Insights and I would like to turn it off if possible.
Is it possible to turn off Application Insights with the Powershell NuGet?
From the about_Telemetry help file:
To opt-out of this telemetry, set the environment variable POWERSHELL_TELEMETRY_OPTOUT to true, yes, or 1.
So running this when your application starts should do the trick:
Environment.SetEnvironmentVariable("POWERSHELL_TELEMETRY_OPTOUT", "1");
I have a Console application build in dotnetcorapp2.1. It's running fine on Windows.
When trying to run on Ubuntu it raise an Exception error:
System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.ConsolePal.set_BufferHeight(Int32 value)
That is because This line:
Console.BufferHeight = Int16.MaxValue - 1;
This document didn't mention the limitation that I take into account for Console.BufferHeight
Googling didn't help like this and this
What is the limitation of Console.BufferHeight (and BufferWidth) on Ubuntu?
I have posted this question to corefx team and submitted an issue there.
All credit in this answer go to #danmosemsft
The member Console.BufferHeight is not supported on Unix. The docs didn't state the Unix specific behaviors on the Console methods/properties.
The class ConsolePal in the document ConsolePal.Unix.cs include also other NotSupported members.
A new document is created to show the PlatformNotSupportedExceptions in System.Console
I modified the code and catch PlatformNotSupportedException separate and application is running on Ubuntu without a problem.
try
{
//.... do your stuff here
}
catch (PlatformNotSupportedException )
{
//log PlatformNotSupportedException
//noop
}
catch (exception ex)
{
//handle exception
}
Edit
Discovering the code that raise PlatformNotSupportedExceptions:
Install the nuget package Microsoft.DotNet.Analyzers.Compatibility
Install-Package Microsoft.DotNet.Analyzers.Compatibility -Version 0.2.12-alpha
Configure the tool as described here
Select the rule PC001 and select Set Rule Set Severity as error
When building the project, any issues related to PlatformNotSupportedExceptions is displayed as error in Error window
I am a beginner in software development. I was following a simple tutorial and was creating a web application in Asp.net MVC - 5. But suddenly my app stopped running even I did not do any fancy stuff. Below is the error I am getting. Please help me here.
Error: System.typeloadexception.
Additional: Microsoft,Ajax.Utilities.OutputVisitor from assembly 'WebGrease'
I have not touched these fancy stuff at all. But as soon as I run the application in local host I start getting this error. Error comes in _Layout.cshtml file near the line
#Scripts.Render("~/bundles/modernizr")
This can happen if your targeted .Net framework version not installed on your System. Check your project properties .Net version and check your Pc has respective .Net installed.
try
{
}
catch (TypeLoadException)
{
// this can happen if respective .Net is not installed in your system
}
TypeLoadException is thrown when the common language runtime cannot
find the assembly, the type within the assembly, or cannot load the
type.
or add this code snippet
AppDomain.CurrentDomain.AsemblyResolve += (s, e) =>
{
return AppDomain.CurrentDomain.GetAssemblies()
.SingleOrDefault(asm => asm.FullName == e.Name);
}
If all attempts fails, try to reinstall WebGrease nugget package
I'm attempting to use the OkHttp-Xamarin library in a Xamarin Android application. Whenever I try to create a new OkHttpNetworkHandler I get the exception below.
Line:
var handler = new OkHttpNetworkHandler();
Throws:
[] Missing method Android.Runtime.JNIEnv::AllocObject(Type) in assembly Mono.Android.dll, referenced in assembly /data/data/com.my.app/files/.__override__/OkHttp.dll
[MonoDroid] UNHANDLED EXCEPTION: System.MissingMethodException: Method not found: 'Android.Runtime.JNIEnv.AllocObject'.
[MonoDroid] at ModernHttpClient.OkHttpNetworkHandler..ctor () <IL 0x00001, 0x00057>
I am using prebuilt binaries from ModernHttpClient version 0.9. My minimum Android version is set to 2.3 and target is set to 4.2. I'm using Xamarin Studio 4.0.13 and Mono 3.2.3.
So this looks like the first call to your binding code.
A couple things could be going on here:
Make sure you are using EmbeddedJar instead of InputJar as the build action for the jar file. Otherwise, you have to include the jar with your main Android application.
Make sure your main application has a reference to the binding DLL, it causes problems if only a dependent project has the reference.
If neither of those fix your issue, let me know, I think there is a working binding Paul Betts has for this library.
Not really an answer to why the Exception is being thrown but at the suggestion of Paul Betts I switched to the Alpha channel and things are working now.