Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:14:19+00:00 2026-06-13T02:14:19+00:00

I have the following powershell script: # C-Sharp source for taking our screenshot $Source

  • 0

I have the following powershell script:

# C-Sharp source for taking our screenshot
$Source = @" 
using System;
using System.Linq;

namespace Testing
{
    public static class TestClass
    {
        public static void DoTest()
        {
             var myLinq = "hello world";
        }
    }
}
"@

$assem = @("System.Core")
$null = Add-Type -ReferencedAssemblies $assem -TypeDefinition $Source -Language Csharp

If I run this via powershell.exe powershell.exe C:\test.ps1 I get the following error:

Cannot add type. There were compilation errors. c:\Users\Administrator\AppData\Local\Temp\c9er05ba.0.cs(10) : The type or n
amespace name 'var' could not be found (are you missing a using directive or an assembly reference?)

c:\Users\Administrator\AppData\Local\Temp\c9er05ba.0.cs(9) :         {

c:\Users\Administrator\AppData\Local\Temp\c9er05ba.0.cs(10) : >>>              var myLinq = "hello world";

c:\Users\Administrator\AppData\Local\Temp\c9er05ba.0.cs(11) :   }

However, if I copy and paste this script into PowerGUI it runs just fine.

The closest link I could find that was helpful was this one. So I tried changing my -language parameter to be csharpversion3, but now I get this:

Cannot add type. There were compilation errors. (0) : An assembly with the same identity 'System.Core, Version=3.5.0.0, Cul
ture=neutral, PublicKeyToken=b77a5c561934e089' has already been imported. Try removing one of the duplicate references.

(1) : using System;

Any ideas how I can get this script to run properly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:14:20+00:00Added an answer on June 13, 2026 at 2:14 am

    Stick with the -language csharpversion3 but drop the -ReferencedAssemblies $assem bit – that’s what’s giving you the duplicate import.

    I also had to add -IgnoreWarnings to get your fragment to compile, but I guess that’s because you’re not posting the whole example.

    In summary, the command:

    Add-Type  -TypeDefinition $Source -Language CsharpVersion3 -IgnoreWarnings
    

    will compile that code without error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Powershell code: Add-Type -Assembly System.Configuration [ExeConfigurationFileMap] $configMap = New-Object ExeConfigurationFileMap
I have the following script, $createZip = { Param ([String]$source, [String]$zipfile) Process { echo
I have the following PowerShell script that will parse some very large file for
I have a powershell script with the following code in it... $appdir = Split-Path
I have a powershell script in which I do the following $somePSObjectHashtables = New-Object
I have the following tiny PowerShell script that's meant to kill some certain processes
i have following situation: a powershell script with this variables: $RUBY = C:\installing\ruby\bin\ruby.exe $ARGS
I have the following snippet of PowerShell script in my profile: . (join-path (split-path
In a PowerShell script automating some SVN tasks I have the following function: function
I have the following code snippet from my PowerShell script that... Loops through a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.