x


DllNotFoundException only on first run

I've been working with plugins for some time now but recently I've encountered a problem I've not come across before.

In the editor, I get a DLLNotFoundException the first time I try to start. After getting this error, if I stop and start again everything works fine. If I restart Unity then I get the same error on on the first time I run.

In standalone this has the effect that the Dll is never found as every time you start the application is the first time.

Anyone heard of this problem before? Any ideas as to what it could be? The Dll is definitely there and it does find it on subsequent runs in the editor.

Thanks.

more ▼

asked Jul 13 '12 at 11:12 AM

HazeTI gravatar image

HazeTI
346 9 14 17

Name of the not-found DLL?

Jul 13 '12 at 01:19 PM Kryptos

Sorry, should've made it clear that it's my own plugin DLL that is causing the error. It is placed in Assets/Plugins and it is found & used correctly on subsequent runs.

Jul 13 '12 at 01:34 PM HazeTI

I'm still having this issue, still a bit lost on what could be wrong. No one got any ideas?

Jul 16 '12 at 08:19 AM HazeTI
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Right, caught it. Realised my mistake. The plugin in question has a a dependency on another Dll. It was that Dll which was causing the error. I needed to call a function of the dependent Dll first so that it is loaded before calling anything in my own Dll.

I knew all this of course, I'd dealt with it before.

more ▼

answered Jul 16 '12 at 09:10 AM

HazeTI gravatar image

HazeTI
346 9 14 17

Good to know. Can you give more hints on how you achieved that? Did you use Assembly.LoadFrom or another method?

This can be useful for people who will encounter the same issue.

Jul 16 '12 at 11:35 AM Kryptos

In my case I'm still using DllImport:

[DllImport(<dependent dll>)]
private static extern bool SomeFunction();

[DllImport(<my dll>)]
private static extern bool SomeOtherFunction();

Both Dll's are placed in Assets/Plugins and I make sure so call SomeFunction first before calling anything from my own plugin.

I did not think about using Assembly.LoadFrom. That may be a better idea...

Jul 18 '12 at 09:39 AM HazeTI

I'm not an expert with loading external resources. But it seams that DllImport is a generic method to load unmanaged code (from any DLL), whereas Assembly.LoadFrom only works with CLI-managed code (that could also be embedded inside a DLL).

Jul 18 '12 at 09:49 AM Kryptos
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x394
x232

asked: Jul 13 '12 at 11:12 AM

Seen: 426 times

Last Updated: Jul 18 '12 at 09:49 AM