Click here to Skip to main content
15,791,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi , I'm trying to execute C# code in Power Shell 2.0 .

My problem is for the references  at the beginning of the code:

$code = @"

using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Xml;<code></code>
using System.Xml.Linq;

   public class Program
        static void Main()
        {  /* the code wich works*/



Add-Type  -TypeDefinition $code -Language "CSharpVersion3"

Powershell gives me an error saying that " The type or namespace Linq doesn't exist" , and the same for Xml. I have Visual studio express 2013 .

How can add or import correctly those references? or what is my error?
Updated 16-Apr-14 22:43pm

1 solution

You're not providing a whole lot of information. What errors are you seeing?
Anywho, try this for your Add-Type line and see how far that takes ya:

Add-Type -TypeDefinition $source -Language CSharp -ReferencedAssemblies System.Xml, System.Xml.Linq
Share this answer
Kinna-10626331 21-Mar-14 8:07am    
I just added more info , I tried with your but the errors still the same.
notjustme 21-Mar-14 9:01am    
What PowerShell version are you using and as what user are you trying to run this? As long as the referenced assemblies are in the GAC this should be possible.

Do you get any useful information if you run the following line in PowerShell;

Kinna-10626331 21-Mar-14 9:16am    
Its 2.0, with the user administrator and when I run your line nothing happens.
notjustme 21-Mar-14 9:34am    
If you find the full path for the dlls you should be able to load them.
notjustme 17-Apr-14 10:24am    
Editing your original question and not adding any more information won't really help you.

By finding the exact path to the actual DLLs I can get your code to load;

Add-Type -TypeDefinition $source -Language CSharp -ReferencedAssemblies "C:\Here\Are\My\dlls\System.Xml.dll", "C:\Here\Are\My\dlls\System.Linq.dll" etc, etc.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900