Dotnet Core library issue

This topic contains 2 replies, has 3 voices, and was last updated by  js 3 months, 3 weeks ago.

  • Author
    Posts
  • #97161

    BlackBoxCoder
    Participant

    Howdy,
    I am totally new to dotnet core.
    I generated a new Folder on my drive, after this I executed this command:
    Donet new classlib -o DLL-Test
    after this I went to the Project Folder and changed the class1.cs file like this:

    using System;
    
    namespace dll_test
    {
        public class Class1
        {
            public static string NewString(){
                return "Newstring";
            }
        }
    }
    

    after this I added the powershell lib like this:
    dotnet add package PowerShellStandard.Library –version 5.1.0-preview-02

    finally i build the dll, which is now showing up:
    dotnet build

    and now I try to Import this via powershell by add-type and specify the source of the file.
    BUT I get an error which is complaining about: At least one type in the assembly could not be loaded.

    Did you had this strange issue before OR you can see directly what i am doing wrong?

    Cheers,
    BlackBoxCoder

  • #97212

    Don Jones
    Keymaster

    Unfortunately, this isn't a .NET forum – you might have better luck getting a good answer someplace like StackOverflow. This website is dedicated to PowerShell.

  • #97218

    js
    Participant

    Works for me.

    $env:path += ';C:\Windows\Microsoft.NET\Framework64\v4.0.30319'
    csc /t:library class1.cs
    
    add-type -path '.\class1.dll'
    [dll_test.Class1]::NewString()
    
    Newstring
    

You must be logged in to reply to this topic.