Closed youyuanwu closed 10 months ago
Would specifying System32 | ApplicationDirectory | AssemblyDirectory
be sufficient here? If not, what would be required?
FabricCreateLocalClient
function comes from FabricClient.dll
. This dll lives inside directory C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code
and is in the system env:PATH variable.
So to make this work the code needs to find FabricClient.dll in the right directory. I am not familiar with the dll searching in cs. But given the generated code, I think
[DefaultDllImportSearchPaths("C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code")]
might work? Is it possible to look up dll in the system PATH like native application?
You can't specify a path like that. The attribute only takes a flags enum. You can see the options here.
I'm not aware of any setting that will simply search all the directories in PATH for dependencies, even in native applications. I think native apps have the same set of options that is exposed to .NET applications through that enum.
Note that, per the docs in the enum, an AddDllDirectory
win32 function exists whereby you can explicitly add a directory to the dll search path. Then you'd need to set the UserDirectories
flag on the enum so that .NET would honor that.
Frankly though, I think the simplest path for you may be to find the file yourself and load it using LoadLibrary
. Once loaded, these p/invokes will work regardless of this enum.
Using "LoadLibrary" suggested solved the issue.
The generated code marks the dll import search path to be system32 path. But the dll lives in
C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code
So, when using these functions, this error is encountered.
The specified module could not be found.
The solution is to support custom values for "DefaultDllImportSearchPaths" in the generated code.
More details can be found here: https://github.com/youyuanwu/service-fabric-cs/issues/2