简体   繁体   中英

error powershell c# visual studio

I have got a simple class libary project in visual studio:

using System;
using System.Linq;
using System.Management.Automation;

namespace EdoX_auslesen_xml
{
    [Cmdlet(VerbsCommon.Get, "DemoNames")]
    public class Get_DemoNames : Cmdlet
    {
        [Parameter(Mandatory = false)]
        public string Prefix;

        protected override void ProcessRecord()
        {
            var names = new string[] { "Chris", "Charlie", "Anne" };
            if (string.IsNullOrEmpty(this.Prefix))
            {
                this.WriteObject(names, true);
            }
            else
            {
                var prefixed_names = names.Select(n => this.Prefix + n);
                this.WriteObject(prefixed_names, true);
            }

        }
    }

}

When I open PowerShell an try to "Get-DemoNames" an error occurs:

在此处输入图片说明

in English:

Get-DemoNames: the file or assebly "System.Runtime, Version=4.2.0.0. Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" or a dependency of it was not found. The system cannot find the given file. In line:1 sign:1 + Get- DemoNames...

I think you need to add a reference to System.Runtime.

View this StackOverflow question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM