Windows Powershell SDK and System.Management.Automation.PSObject - c#

I have a build error in a c sharp program that I am compiling in Visual Studio 2008 on a Windows Server (2008, I guess) SP 2 64-BIT OS.
It says that 'System.Management.Automation.PSObject' is defined in an assembly that is not referenced.
I did some searching in MSDN and I found that this seems to be part of the Windows Power Shell SDK. http://msdn.microsoft.com/en-us/library/system.management.automation.psobject(VS.85).aspx
The problem is that I already have the Windows Powershell. If this is all I need, how do I make use of it or reference it in the C Sharp IDE. If I need to download something extra (ie the SDK), where do I go to do this and install it? I could not find anything online.

If you can't find it there, type this at a PowerShell prompt.
Copy ([PSObject].Assembly.Location) ~/Desktop

Look in C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0 for System.Management.Automation.dll and if it exists, add it as a reference in your C# project. If it doesn't exist, then download the Windows SDK which will put the file in the above location.

To correctly reference PowerShell, you should reference the PowerShell inside the GAC. The PowerShell included with the Vista SDK is PowerShell V1.0, and this technique will reference 1.0, 2.0, or X.0, whatever is installed. Referencing the SDK assembly will also not create the most portable of projects, because you have to have the SDK installed to build the project, rather than just Visual Studio and Windows.
Unfortunately, referencing GAC items is not something the visual studio UI does cleanly, so you have to go hand edit the CSProj file. Find the section with elements, and add this reference element.
<Reference Include="System.Management.Automation" />
This will reference the latest System.Management.Automation installed on the system, no matter what version it is.
Hope this helps

Related

Cannot find reference for System.Management.Automation in Visual Studio (.Net Framework 4.6.2 )

