yartat / MP-MediaInfo

Mediaportal MediaInfoLib wrapper
Other
45 stars 21 forks source link

MediaInfo library was not loaded! #14

Closed lynn-orrell closed 4 years ago

lynn-orrell commented 4 years ago

I get this error message on some machines but not others. Is there any way to understand why MediaInfo.dll failed to load?

yartat commented 4 years ago

Please, describe more information what is OS was used, version MediaInfo.Wrapper. Did you use .NET Core version or full .NET?

lynn-orrell commented 4 years ago

Edition: Windows 10 Pro Version: 1909 OS build: 18363.535

MediaInfo.Wrapper: 19.4.1.0

.NET Framework 4.8

yartat commented 4 years ago

Fixed in 84003fcfe9c854f63a39bedf382c1c6e823bd527

ransagy commented 4 years ago

This still seems to happen, But i'm not sure if its the exact same issue; It works when building for x64, but AnyCPU doesn't copy any of the runtime dlls, including libmediainfo etc and the other dependencies.

All machines showing this are on Windows 10. I have a netstandard2.0 library that references the .NET Core version of the wrapper (19.09) and there are two consoles that are targetting NET Framework 4.7.2 referencing this library.

yartat commented 4 years ago

I created 2 packages: .NET full and .NET standard. .NET standard should use in .NET Core services and applications only. If you run application on .NET Framework 4.8 you should use .NET full package

ransagy commented 4 years ago

Not sure i follow. The project that uses this library is a netstandard2.0 one, even if the root that loads it is a .NET Framework based one.

It does work well in runtime, but only if i build for x86/x64 explicitly; it just doesn't copy any of the artifacts when building to AnyCPU. Is that just not supported in general?

I'm not sure why that would be related to which runtime executes the code.

yartat commented 4 years ago

MediaInfo.Native package contains MediaInfo.Native.targets (you can find it in %USERPROFILE%.nuget\packages\mediainfo.native\19.9.0) file with instructions how to build in 3 cases:

MediaInfo.Wraper library detects what kind of process (x32 or x64) and tries find MediaInfo library in root folder or x86\x64 folder.

yartat commented 4 years ago

MediaInfo.Core.Native package contains runtimes with structure of folder and libraries well known only for .NET Core runtime

ransagy commented 4 years ago

Then it seems unrelated to this issue, I just don't get the x86 and x64 folders in the output. If it was a Core vs Framework issue, id expect not to get anything even when building for a specific arch. Should i open a new issue here or on the Native package in your opinion?

yartat commented 4 years ago

Could you create a simple project with mediainfo.wrapper package only and try build it? If you have same result as in your project can you share it with me?

ransagy commented 4 years ago

@yartat sorry for the delay - here is the repro: https://github.com/ransagy/mpMediaInfoBitnessRepro

Run the console project on either Any CPU or x64 and see the difference in outputs.

yartat commented 4 years ago

I update test project. See https://github.com/yartat/mpMediaInfoBitnessRepro/commit/22aa89c43a9e5001628def18f1f2fac88b921f33

LeaFrock commented 2 years ago

Now Microsoft recommends NFX projects using PackageReference instead of packages.config. But the MediaInfo.Native.targets reads,

 <ItemGroup Condition=" (Exists('packages.config') Or Exists('packages.$(MSBuildProjectName).config')) And '$(Platform)' == 'x86'">
    <None Include="$(MSBuildThisFileDirectory)native\x86\*">
      <Link>%(Filename)%(Extension)</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Visible>False</Visible>
    </None>
  </ItemGroup>

The Condition prevents CopyToOutputDirectory so I have to copy the .dlls (in native/x86) manually and it works well. And I believe I'm not alone so it's worth leaving a comment here.

The following is a very small console sample:

    internal class Program
    {
        private static void Main(string[] args)
        {
            string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test2.mp3");
            var media = new MediaInfoWrapper(filePath, NullLogger.Instance);
            if (media.Success)
            {
                Console.WriteLine(media.Duration.ToString());
            }
            Console.ReadKey();
        }
    }

    internal sealed class NullLogger : MediaInfo.ILogger
    {
        public static readonly NullLogger Instance = new NullLogger();

        public void Log(LogLevel loglevel, string message, params object[] parameters)
        {
            try
            {
                if (parameters?.Length > 0)
                {
                    Console.WriteLine(string.Format(message, parameters));
                }
                else
                {
                    Console.WriteLine(message);
                }
            }
            catch(Exception)
            {
                ;
            }
        }
    }

1668670146168

w7rus commented 1 year ago

Using mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim or mcr.microsoft.com/dotnet/aspnet:7.0 had same MediaInfo library was not loaded! error. MediaInfo.Core.Native & MediaInfo.Wrapper.Core are installed for project.

As a temporary solution: manually installing required libraries fixes the problem

RUN apt update &&\
    apt-get install -y libmediainfo0v5 libzen0v5