System.Management.Automation dll throws ItemNotFoundException on Appx calls - c#

I have a very strange issue. I have added a reference to System.Management.Automation in my project and I am trying to call the following code:
using (Powershell ps = Powershell.Create())
{
ps.AddScript("Get-AppxPackage");
ps.Invoke();
}
Note that I can run other powershell commands in this way fine, it is only the Appx commands that are raising an exception. Running the Get-AppxPackage command results in an ItemNotFoundException. The error is:
Exception thrown: 'System.Management.Automation.ItemNotFoundException' in System.Management.Automation.dll
Additional information: Cannot find path 'C:\Users\xxxx\Documents\WindowsPowerShell\Modules' because it does not exist.
My first assumption was that this may be a working directory thing, so I explicitly set the working directory before calling the command, but that did not change anything. I then checked, and that directory did not exist, so I created it just to see what would happen. After creating the directory and running the code again I got this error:
Exception thrown: 'System.Management.Automation.ItemNotFoundException' in System.Management.Automation.dll
Additional information: Cannot find path 'C:\windows\system32\windowspowershell\v1.0\Modules\Appx\Microsoft.Windows.Appx.PackageManager.Commands' because it does not
I honestly have no idea what is going on here. To make the issue even stranger, I tried this on another computer and the code works fine. So there must be something wrong with Visual Studio or my project on that one computer.
I've tried deleting the debug and obj folder, the suo and all of that. I've removed the reference to System.Management.Automation and re-added it, even rebooting in between. I am at a loss, I have no idea why this is happening or what else I can do to figure it out.
Note: I am able to run the Appx commands in Powershell ISE fine, so there is no issue on the computer. The problem is only with calling that command through the System.Management.Automation dll.
Any help would be greatly appreciated.

OK, it appears that this issue was caused by installing the incorrect version of System.Management.Automation as a nuget package via the package manager. I had uninstalled this and then added a reference to the latest version of the DLL manually before I started getting the issue described above.
But the uninstall for the nuget package clearly didn't work properly as the project continued to reference this version, and nothing I tried could get it to use the new one.
To solve the issue, I created a new project, added the source files, added a reference directly to the new version of System.Management.Automation and the error stopped occuring.
I can only assume that the installing and uninstalling the wrong version with the package manager corrupted the first project.

Related

while VSbuild task getting error error MSB4057: The target "_IsProjectRestoreSupported" does not exist in the project.,

Working on wpf application, with Wix to create .msi. why am i getting error
D:\a\1\s\wpfsetup\wpfsetup.wixproj : error MSB4057: The target
"_IsProjectRestoreSupported" does not exist in the project
using msbuild version '17.2.1.25201
NuGet Version: 4.4.1.4656
Please check if the below steps help to fix the issue:
As per my research, it seems to be many bug fixes in every alternate version of the MS Build like 15.8.1, 16.11, etc.
There are some breaking changes and behavior changes mentioned in the MSFT official documentation of MSBuild 17.0. Please check this documentation to know more information if these changes with their resolutions helps to fix the issue.
And it might be the folder path in the build was wrong. Target Name must include the name of the solution folder. Refer this.
Try Restoring the MSBuild Nuget Package Version using this command:
nuget restore MySolution.sln -MSBuildVersion 16.11

Weird error: Microsoft (R) Visual C# Compiler version 3.5.0-dev-20359-01 (8da8ba0c)

I have a Unity 2020.3.22f1 project that was perfectly working at first. However, this error occured after editing and saving one of my scripts in Visual Studio (with no apparent bug in it):
I don't give details about my script or the project, because it doesn't seem to relate to the project itself or what I did, as the error appears now in all my Unity projects! I first tried to delete the script that triggered the bug, then I deleted the whole project. I even uninstalled/reinstalled Unity (different versions), Visual Studio and Unity Hub. But it seems that now I'm stuck with this forever.
Does anyone have a single clue about this? I saw one or two people having the same problem on the web, and with no other solution than formatting the hard drive. As I'm not working on my personal computer, I can't do that...I mean, there must be a rational explanation to this bug!!
I downloaded the latest version of Unity (2021.2.2f1), launched a brand new project, and the error now turned to: "The specified path can't be found" (rough translation from french), without more precision...still no idea what it means.
Ok, I found a solution from here: Unity 2019.3.0a7: Microsoft Visual C# Compiler Errors
I don't know how it's related, but it is suggested that the error can be triggered by uninstalling Anaconda and Python (which I happened to do recently), which leads to remaining artifacts in the Windows registry. I then deleted the following item in the Windows registry:
Computer\HKEY_CURRENT_USER\Software\Microsoft\Command
Processor\AutoRun
and restarted Unity. Now it works!
Got the same issue, the problem is in an incomplete path
Command line is : "C:\Program Files\Unity\Hub\Editor\2022.1.0a13\Editor\Data\Tools\netcorerun\netcorerun.exe" "C:/Program Files/Unity/Hub/Editor/2022.1.0a13/Editor/Data/Tools/ScriptUpdater/ApiUpdater.MovedFromExtractor.exe" "Library\Bee\artifacts\mvdfrm\UnityEngine.LocalizationModule.dll_9374ECE80455BEFE.mvfrm" "C:\Program Files\Unity\Hub\Editor\2022.1.0a13\Editor\Data\Managed\UnityEngine\UnityEngine.LocalizationModule.dll"
Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\damos\project name is missing here\Library\Bee\artifacts\mvdfrm\UnityEngine.LocalizationModule.dll_9374ECE80455BEFE.mvfrm'.
This path is missing the project name between damos ans library

Issue with nuget package Xamarin.Firebase.iOS.CloudMessaging 3.1.2

