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 8372145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:20:57+00:00 2026-06-09T14:20:57+00:00

I’m working on a project to integrate a custom made c# .DLL into powershell.

  • 0

I’m working on a project to integrate a custom made c# .DLL into powershell. However, I’m having problems
with casting the C# Objects into a form that PowerShell can understand which it cannot. I’ve searched google
like a million times and tried a few different things but none of them were succesfull.

The following error occurs when I’m calling SNC-getVlan with an array of objects:

“Exception calling “printObject” with “1” argument(s): “Unable to cast object of type ‘System.Management.Automation.PSObject’ to type ‘Objects.blablazzz.DC_Object'”

I’m posting some small subsets of my code hoping you guys can see what I’m doing wrong.

Classes I’m using:

public class DC_Object
{
    public string name = "undefined";
}

public class Cmdb_Host : DC_Object
{
    //Lots of properties
}

public class Cmdb_Vlan : DC_Object
{
    //Lots of properties
}

Function that prints the objects:

public static void printObject(Object[] objects)
{
    foreach (Object o in objects)
    {
        string name = ((DC_Object)o).name; //I'm assuimg things go wrong in here.

The fromJSON function is the function that actually returns the object that is sent into printObject, not sure
if it matters but I’ll post it anyways.

static public Object[] fromJSON(string input)
{
    //Check the string to see to what object it should convert to
    switch (input.Substring(0, 16))
    {
        //Reuest for a host (Host Table)
        case "{\"u_cmdb_ci_host":
            if (input[18] == '[') // We have an array
            {
                Container_Host c_host = JsonConvert.DeserializeObject<Container_Host>(input);
                return c_host.u_cmdb_ci_host;
            }
            else    // We have a single object
            {
                Container_Host_Single c_host = JsonConvert.DeserializeObject<Container_Host_Single>(input);
                Container_Host h = new Container_Host();
                h.u_cmdb_ci_host = new Cmdb_Host[1];
                h.u_cmdb_ci_host[0] = c_host.u_cmdb_ci_host;
                return h.u_cmdb_ci_host;
            }
        //Request for a VLAN (Network Table)
        case "{\"cmdb_ci_ip_net":
            Container_Vlan c_vlan = JsonConvert.DeserializeObject<Container_Vlan>(input);
            return c_vlan.cmdb_ci_ip_network;
    }

    return null;
}

Powershell Module/Script:

#Loads in the custom DLL created for this specific project.
[Reflection.Assembly]::LoadFrom(“C:\Users\Joey\Documents\PSScripts\DataCollector\DataCollect.dll”)

# Creates a new Client object that handles all communication between the PowerShell module and the
# sncdb-worker at server side.
$client = new-object blablazzz.Sender;
[blablazzz.Config]::Configure("C:\Users\Joey\Documents\PSScripts\DataCollector\asp4all.ini")
$client.Connect();

# This functions returns a Host Machine (Virtual or Physical) in object notation to    for easy post-processing
# in PowerShell. 
Function SNC-GetHost($hostz = "blabla")
{
    return $client.sendMessage([blablazzz.Parser]::getHost($hostz));    
}

# This function returns VLAN information in object notation. This is a collection most     of the time.
function SNC-GetVLAN($vlan = "TLS-TL2-CPH-TEST")
{
    return $client.sendMessage([blablazzz.Parser]::getVlan($vlan));
}
Function printObject($hostz)
{
    [blablazzz.Formatter]::printObject($hostz)
}

PowerShell commands (dll is already loaded):

PS C:\$variable = SNC-Get-VLAN
PS C:\printObject($variable)

I’ll have to note that my printDebug function works fine when used on SNC-getHost but doesn’t work on
SNC-getVlan, SNC-Get-Vlan returns an array of values while SNC-getHost only returns one value (it’s still
in an array though but it doesn’t look like PowerShell kept it in an array).

  • 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-09T14:20:59+00:00Added an answer on June 9, 2026 at 2:20 pm

    For the people who might come across the same problem. The solution was to change the return value of my functions and the arguments to DC_Object since this is the top encapsulating object. This solved all casting problems.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.