So I have view this link: How to reference System.Management.Automation in a .NET Framework 4.7.2?
"you must use System.Management.Automation v5.1.x." this could works for me
But I want to find out if I can use System.Management.Automation without install any reference using Nuget. (like from the native machine, add reference is fine.)
I try to find through assembly but nothing. I have verified that there exist System.Management.Automation.dll in all these three location:
C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35
C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0
C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0
Also, since I can fine the dll file, so I followed this link (https://learn.microsoft.com/en-us/dotnet/framework/app-domains/install-assembly-into-gac) to install an assembly into the global assembly cache. But still not work.
Only System.Management and System.Management.Instrumentation in (Assemblies) Add Reference table.
Please help,
Many thanks!
For downloading Microsoft.PowerShell.5.ReferenceAssemblies in visual studio, you could try this download method (right click on the .Net Framework project and select Manage Nuget Packages...->Search and download Microsoft.Powershell.5.ReferenceAssemblies) to check if the problem can be solved.

How can I add Excel 2010 (14) PIA to a .NE 3.5 project?

I'm using VS 2012.
The MS Office installed is 2013 x64.
I've downloaded and installed the Office 2010 PIA.
At the VS:
I can only add references to
Microsoft.Office.Core
Microsoft.Office.Interop.Excel
if the project is set to .NET 4.0, not 3.5.
And to do this in the .NET 4.0 project:
((Excel.Worksheet)xlWorkBook.Sheets1).Delete();
I need to add Microsoft.CSharp
In another PC, using VS 2010 and with Excel 2010 x64 installed. I was able to create a project without the Microsoft.CSharp library and the Office PIA is available in .NET 3.5.
So, how can I create a .NET 3.5 project using Excel 2010 (14) PIA in VS 2012 ? What I'm missing here?
I think I repro this problem. This goes wrong when you start with a project that targets .NET 4 and then change the Framework Target to 3.5. The <HintPath> element is missing in the project file, needed by MSBuild version 3 to find the interop assembly.
And the PIA indeed doesn't show up in the assembly list when you target 3.5, it isn't configured to look in the directory where the PIA is stored. So it is simply missing from the list.
Microsoft.CSharp is a very similar story, it is only available as a .NET 4 assembly. It is the support assembly for the dynamic keyword. So when you switch to 3.5, it is going to complain about an assembly whose metadata it cannot read.
Going forward always works better than going backwards in the time. The workaround is simple enough. Just remove Microsoft.CSharp from the referenced assemblies, you will not need it. Or better yet, start your project with 3.5 selected so it never gets added. And to add the Office interop assembly, use Project + Add Reference, click the Browse button. Navigate to the C:\Program Files (x86)\Microsoft Visual Studio 11.0\Visual Studio Tools for Office\PIA\Office14 directory and select Microsoft.Office.Interop.Excel.dll. The HintPath element is now properly written and MSBuild will be happy.

Targeted my project in Visual 2010 to .Net 4.0 but the system still looks for the dll 'System.Core version 2.0.5.0'

My project targets .Net 4.0 Client profile but it crashes as soon as it starts by displaying a file load exception stating that System.Core version= 2.0.5.0 . How can I change that?
Edit: Forgot to add, it's a WPF project.
This is mainly for future me, who will at some point come back to this question, and none of the current answers will solve your problem (hey future me!)
My issue was a nuget package referencing System.Core 2.0.5.0 so I had no control over the reference.
To get System.Core 2.0.5.0 installed on the machine, which already had .NET 4.0 installed and patched, I installed the Portable Class Library.
To install the Portable Class Library tools on a build machine without installing Visual Studio 2012, download the Portable Library Tools, and save the download file (PortableLibraryTools.exe) on your computer. Run the installation program from a Command Prompt window, and include the /buildmachine switch on the command line.
I had a problem similar to this that only occurred on windows XP/Server 2003 while Windows 7/Server 2008 and later worked fine. After a long time of looking I ran into this article:
http://code.google.com/p/autofac/wiki/FrequentlyAskedQuestions
It suggested downloading the following hotfix
http://support.microsoft.com/kb/2468871
After installing that everything worked fine! Maybe give that a try and see if it helps.
Probably you included reference to some libraries belonging to .Net 2.0 and they depends on System.Core 2.0. So you need to check every reference's version number included in your project.
Make sure that System.Core in References targets version 4. Also, make sure Specific Version is false. You could also try to remove the reference to System.Core and then add it again.
Open the references section in solution explorer, delete the System.Core
Right click on the References and add a new one, locate System.Core v4.0 and add that one.
I was able to fix a similar error by installing Framework 4.0 UPDATE kb2468871
Direct link: http://www.microsoft.com/en-us/download/details.aspx?id=3556
Info Link: http://support.microsoft.com/kb/2468871

Error when using Symbol/Motorola Fusion dll - WinCE 6.0

When I run any project from Visual Studio, it works excellent (on Motorola MC 3190 - WinCE 6.0)
However, when I install and run the application on the device, I get this error:
No compatible FusionInterface dll found, Expected version is 4.1.0.1 or higher version having the format 4.x.x.x
What could be the problem?
In my case, deploying Symbol.Fusion.dll and FusionInterface.dll files in the same directory than my executable has resolved this error.
You must install the symbol.all.arm.cab file. If you are using Windows CE then you need the armv4 version. If you are using Windows Mobile, then you need the armv4i version.
Also, make sure there is no local copy of the DLLs in your application's directory; this could be possibly causing a version mismatch.
Adding a reference to Symbol.ResourceCoordination worked for me. Per the CS_FusionSample1 code example included with the Motorola EMDK v2.9, the relevant Symbol references are Symbol, Symbol.Fusion, and Symbol.ResourceCoordination.
Note, I'm building for a Motorola 9190 handheld under Windows CE 6.0.
Fusion Interface DLL Version Compatibility
EMDK for .NET access Fusion Public API via Fusion interface DLL as mentioned in the Overview section. There can be different versions of Fusion Public API and in return many versions of Fusion Interface DLLs.
Version Incompatibility Issue
If this DLL is incompatible with EMDK, an appropriate meaningful error message will be provided in the exception when trying to access Fusion. This occurs when creating Config and WLAN objects.
Possible Messages
Older and incompatible FusionInterface dll 1.0.0.1 found. Expected version is 2.0.0.3 or higher version having the format 2.x.x.x
Newer and incompatible FusionInterface dll 3.1.0.5 found. Expected version is 2.0.0.3 or higher version having the format 2.x.x.x
Solution
The DLL version incompatibility arises because of the two files (Fusion Interface DLL and the Fusion Assembly DLL) taken from different EMDK packages. To fix the issue,
Method 1:
Remove "Symbol Managed Class Libraries" using "Remove Programs" in the control panel of the device.
Check "\Windows" folder of the device for any existence of "FusionInterface.dll" and if so, delete it.
Take the "symbol.all.arm.cab" from EMDK installed location, copy to the device and run installation.
The typical location is the appropriate sub directory (wce400\armv4 or wce500\armv4i) of "\Program Files\Enterprise Mobility Developer Kit for .NET\v2.x\SDK\Smart Devices".
Run the application.
Method2:
Copy the appropriate DLL to the \Windows directory of the device.
Run the application
Note: This DLL is not separately available in the EMDK for .NET package.

Can't find System.Workflow assembly in .NET. How do I get it?

I've installed a complete SharePoint Server (MOSS) 2007 on my dev box + the latest Visual Studio (SP1) + the latest full Windows SDK. According to the Windows Workflow Foundation page http://msdn.microsoft.com/en-us/netframework/dd980558.aspx, that is all I should need to do to be able program against the .NET Workflow APIs.
And yet, all of the projects I build from the standard Workflow templates refer to the assembly System.Workflow and VS complains that that assembly isn't available. I've searched around on my hard drive, and I can't find a file for that assembly anywhere obvious on my disk.
I do find some files that look like they might be that assembly, but they're buried down in wacky places below particular applications like they are runtime support for that app. They don't seem to be what I'm supposed to point VS at.
Can anyone tell me how to fix this problem? Do I need to install something else that I have yet to come across? Are these assemblies already on my system and I just need to know how to point VS at them? I'm stumped.
BTW: I was going to try uninstalling and reinstalling VS, but the installer fails with some very cryptic error message when I try to uninstall.
TIA for any help, and Happy Holidays to all!!!
I did a Repair using the .NET 3.5 SP1 SDK distributable, and I believe that this solved the problem. I thought at first that it didn't (as I say in prior comments) because I was looking for the files to show up in the v3.5 assembly directory. The missing files actually go in the v3.0 assembly directory. I later brought up one of the sample projects in VC and noticed that the symbols were now resolving, and sure enough, the missing .dll files were now present.
So I guess that the .NET SDK installer that ships with VS somehow didn't install these .dll files. It took doing a Repair on the SDK to fix the problem.
I'm a happy camper now!
In addition to change the target framework to 4.0, you also need to:
Add a reference to System.Workflow.Runtime
Add a reference to System.Workflow.ComponentModel
There's no assembly named System.Workflow in .NET 3.x: the WF assemblies (in 3.x) are:
System.Workflow.Runtime
System.Workflow.ComponentModel
System.Workflow.Activities
System.WorkflowServices (3.5)
You should be able to find all these assemblies in the GAC, and reference them via the Add Reference dialog, .NET tab.
It's possible System.Workflow is a (badly named) SharePoint-specific DLL, in which case, sorry, the above won't help... try the SharePoint install directory or SharePoint SDK install directory. Are the project templates you're using SharePoint templates, or the ones from File > New Project > Visual C# > Workflow?
I have a same problem, and solved it. The reason is your project's target .net framework not include this assembly (it's maybe .net 3.5 client profile or 4.0 client profile). The solution is very simple: set the target framework of your project to .NET Framework 3.5 or 4.0.
It work for me.
Please find it in C:/Windows/Assembly/GAC_MSIL
All the DLLs are Present there..
Also If U donot Find it then do the Following
Right Click Project->Application->Target Framework-> .Net Framework 4.0
It should show Up then.

Categories

Resources