1

There are a lot of posts on here about this, I'm using this code from another SO post and placing a delegate assignation in my Main() method. None of the other posts have directly answered my question.

I've got my third party assembly embedded as a resource but when I fire up the app:

  • I'm getting a TypeInitializationException with an inner of FileNotFoundException. It's trying to find the assembly on the file system and failing.
  • it's never getting to the Main method, where the event handler for AssemblyResolve is assigned

I have two assembly refs that are embedded in my Resources.resx, one is a third party tool (command line parser) and the other is a Library file where the meat of the application resides.

Maybe this isn't possible with a console app? Seems unlikely but I don't see a way around it.

Re: ILMerge etc: I'd like to get this done entirely in code without involving any tools. Reason: I don't want to have source code in the repository that requires other team members to install a tool that they probably don't have already. If that's not possible then ILMerge looks like the next best option.

Community
  • 1
  • 1
jcollum
  • 43,623
  • 55
  • 191
  • 321
  • How is ILMerge any less of a first party tool than C# and visual studio itself? – Chris Marisic Mar 10 '10 at 19:06
  • @Chris: good point. Editing now. Still, if I can get this done without involving ILMerge I'd prefer to do it that way. It seems reasonable. – jcollum Mar 10 '10 at 19:24

3 Answers3

2

Consider using ILMerge to merge the assemlies into one rather than embedding as a resource. This is download site for ILMerge.

You would merge your third party assemblies into your console app.

btlog
  • 4,760
  • 2
  • 29
  • 38
  • Oops, beat me. I just added "I'd prefer not to use a 3rd party..." – jcollum Mar 10 '10 at 16:25
  • guess I should have read the link to the other SO question :) – btlog Mar 10 '10 at 16:38
  • Yeah, it looks like it should be possible with just a few lines of code, I just can't figure out how to get the event to fire at the right time in the app's lifecycle. – jcollum Mar 10 '10 at 16:48
1

You could also look at application virtualization tools like XenoCode. They can package multiple assemblies (including the .net framework itself) into a stand alone executable.

dkackman
  • 15,179
  • 13
  • 69
  • 123
1

If it is mixed mode assembly, it has to reside on the disk. Some limitation or something.

leppie
  • 115,091
  • 17
  • 196
  • 297