I get many error messages if I install the Xamarin.Firebase.iOS.CloudMessaging 3.1.2 nuget package.
Error: linker command failed with exit code 1 (use -v to see invocation)
Error MT5210: Native linking failed, undefined symbol: _FIRLogBasic. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
Error MT5211: Native linking failed, undefined Objective-C class:
FIROptions. The symbol '_OBJC_CLASS_$_FIROptions' could not be found
in any of the libraries or frameworks linked with your application.
Error MT5211: Native linking failed, undefined Objective-C class:
GULAppEnvironmentUtil. The symbol
'_OBJC_CLASS_$_GULAppEnvironmentUtil' could not be found in any of the
libraries or frameworks linked with your application.
Error MT5201: Native linking failed. Please review the build log and
the user flags provided to gcc: -ObjC
Error MT5202: Native linking failed. Please review the build log.
I tried uninstalling and reinstalling the nuget package but I still get the same errors.
I use Visual Studio Community for Mac 8.1.5 (build 9).
I need Xamarin.Firebase.iOS.CloudMessaging because I follow this tutorial: https://www.robbiecode.com/setup-push-notifications-with-firebase-in-xamarin-forms-for-ios/
What is wrong with my project? What can I do?
The following two projects are in my solution:
InapppurchaseTest.iOS, MonoGame.Framework.iOS (develop)
Well, this is a well-known issue with Firebase and Xamarin, what basically happens here is the old bin and obj files while interacting with the new data override some existing files that are needed by iOS to synthesize the IPA while deployment and hence ends up throwing linking RELATED errors, follow the below steps and it will clear this mess.
Clean bin and obj
Delete the builds in the following path of your MAC machine - ~/Library/Caches/Xamarin/mtbs/builds/ProjNAME where 'ProjName' is the name of the project you are currently working on
Once you are done with both the above steps add the Xamarin.Firebase.iOS.CloudMessaging package and change linker setting to Don't Link (this is for the time being)
After installing these packages see to it that you build your project dependency wise which means PCL'S and .Net standards first then the native iOS project.
Clean bin and obj again if it does not work for the first build...
This should solve your issues in case it does not repeat the above procedure.
EDIT
If you check the GitHub comment by SotoiGhost here, it says adding the below line anywhere in your project should solve this issue...
var foo = Firebase.Core.Configuration.SharedInstance;
Feel free to get back in case of issues
Good luck!

Why does using SQLite in Azure Functions give me a DLLNotFoundException?

I'm trying to write a timer-triggered Azure Function that downloads a bunch of data and processes it into a SQLite database. I've written code that does this and runs fine on my own machine. But, the same code in Azure yields a DllNotFoundException, complaining that the system can't load "e_sqlite3."
Here is the full error message (for the inner exception):
Exception while executing function: FnordFunction
Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception
while executing function: FnordFunction --->
System.TypeInitializationException : The type initializer for
'SQLite.SQLiteConnection' threw an exception. --->
System.DllNotFoundException : Unable to load DLL 'e_sqlite3': The
specified module could not be found. (Exception from HRESULT:
0x8007007E)
at
SQLitePCL.SQLite3Provider_e_sqlite3.NativeMethods.sqlite3_libversion_number()
at
SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number()
at SQLitePCL.raw.SetProvider(ISQLite3Provider imp)
at SQLitePCL.Batteries_V2.Init()
at SQLite.SQLiteConnection..cctor()
End of inner exception
Here are the steps to reproduce:
In Visual Studio 2017, I created an Azure Function project using the latest template.
I added my code files to the project, and edited the "Run" method to call the code.
Using NuGet, I added sqlite-net-pcl, and some other libraries I need. (I've also tried this with EntityFrameworkCore, using SQLite; that didn't work either).
Build
Publish
Run. Failure.
The problem might be that my code is wrong--but it works fine when I just make a console .exe.
The problem might be that VS2017 is not bundling the correct dll for SQLite when it builds. I'm not sure how to fix that. I've seen from other searches that the same error message pops up when the platform target is set to "Any CPU," but changing that to x86 or x64 does not fix the problem.
The problem might be that the SQLite libraries I have tried won't run in the Azure Functions sandbox. If so, are there any simple SQLite libraries that will run in the sandbox?
Thanks in advance...
The problem is that when running in a Function App, native binaries can't be automatically loaded from your bin folder, so it's not finding the DLL.
One way to solve this is to drop it in your D:\home\site\tools folder (e.g. using Kudu Console), as that folder is automatically place on the PATH.

Receiving Build Error When Trying To Build EFModel

As the title says, when I am trying to build the DLL for my EF model, I am receiving the following build error:
Error 9 An Exception was thrown while processing the template. The following Exception was thrown:
System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
at Microsoft.VisualStudio.TextTemplating.IDebugTransformationRun.get_Errors()
at Microsoft.VisualStudio.TextTemplating.Engine.ProcessTemplateImplementation(TemplateProcessingSession session, String content, ITextTemplatingEngineHost host, String className, String classNamespace)
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\SSDLToSQL10.tt 0 0 Miscellaneous Files
I am using Entity Framework version 6.1.3 and the odd thing is that I have another copy of the same project elsewhere in my solution and it does not get this error.
Does anyone have any suggestions on how to fix this build error?
After looking around elsewhere, I developed a hunch that the problem was being caused by my Entity Framework installation. I went ahead and opened up the NuGet Package Manager console and ran the command:
Update-Package –reinstall EntityFramework.
After waiting for EF to reinstall, I restarted Visual Studio. Upon restarting I was able to build my EF Model project without any errors. Hopefully this helps anyone else who runs into the same problem.

Categories