What is PowerShell.Telemetry.ApplicationInsightsTelemetry and can I turn it off? - c#

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");

Related

Error : Unable to load DLL 'libgmp-10.dll' when testing azure function c# .net 5.0

I published my c# .NET 5.0 code to azure functions (windows) and im getting this weird error message:
2021-06-21T01:56:53.465 [Error] Executed 'Function1' (Failed, Id=fdefdbba-49a7-44ad-8082-841d2941d90b, Duration=169ms)Unable to load DLL 'libgmp-10.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
I tried to see the \wwwroot files on the azure functions console but then i get this error:
3 [main] ls (8392) C:\Program Files\Git\usr\bin\ls.exe: *** fatal error - Couldn't set directory to \\?\PIPE\ temporarily.
Any hints?
It seems that the deployment is not done correctly.
Libgmp-10.dll a DLL (Dynamic Link Library) file which is referred to
essential system files of the Windows OS. It usually contains a set of
procedures and driver functions, which may be applied by Windows.
Please delete the Azure Function and, re-create and deploy a fresh code using Develop and publish .NET 5 functions using Azure Functions OR if you are using ADO, Setting up a CI/CD pipeline for Azure Functions.
Let me know if you have any follow up questions.

An error has occurred during web site deployment in App Service Editor

I made some changes in the QnAMakerBasDialog.cs file, in trying to edit the default threshold. I did not change any other thing. When I tried deploying my changes at first, I was not getting the expected response and so I went back the editor to reverse my changes. It was at this point I started getting this error message.
I need help in reversing all changes if possible but most expecially in getting "test web chart" and all my channels working again.
Please see error message error:
kindly note that I tried this in the kudu console but still got the same error message
\> build.cmd
1 file(s) copied.
Installing Kudu Sync
D:\local\AppData\npm\kudusync -> D:\local\AppData\npm\node_modules\kudusync\bin\kudusync
+ kudusync#0.3.0
added 7 packages from 8 contributors in 3.22s
Handling ASP.NET Core Web Application deployment.
Failed to add 'D:\local\UserProfile\.dotnet\tools' to the PATH environment variable. Add this directory to your PATH to use tools installed with 'dotnet tool install'.
Welcome to .NET Core 3.1!
---------------------
SDK Version: 3.1.301
Telemetry
---------
The .NET Core tools collect usage data in order to help us improve your experience. The data is anonymous. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
----------------
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Find out what's new: https://aka.ms/dotnet-whats-new
Learn about the installed HTTPS developer cert: https://aka.ms/aspnet-core-https
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs
Write your first app: https://aka.ms/first-net-core-app
--------------------------------------------------------------------------------------
Unhandled exception. System.ComponentModel.Win32Exception (5): Access is denied.
at System.Diagnostics.Process.set_PriorityClassCore(ProcessPriorityClass value)
at System.Diagnostics.Process.set_PriorityClass(ProcessPriorityClass value)
at Microsoft.Build.CommandLine.MSBuildApp.Execute(String[] commandLine)
at Microsoft.Build.CommandLine.MSBuildApp.Main(String[] args)
MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
System.ComponentModel.Win32Exception (5): Access is denied.
at System.Diagnostics.Process.set_PriorityClassCore(ProcessPriorityClass value)
at System.Diagnostics.Process.set_PriorityClass(ProcessPriorityClass value)
at Microsoft.Build.CommandLine.MSBuildApp.Execute(String[] commandLine)
Failed exitCode=-532462766, command=dotnet restore "QnABot.sln"
An error has occurred during web site deployment.
Surprisingly, I also encountered this problem. I also encountered this problem in Buid after modifying the Azure Bot code!
Even with this error, my build is successful

Azure DevOps - PowerApps package Deployer - You cannot call a method on a null-valued expression

