sskodje / ScreenRecorderLib

A .NET library for screen recording in Windows, using native Microsoft Media Foundation for realtime encoding to h264 video or PNG images.
MIT License
408 stars 93 forks source link

Publishing a singel file breaks the assembly for this library. #274

Closed JanssonTheBest closed 9 months ago

JanssonTheBest commented 9 months ago

I recently tried publishing my project as a single file, by merging all the assemblies into to one exe, where I've used x86 on everything, but the screenrecorderlib assembly breaks.

System.BadImageFormatException HResult=0x8007000B Message=Could not load file or assembly 'ScreenRecorderLib, Version=1.0.8721.22425, Culture=neutral, PublicKeyToken=null'. An attempt was made to load a program with an incorrect format.

This exception was originally thrown at this call stack: System.Runtime.Loader.AssemblyLoadContext.InternalLoad(System.ReadOnlySpan, System.ReadOnlySpan) System.Reflection.Assembly.Load(byte[], byte[]) System.Reflection.Assembly.Load(byte[]) Costura.AssemblyLoader.ReadFromEmbeddedResources(System.Collections.Generic.Dictionary<string, string>, System.Collections.Generic.Dictionary<string, string>, System.Reflection.AssemblyName) in Common.cs Costura.AssemblyLoader.ResolveAssembly(object, System.ResolveEventArgs) in ILTemplate.cs System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(System.ResolveEventHandler, System.Reflection.RuntimeAssembly, string) System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(System.Reflection.RuntimeAssembly, string)

Inner Exception 1: BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B)

sskodje commented 9 months ago

Unfortunately, to my knowledge, single file deployment does not work with libraries compiled with c++/cli.

https://github.com/dotnet/sdk/issues/12345

JanssonTheBest commented 9 months ago

Unfortunately, to my knowledge, single file deployment does not work with libraries compiled with c++/cli.

https://github.com/dotnet/sdk/issues/12345

Any idea where i could start researching? What exactly is the issue, why cant I merge everything into one assembly?

sskodje commented 9 months ago

It's an issue with the dot net build tools apparently. I don't know any more unfortunately.

JanssonTheBest commented 9 months ago

image How would I do this?

sskodje commented 9 months ago

https://learn.microsoft.com/en-us/nuget/quickstart/install-and-use-a-package-in-visual-studio

JanssonTheBest commented 7 months ago

https://learn.microsoft.com/en-us/nuget/quickstart/install-and-use-a-package-in-visual-studio

I solved the problem through selfextracting and .net reflection