1

I'm struggling with this. My WPF app, in debug/release works fine. After I publish it, via InstallShield Express, I get a runtime exception and the program crashes.

When the program crashes, I can choose to debug the program in Visual Studio, it breaks in the RelayCommand which looks like

public class RelayCommand : ICommand
{
    public Action<object> _execute;

    public RelayCommand(Action<object> execute)
    {
        this._execute = execute;
    }

    public bool CanExecute(object parameter)
    {
        return true;
    }

    public event EventHandler CanExecuteChanged;

    public void Execute(object parameter)
    {
        this._execute(parameter); // where the breakpoint is
    }
}

The error message is

FileNotFoundException was unhandled
Could not load file or assembly 'TaskScheduler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified

I'm lost as to why this is. I have other commands on the page, and they are all set up in the following manner

   public ICommand SaveScheduledTaskCommand { get; set; }
   public ICommand OpenFileCommand { get; set; }

    #region Constructor

    public MyApp()
    {
        OpenFileCommand = new RelayCommand(new Action<object>(OpenFile)));
        ScheduledTaskCommand = new RelayCommand(new Action<object>(SaveScheduledTask));
    }

    #endregion

    private void OpenFile(object o)
    {
        MessageBox.Show("OF"); //works fine
    }    

    private void SaveScheduledTask(object o)
    {
        MessageBox.Show("TS"); //never shows
        TaskScheduler ts = new TaskScheulder();
        //more code
    }    

I guess the issue is with the TaskScheduler.dll (based upon the error message) but, the .dll exists in the installed folder (under c:\Program Files\Compamy\MyApp)...

I don't think it matters but, the TaskScheduler.dll is saved outside of my project (it is saved on the desktop) but I assume this is not relevant as the installer will take a copy of it and save it to the program Files folder any way?

I used InstallShield Express to create the installer and other than this, it works fine. I also another 3rd party dll, XCeed, and this work fine in my app.

I'm totally lost as to what I can do as I can't see how I can fix the code! Why can't the application "see" the dll?

