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

Unhandled Exception: System.IO.FileNotFoundException #11

Open
xnetdude opened this issue Oct 7, 2020 · 7 comments
Open

Unhandled Exception: System.IO.FileNotFoundException #11

xnetdude opened this issue Oct 7, 2020 · 7 comments

Comments

@xnetdude
Copy link

xnetdude commented Oct 7, 2020

Hi,

Really can't find the issue here,

I have a working install on dev system with the YARA engine but when deployed the TestApp (from this project) to a server I get this:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'libyara.NET.dll' or one of its dependencies. The specified module could not be found.

Have done all the usual dependency walking stuff, checking the file isnt locked (or obv missing) but still no joy.

I resorted to installing a new copy of VS2017 onto a virgin Windows Server 2016 box and then compiled this project and abd the TestApp aworked! Copy all the contents of microsoft\libyara.NET\TestApp\bin\x64\Debug to problem server and get the same error.

For me, it's either VS2017 is installing some dependency which this library needs or there is some lock to the machine it's compiled on - either way I can't figure it out so really appreciate any help or guidance on this.

Thanks.

J.

@swannman
Copy link
Member

swannman commented Oct 8, 2020

Hi @xnetdude, a couple of questions:

  • What version of .NET is installed on the target server?
  • Does TestApp fail if it imports the Microsoft.O365.Security.Native.libyara.NET nuget instead of referencing libyara.NET.vcxproj directly?

Thanks,
Matt

@xnetdude
Copy link
Author

xnetdude commented Oct 8, 2020

*** updated after installaling the correct nuget package ***

Hi Matt,

Thanks for your reply.

We have .net 4.7 on both test servers. One where we installed VS2017 and then the TestApp worked, and then we simply copied the contents of the microsoft\libyara.NET\TestApp\bin\x64\Debug to the second server where it showed the error in my OP.

Referencing Microsoft.O365.Security.Native.libyara.NET and removing libyara.dll from the TestApp works without error, what does this tell us?

Greatly appreciate any more thoughts.

Thanks.

James.

@xnetdude
Copy link
Author

xnetdude commented May 5, 2021

Hi Matt - still seeing this with directly using the nuget package both x86 and x64:

Could not load file or assembly 'libyara.NET.dll' or one of its dependencies. The specified module could not be found. :

Any further thoughts?

TIA.

@admiralbenbou
Copy link

@xnetdude Hello. I met this issue and revealed that Visual C++Redistributable is need for libyaranet to work. Installation of it resloved my issue.

@DestroyerDarkNess
Copy link

I have the same problem, when I use nuget package "Microsoft.O365.Security.Native.libyara.NET" it works perfectly.

But if I download and compile the "libyara.dll" library normally and add it to my project, it gives this same error and I have not found how to solve it.

I hope you can help me. Thank you.

@MIAIONE
Copy link

MIAIONE commented Oct 15, 2023

I have encountered the same issue. When I use the NuGet package for .NET Framework, there are no problems. However, when I use the package for .NET Core, I encounter an issue where 'libyara.NET.dll' cannot be loaded. Additionally, my project is targeting .NET 7, while the NuGet package specifies .NET 6. I'm not sure if this is the cause of the problem. However, it's worth noting that the program is written in CPP/CLR, so it "might" have stricter framework requirements. In the past, third-party components with .NET 6 packages were MSIL, and theoretically, referencing them directly in .NET 7 should not be an issue. If possible, it would be advisable for 'libyara.NET' to provide multiple versions of the NuGet package, including the latest for the .NET .

@MIAIONE
Copy link

MIAIONE commented Oct 15, 2023

I have found a solution:

  1. The issue stems from changes in .NET 6 or later versions, where the handling of native libraries involves placing them in runtimes\win-x64\ijwhost.dll. This causes problems for CPP/CLI compiled programs in loading the runtime environment.

  2. Therefore, to resolve this, use the version of IJWHost.dll corresponding to the .NET version you want to use. Place 'IJWHost.dll' in the same directory as libyara.NET.dll ( you can set it to be copied with the solution). Currently, my .NET 7 version of libyara.NET is running smoothly with this setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants