Page 1 of 1

Issue loading assembly

Posted: Wed Mar 18, 2020 2:52 pm
by Skywayskase
Product, version and build: Powershell Studio 2020 (5.7.173)
32 or 64 bit version of product:64 bit
Operating system: Windows 10 Enterprise 1903
32 or 64 bit OS: 64 bit

I'm trying to build a module that is essentially a wrapper for a C# SDK. When I add the assembly and its required assemblies (one of which is Newtonsoft.Json) I get the following error when trying to call on the classes within the assembly:
Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I'm able to load the assemblies and tab-complete the contained classes in the regular Powershell host. I can also add the assemblies in VSCode and utilize intellisense, but I'd like to use Powershell Studio to build the module and have PrimalSense recognize the classes as well.

Re: Issue loading assembly

Posted: Thu Mar 19, 2020 7:03 am
by brittneyr
From the error message, it appears that there might be a mismatch of assemblies. Please verify that the assemblies you are trying to reference are all the correct versions along with their dependencies and compiled the same (x64 or x86).

Re: Issue loading assembly

Posted: Thu Mar 19, 2020 8:23 am
by Skywayskase
Honestly, this type of project is new to me. I've never worked with SDKs before, and I've never scripted against compiled DLLs. I used Nuget to download the assembly I'm trying to base this module around, Nuget downloaded it and the dependent packages, I copied the DLL files out of the netstandard2.0 folder for each downloaded package, and one at a time used "Add-Type -Path $pathToDLL" starting with the dependent packages and finishing with the one I'm actually trying to build this around. I went to Github and looked at the .csproj file and verified there's a PackageRefernce item for each of the dependent packages I'm adding first, and that the version referenced in the .csproj file is the same as version the DDLs claim to be. I'm probably in over my head, but I thought this would be a cool project and a useful one for myself and others (if I could get it to work).

Something I'm still unclear on is why does VSCode and the PWSH host seem to load the DLLs just fine, but Powershell Studio doesn't?

Re: Issue loading assembly

Posted: Wed Mar 25, 2020 7:29 am
by brittneyr
Without actually seeing what you are doing, there are many reasons why this could be happening. Are the paths you are using with you use 'Add-Type' the full path to the dll? Do you have all the same dlls required listed that you added in VS Code?

Re: Issue loading assembly

Posted: Wed Apr 01, 2020 10:50 pm
by Alexander Riedel
If you google the issue, you will see that there is a widespread issue with this assembly and its different versions.
You use something that requires a different assembly version than what you load. Error messages are not generally helpful in such cases
I would go hunt down all instances of that assembly and move them one by one to see which one gets actually loaded.
It would also help to know more about what SDK you want to wrap.