Can't find the assembly on other system.

cjimme

New member
Joined
Apr 16, 2017
Messages
3
Programming Experience
1-3
Hi,
I downloaded this assembly https://inputsimulator.codeplex.com/ to simuilate keyboard presses.
Everything works fine but if I put the .exe file from the debug folder on another system I get an error that it says that it can't find that assembly.
Any idea what I do wrong? And more importantly what can I do in the future so the custom assemblies work on the other computers too.

Kind regards, Jimme
 

cjimme

New member
Joined
Apr 16, 2017
Messages
3
Programming Experience
1-3
Fixed the issue like this:

Embed the dll in a compiled exe:
1 - Change the properties of the dll in References so that Copy Local=false
2 - Add the dll file to the project as an additional file not just a reference
3 - Change the properties of the file so that Build Action=Embedded Resource
4 - Paste this code before Application.Run in the main exe

AppDomain.CurrentDomain.AssemblyResolve += (Object sender, ResolveEventArgs args) =>
{
String thisExe = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
System.Reflection.AssemblyName embeddedAssembly = new System.Reflection.AssemblyName(args.Name);
String resourceName = thisExe + "." + embeddedAssembly.Name + ".dll";

using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
Byte[] assemblyData = new Byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return System.Reflection.Assembly.Load(assemblyData);
}
};
 
Top Bottom