Unable to load the WITDataStore64 dll

4

I'm trying to run a PowerShell script, and I have to load several assemblies to accomplish my task. Most assemblies are loading fine, but there's one I'm having trouble getting to work:

Microsoft.VisualStudio.Services.Common.dll

I've tried a few different approaches.

I've tried the LoadFrom, ReflectionOnlyLoadFrom, and Add-Type -Path Methods, but they all return an error saying

Could not load file or assembly 'path\Microsoft.WITDataStore64.dll' or one of its dependencies. The module was expected to contain an assembly manifest...

FulllyQualifiedErrorID : BadImageFormatException

I've tried ReflectionOnlyLoad, but that just returned an error saying

Exception calling "ReflectionOnlyLoad" with "1" argument(s): "Could not load file or assembly '$pathToDlls\\Microsoft.WITDataStore64.dll' or one of its dependencies. The given assembly name or codebase was invalid.

(Exception from HRESULT: 0x80131047)"

The path is correct - I have visually confirmed that the file is there - and the name of the dll is correct as well (copy-pasted the filename just to be sure). Other dlls are loading just fine; it's just this one that isn't loading.

Microsoft has a documents page about this exception, and it suggests that I should "[a]ccess the methods defined in the DLL by using the features provided by your development language." I think it assumes that I'm using something more than just PowerShell. If there is a way to access the DLL's methods through powershell, I am unaware of it.

What is making this dll in particular so much trickier to load, and how can I get it to load?

powershell
asked on Stack Overflow Jul 16, 2019 by MrSpudtastic • edited Jun 20, 2020 by Community

1 Answer

1

The error you are getting is that some code is trying to load a native dll (which lacks the magic bits that make it a CLR assembly) as an assembly.

The assembly Microsoft.VisualStudio.Services.Common.dll can be obtained at different versions via nuget, and might be installed on the local computer at any version.

I also see some related questions regarding problems and bugs loading the same assembly.

I was able to load an old version of the package from NuGet to a local folder and access it in powershell:

  • Install .net core SDK (2.0 or above)
  • Install .net 4.5.2 Developer Pack
  • Create a blank folder
  • Open a powershell prompt in the folder

Then run:

dotnet new console --target-framework-override net452
dotnet add package Microsoft.TeamFoundationServer.ExtendedClient -v 14.89.0
dotnet build .
add-type -Path .\bin\Debug\net452\Microsoft.VisualStudio.Services.Common.dll
[microsoft.visualstudio.services.common.VssEnvironment]::GetTfsSharedFilesPath()

If this works, you'll probably want to switch it to use nuget.exe - this doesn't require the SDKs to be installed but I don't know how to use it.

answered on Stack Overflow Jul 25, 2019 by Peter Wishart

User contributions licensed under CC BY-SA 3.0