MyDaftQuestions
  • 4,487
  • 17
  • 63
  • 120
  • Did you try copying the `TaskScheduler.dll` in the folder where the .exe is? – nakiya Sep 19 '14 at 06:32
  • @nakiya, good question. When I look in C:\Program Files (x86)\Company\MyApp I can see the .exe - the TaskScheduler.dll file is also there, as well as things like the Xceed.Wpf.Toolkit.dll (which works fine) – MyDaftQuestions Sep 19 '14 at 06:37
  • 1
    To debug, you can try http://msdn.microsoft.com/en-us/library/ff527268(v=vs.110).aspx and see why the assembly is not loading – Gayot Fow Sep 19 '14 at 13:04
  • Try to setup the .net assemply bindinging logging http://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net and http://msdn.microsoft.com/en-us/library/e74a18c4%28v=vs.71%29.aspx – nemesv Sep 21 '14 at 13:19
  • I see two possibilities. Either you have a version problem (TaskScheduler.dll has a different version from what you built against), or more likely, TaskScheduler itself is missing a dependency. Open TaskScheduler in a reflector (e.g. ILSpy) and check the references for non-framework assemblies, also try FusionLog as nemesv suggested. – Mike Fuchs Sep 22 '14 at 06:14
  • @adabyron, what do you mean by different version? Are you saying if the `TaskScheduler.dll` was built using .NET3.5 and my application is using .NET4.5 that *this could* cause this type of issue? – MyDaftQuestions Sep 22 '14 at 07:47
  • FusionLog seems very promising... Thanks @nemesv, will test (hopefully) after work – MyDaftQuestions Sep 22 '14 at 08:24
  • No, that should be no problem. You can run components from earlier .NET versions in a later runtime. But if the assembly itself has a different major version (e.g. 2.0.0.0 instead of 1.0.0.0), it's not compatible. From your code I take that you need to have a reference to TaskScheduler in your project. Check if this assembly is the same as the one deployed in the install folder. – Mike Fuchs Sep 22 '14 at 08:53
  • @adabyron How do I check if it's the same assmebly, via DotPeek or some decomplier? – MyDaftQuestions Sep 22 '14 at 08:57
  • 1
    You can see the assembly version in any file explorer (properties, details). But you'll need the decompiler for checking the references of TaskScheduler.dll (what I think might be more likely the source of the problem, see first comment). Any decompiler/reflector like DotPeek or ILSpy will work for that. – Mike Fuchs Sep 22 '14 at 09:20
  • It's definitely not the version problem... just saw that your assembly is not strong named (no public key), so it would not give you a FileNotFoundException but rather a MethodNotFoundException or the like at runtime. – Mike Fuchs Sep 22 '14 at 09:38
  • @adabyron, thanks. I will try with Fusion in about 9 hours time! :) – MyDaftQuestions Sep 22 '14 at 09:56
  • When you're in the debugger go to Debug->Windows->Modules and see if the assembly is loaded and where it is loaded from. Also check to see if you have any other exceptions before that - perhaps run the app, attach to it with VS and use Debug->Exceptions to have it break on all exceptions. Perhaps there is another exception happening before that point - e.g. if you have a xaml file with a Build action of Resource (instead of Page) and not all the relevant dlls have been loaded. Also try running the app locally without the debugger attached (e.g. Ctrl+F5) to see if that works. – AndrewS Sep 23 '14 at 16:24
  • @AndrewS, the file is only shown in the Modules pane when I enter that project. At that stage, it shows me it `Cannot find or open the PDB file` but according to [this post](http://stackoverflow.com/questions/15937707/error-message-cannot-find-or-open-the-pdb-file) it suggests the PDB does not matter? – MyDaftQuestions Sep 24 '14 at 07:13
  • @adabyron, finally got Fusion working, and logging enabled. As probably expected, the .dll is not present. So, we know why it's failing, it's missing the .dll - but why? How do I make it not missing? – MyDaftQuestions Sep 24 '14 at 07:26
  • Can you post the log? Did you check at which paths the .dll is looked for (Attempting download from...), and compared that to the location you placed the .dll? – Mike Fuchs Sep 24 '14 at 08:23
  • I had something similar but I could solve it. They key thing was `... or one of it's dependencies.` It could be that a DLL/assembly where TaskScheduler is referring to could not be found. DLL's/assemblies that are referenced by TaskScheduler could be detected by running in VisualStudio and inspect the `'' (Managed...) Loaded 'C:\...'` entries. Locate the point where TaskScheduler.dll is loaded. The DLLs/assemblies that follow are (probably) loaded due to TaskScheduler. Check if these DLL's exist or can be reached. – Sjips Sep 24 '14 at 12:36
  • You mention that you got the fusion log working. Then it should list the paths that it checked for the file (i.e. the probe bin path). Is the assembly directly in one of those folders. As someone else mentioned it would be helpful if you posted the log. – AndrewS Sep 24 '14 at 16:13
  • While it's not so much a fix for the issue, you could try using Fody Costura to embed all dependancies into the exe: https://github.com/Fody/Costura – Daloupe Sep 24 '14 at 17:23
  • Try changing the version of TaskScheduler and see if you get the same error message. Try renaming TaskScheduler temporarily to see if you still get the message. – Ranjith Venkatesh Sep 26 '14 at 15:23
  • @nemesv can you move to an answer please – MyDaftQuestions Sep 27 '14 at 11:21
  • @MyDaftQuestions my comment was just a hint. You have found the solution so you should write a summary answer how you found out the problem and just assign the bounty to Henrik's answer which also include the hint: use fusion log. – nemesv Sep 27 '14 at 11:26

1 Answers1

2

Since TaskScheduler is included this is because you are missing to include an assembly that is referenced by the TaskScheduler.dll.

Debug Step 1
Inspect the dependencies of TaskScheduler.dll and make sure to include all dependencies in the installation package (except framework assemblies).

Debug Step 2
If you cannot inspect the dependencies of TaskScheduler.dll then follow this guide, How to enable assembly bind failure logging (Fusion) in .NET, to find out which assemblies are missing.

Community
  • 1
  • 1
Henrik Cooke
  • 775
  • 5
  • 8