Issue loading assembly

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 3 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Skywayskase
Posts: 2
Last visit: Mon Mar 15, 2021 2:23 pm

Issue loading assembly

Post 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.
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 11:13 am
Answers: 39
Been upvoted: 30 times

Re: Issue loading assembly

Post 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).
Brittney
SAPIEN Technologies, Inc.
Skywayskase
Posts: 2
Last visit: Mon Mar 15, 2021 2:23 pm

Re: Issue loading assembly

Post 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?
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 11:13 am
Answers: 39
Been upvoted: 30 times

Re: Issue loading assembly

Post 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?
Brittney
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Issue loading assembly

Post 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.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 3 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.