6

I've got a library consisting of two parts - One .net assembly that P/Invokes to a native 3rd party dll. In desktop mode this works just fine: However, when referencing the assembly from a Metro style app and running it, it throws a System.DllNotFoundException on the P/Invoke complaining that "Unable to load DLL 'library': The specified module could not be found."

The native dll does not do anything special but only creates out-going TCP/IP connections to a server. The system cannot know this, but rather the native dll could do anything. This is why I suspect it might not be possible to do this.

Some dll search order is mentioned on msdn regarding Metro style apps, hinting about it is possible to load native dlls?

Also I found this link on msdn talking about loading "libraries" and mentions the PackageDependency in the manifest file, but to me it's still unclear how to add a native dll to the package in a way that it is possible to P/Invoke it.

vidstige
  • 12,492
  • 9
  • 66
  • 110
  • Can you try commenting out the TCP/IP stuff in the DLL and testing again? That will distinguish not finding the DLL from not findind its dependencies. Also, did you check off on Capabilities that you want to use the outgoing Internet connection? – Kate Gregory Oct 20 '11 at 11:56
  • I did not build the dll. It's not part of the solution. So I cannot change the way the dll was build. Good point that it might be some secondary dependency causing the error! Will check this out asap. – vidstige Oct 20 '11 at 12:54
  • 1
    @vidstige You have probably solved this issue by now, but otherwise please have a look at [my answer](http://stackoverflow.com/a/12122750/650012) to a related question. – Anders Gustafsson Aug 25 '12 at 14:21
  • @AndersGustafsson I switched jobs in between so I cant try it :-S. I'm pretty sure this was one of the first things I tried. – vidstige Aug 27 '12 at 07:28

2 Answers2

0

This is probably by design. Your problem might be caused by an error with error code 126 being returned from LoadLibrary. If your application runs in desktop mode you should target desktop mode for your application. You might use an earlier version of Windows as well.

Norbert Willhelm
  • 2,579
  • 1
  • 23
  • 33
0

Add it to your project (right click project, Add, Existing Item.) Check that in the properties of that item, Content is set to True (it is false by default.) Build.

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
  • Thanks for your answer. This works in a normal c# environment, but I tried it and could not get it to work on the Metro-project. – vidstige Oct 19 '11 at 07:10
  • 1
    Describe "not working" - compile error? mystery green screen on launch? exeption thrown while running? – Kate Gregory Oct 19 '11 at 12:43
  • 1
    I updated the question with a specific error message! The exception is thrown when calling the method with the P/Invoke attribute. – vidstige Oct 20 '11 at 06:49