BadImageFormatException in NAppUpdate.Updater.exe

120 views
Skip to first unread message

Matthew Shorten

unread,
Jul 8, 2016, 8:29:58 AM7/8/16
to NAppUpdate
Hi all

Really liking the NAppUpdate framework.   I've successfully implemented into an application and it works well ... up to a point. 

The issue arises because we merge the separate .exe and .dlls (including the NAppUpdate.Framework.dll) into a single, portable .exe file for deployment.  Just in advance of a "cold update" (inside NauIpc.ExtractUpdaterFromResource), NAppUpdate extracts a copy of NAppUpdate.Updater.exe from itself and saves to %APPDATA%\foo.exe.  So far so good.  But a copy of NAppUpdate.Framework.dll is also required in that folder.  NAppUpdate tries to supplies this as follows

// Now copy the NAU DLL

var assemblyLocation = typeof(NauIpc).Assembly.Location;

File.Copy(assemblyLocation, Path.Combine(updaterPath, "NAppUpdate.Framework.dll"), true);


However, remember that NAppUpdate.Framework.dll has been merged (along with all the other DLLs) into a single portable .exe.  Therefore, in the code snippet above, assemblyLocation contains the full path and filename of the .exe and it is this which gets copied to the %APPDATA% folder and named NAppUpdate.Framework.dll. 

Then when foo.exe is launched it terminates almost immediately leaving a BadImageFormatException in the Windows Application Event log.

Can anyone suggest a workaround?  I still want to have a single portable exe.  Perhaps NAppUpdate.Updater.exe could be built so that it has no external dependencies?  What does the rest of this group think?

Thanks in advance
Matthew

Itamar Syn-Hershko

unread,
Jul 8, 2016, 12:29:04 PM7/8/16
to nappu...@googlegroups.com
This is why the library shouldn't be ILMerged into your app :)

foo.exe takes dependency of the NAppUpdate DLL and expects to see it there - the updater has external dependencies because the design was to keep it minimal. Also, what happens if you have custom actions and you need the files copied there as well?

You have the option of copying more files there (via a config), but I don't think there is a way to not have the NAU DLL there

--

Itamar Syn-Hershko
http://code972.com | @synhershko
Freelance Developer & Consultant
Lucene.NET committer and PMC member

--
You received this message because you are subscribed to the Google Groups "NAppUpdate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nappupdate+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthew Shorten

unread,
Jul 12, 2016, 11:50:58 AM7/12/16
to NAppUpdate
Itamar

Found a way to make this all work after some experimentation.  Rather than ILMERGE everything into a portable .exe I've used https://github.com/Fody/Costura to achieve the same thing and its a lot less hassle!  Using this package and (importantly) turning on the CreateTemporaryAssemblies option means that NAppUpdate and associated cold update work as expected.

Thanks for your help
Reply all
Reply to author
Forward
0 new messages