Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.DllNotFoundException caused by dynamically linked CRT #1440

Open
CliffCawley opened this issue Sep 10, 2023 · 8 comments
Open

System.DllNotFoundException caused by dynamically linked CRT #1440

CliffCawley opened this issue Sep 10, 2023 · 8 comments
Assignees
Labels
Bug Something isn't working

Comments

@CliffCawley
Copy link

Environment

How do you use Sentry?
sentry.io through Unity

Which version of the SDK?
1.5.1

How did you install the package? (Git-URL, Assetstore)
Unity Package Manager

Which version of Unity?
2022.3.8f1

Is this happening in Unity (editor) or on a player like Android, iOS, Windows?
Player, Windows 10 IL2CPP Production build

Steps to Reproduce

Difficult to reproduce, because this is happening in the wild, but the issue seems to be because you're compiling sentry.dll with the dynamic CRT linked in. This means we're required to ensure that the user has the correct CRT runtimes installed too.

Would be great if it was possible to statically link the CRT instead, so that we don't need additional runtimes installed:

Using depends you can see the currently dynamically linked dlls (see below)

On systems that don't have this installed, but run our IL2CPP Unity game just fine, we experience the System.DllNotFoundException

Expected Result

No exception

Actual Result

System.DllNotFoundException
Unable to load DLL 'sentry'. Tried the load the following dynamic libraries: Unable to load dynamic library 'sentry' because of 'Failed to open the requested dynamic library (0x06000000) - The specified module could not be found. (WinError:0000007e)

Any logs or screenshots

image

@bitsandfoxes
Copy link
Contributor

Hey, sorry to see you run into issues.
This is the first time this has come up. I'll have to look into that. Do you know anything more about those environments this is happening on?

@CliffCawley
Copy link
Author

Hey, sorry to see you run into issues. This is the first time this has come up. I'll have to look into that. Do you know anything more about those environments this is happening on?

90% are from Windows 10.0.19045
4% from Windows 10
3% from Windows 11

It seems to be a mix of machines and, various languages.

Some devices that appear:
HP Pavilion Power Desktop 580-1xx (HP)
X555LJ (ASUSTeK COMPUTER INC.)
20LTS2SW00 (LENOVO)

The issue here is that sentry is trying to reference dlls that don't exist on those systems, since sentry is linking to a specific version of the libraries.

I believe the fix is simple: statically link to the libraries, instead of dynamically link.

@CliffCawley
Copy link
Author

CliffCawley commented Sep 25, 2023

Just to add to this, it looks like you have a dependency on the native sentry library, and the docs there have the following:

The following options can be set when running the cmake generator, for example using cmake -D BUILD_SHARED_LIBS=OFF ...
SENTRY_BUILD_SHARED_LIBS (Default: ON): By default, sentry is built as a shared library. Setting this option to OFF will build sentry as a static library instead. If sentry is used as a subdirectory of another project, the value BUILD_SHARED_LIBS will be inherited by default. When using sentry as a static library, make sure to #define SENTRY_BUILD_STATIC 1 before including the sentry header.

So the built sentry dll that you're relying on, has been built as a shared library. You'll want to build it with SENTRY_BUILD_SHARED_LIBS set to OFF so that it's built as a static library instead.

I think that will solve it, but I could be wrong

@bitsandfoxes
Copy link
Contributor

Hey, thanks for providing all the extra context.
Just to confirm: This is caused by sentry-native trying to capture a native crash? Do you maybe have a callstack for the System.DllNotFoundException?

@CliffCawley
Copy link
Author

CliffCawley commented Oct 23, 2023

@bitsandfoxes Sorry for the slow reply, it seems my github notifications haven't been working, should be fixed now.

This is using the Unity sentry library (This github).

The callstack appears to be:

System.DllNotFoundException: Unable to load DLL 'sentry'. Tried the load the following dynamic libraries: Unable to load dynamic library 'sentry' because of 'Failed to open the requested dynamic library (0x06000000) - The specified module could not be found.  (WinError:0000007e)
  Module "Sentry.Unity.Native.SentryNativeBridge", in Init
  Module "Sentry.Unity.Native.SentryNative", in Configure
  Module "Sentry.Unity.SentryInitialization", in Init

The Unity log reveals only that it was called immediately after the app loads:

image

@stephanie-anderson
Copy link

Thanks for the details, @CliffCawley - we'll have a look at this by the end of this week.

@bitsandfoxes
Copy link
Contributor

I think that's a fair request. Especially on desktop platforms the increase in size should be alright?
I'll make that work.

@CliffCawley
Copy link
Author

Thanks @bitsandfoxes, that would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
Status: No status
Status: No status
Development

No branches or pull requests

3 participants