I am trying to run packagedeployer using PowerApps Deploy Package and getting an error "You cannot call a method on a null-valued expression".
This is a CRM Package solution that is created using Dynamics 365 SDK templates. Please find below the link with details
https://learn.microsoft.com/en-us/powerapps/developer/common-data-service/package-deployer/create-packages-package-deployer#create-a-package
Azure DevOps Error Screenshot
"You cannot call a method on a null-valued expression"
The information is not enough to solve the problem, but i can suggest a way you can troubleshoot.
First, set the system.debug value to "true" in your pipeline Variables,
and then run the build again and you shall see the detailed exception message in the debug information(with ##[debug] before them) in the log information.
Most likely you will see it's a ps1 file that raised the error since the error message you cannot call a method on a null-valued expression usually occurs in ps script and it should points out in which line which char you got the error.
Then, add a PowerShell Script task down below your PowerApps Deploy Package task, add an Inline script using the Get-Content method:
Get-Content -Path {path you find in above task log information}
Now you are able to see which line in the script caused the problem and find a way to solve it, or update what you find in your question post and we will keep on.
Below are some reference links you can check:
Troubleshoot the InvokeMethodOnNull Error with PowerShell
You cannot call a method on a null-valued expression

ASP.NET Attempt by method ... to access field 'System.Data.SqlClient.xxx._connection' failed

I'm using a package from NuGet which works on localhost, worked on a production server but after a recent move to a different production server, I get the following error:
Attempt by method 'EntityFramework.BulkInsert.Extensions.TypeExtensions.GetPrivateFieldValue(System.Object, System.String)' to access field 'System.Data.SqlClient.SqlConnection._connectionString' failed.
The package is: https://efbulkinsert.codeplex.com/ I don't think it's package specific because using an alternative package for bulk inserts I get a similar error:
Attempt by method 'Z.Utility.SqlBulkOperation.SetCommonSetting()' to access field 'System.Data.SqlClient.SqlBulkCopy._connection' failed.
The common thing here is System.Data.SqlClient.xxx._connection failed
Are there any IIS setting I need to look at? I'm stumped.
I had to change the .NET Trust Levels from Medium to Full in IIS.

Issue with Microsoft Enterprise Library 5.0 and custom powershell cmdlet

I'm creating a custom powershell 1.0 cmdlet that will allow me to feed exceptions from powershell scripts to the Microsoft Enterprise Library v5.0 exception handling block.
I load up my Exception handling config from an external file since the cmdlet is compiled into a dll, and then try to create an instance of ExceptionManager using the config.
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource config =
new Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource(configFile);
WriteDebug("Config loaded from " + Path.GetFullPath(configFile));
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(config);
exManager = EnterpriseLibraryContainer.CreateDefaultContainer(config).GetInstance<ExceptionManager>();
This fails when I call my command from powershell with the following error:
Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type ExceptionManager, key "" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManager", name = "(none)".
Exception occurred while: while resolving. Exception is: InvalidOperationException - The type ExceptionManager cannot be constructed. You must configure the container to supply this value.
The frustrating thing is that the code works perfectly fine when used in a stand-alone console application with the exact same configuration. I'm not really sure why I'm getting this error; I've made sure that I'm using the same assemblies that are referenced in the config file and I've made sure that I'm referencing all the necessary enterprise library dlls in my project.
Additionally, I've had to copy the Enterprise Library dlls into the powershell install directory (%SystemRoot%\system32\WindowsPowerShell\v1.0), otherwise I would receive FileNotFoundExceptions about not being able to find the correct library while the configuration file was being processed. I don't have too much experience with powershell or enterprise library, but I'm guessing that this might be resolved by playing around with AppDomain settings.
Turns out I wasn't giving an absolute path to my configuration file, which was causing weirdness. I originally just set it to "widgit.dll.config", and threw it under %systemroot%\System32, since that's the default working directory of my powershell, and seemed to get rid of the initial "file not found" errors I was having (didn't want to change the working directory until I understood the entire problem). On a hunch, I copied the config into the powershell directory and renamed it powershell.exe.config, and that solved my other problem.
Putting stuff into system directories isn't the most elegant solution at this point, but it's sufficient for my current problem.

Categories

Resources