WIX changing assembly name on install - c#

I built a simple WIX installer that deploys an exe and a third-party dll, and creates shortcuts. The installer appears to work fine, and places both the exe and dll in a folder in C:\Program Files(x86), but when I try to run the application I get an error:
System.IO.FileLoadException: Could not load file or assembly 'GACManagerApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'GACManagerApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
The application runs just fine from the IDE, and even from the executable in the IDE bin directory, but after deploying with WIX cannot load the assembly. On a hunch, I copied the dll from the bin directory to the deployed location, and it started working. Looking closer, it appears that WIX is doing something to the third-party metadata when it deploys that changes the signature enough that the exe can no longer load it. Here is the definition of the assembly in the wxs:
<Component Id="GACManagerApi">
<File Id="GACManagerApiDLL" Name="GACManagerApi.dll" Source="$(var.GHCComponentManager.TargetPath)" />
</Component>
I also noticed that the details on the dll properties are different, with the File description, product name and original filename being changed to that of my executable, instead of the original values for the assembly.
Am I missing something in my wsx that is causing this to happen?

I figured it out. The problem was how I was defining the Source attribute. The hint really should have been in the file property details, but I was too consumed with my assumptions to see it. I was reading some other documents talking about pulling assemblies from outside the project when I noticed it.
I was defining the source as:
Source="$(var.GHCComponentManager.TargetPath)"
which translates literally to the full path of my release executable. With the Name attribute of the File element, it was effectively moving my executable to the release location and renaming it GACManagerApi.dll. The correct source should be:
Source="$(var.GHCComponentManager.TargetDir)\GACManagerApi.dll"

Related

Could not load file or assembly 'System.Web.Mvc, Version=5.2.3, Culture=neutral, PublicKey

After doing push from git server I got this error when I build and open my project:
Could not load file or assembly 'System.Web.Mvc, Version=5.2.3, Culture=neutral, PublicKeyToken=******' or one of its dependencies. The system cannot find the file specified.
The project is working pretty well with the same code in a different computer.
Problem
The error is a file not found, like the one I helped out with the other day:
Could not load file or assembly .. The system cannot find the file specified.
Troubleshooting
Open ProcessMonitor and run it when VS won't let you build your solution and throws the error. Stop the trace when it fails and investigate ProcMon's (Filemon) log to see where the IDE is looking for the DLL it cant find.
Solution
Put the DLL where its expected to be found (this will hopefully sort out the VS library referencing failure).
Also try:
disable Resharper
restart VS
clean & rebuild
I found nuget or some other update can bump the System.Web.MVC version to 4.0.0 unintentionally. So just check the dll that you have in your bin folder (or wherever the reference points) is of the same version specified in your web.config.

NopCommerce Nop.Core conflicting DLL issue

So I started working on an existing project at work in NopCommerence and I accidently added the Newtonsoft.Json DLL to the Nop.Core project, ever since then, the project keeps randomly crashing giving me the error:
Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
I removed the reference from the project right away, so there is now no reference to this DLL in the Nop.Core project.
But there is some code in the project which looks for the reference:
When we get to that plugin it crashes here:
I got no clue where to even look to solve this, it looks like it's trying to load two different versions of the DLL and when I Google around, it says to update though NuGet and I did this and nothing has solved it.
So you removed the reference, but what about the actual dll file? It looks like something is 'discovering' it at runtime and it exists on your disk somewhere and the application is finding it.
It's hard to know what to suggest but try to find out where the app is looking for plugin files, then look in that directory and delete the Json stuff. You could also try just deleting all of the bin and obj directories in the whole solution, since they will be re-created by the next build. Also look in the packages directory in the root of your solution, you may find a copy of the Json package lingering there. If you;ve definitely removed it using NuGet, then delete it from packages too.
Make a backup copy before you start, just in case my suggestions are complete rubbish ;-)

Dll incompatibilites in c#

I have a C# class library which contains a number of dlls in the assembly which I have updated. The classes are executed from a .exe file. Recompiling the calling the exe is fairly tricky (not done by me). I now get the following.
Could not load file or assembly 'xxx.xxx.xxx.xxx, Version=0.3.1768.0,
Culture=neutral, PublicKeyToken=xxxxxxxx' or one of its dependencies.
The located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
Does this mean that the references used when compiling the .exe are now different from the newer dlls I have used in the assembly that the classes inherit? Note that I have kept the original dlls used to build the .exe file. So I'm curious as to the message and I'm assuming that it is because the dlls pulled in a references in the references are newer than those in the directories used for the executable.

References in Visual Studio 2010

this may be a stupid question but when I add a reference to my project and set Copy Local to false (so it doesn't copy the dll to the working directory) I get this error:
Could not load file or assembly 'HtmlAgilityPack, Version=1.4.0.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a' or one of its dependencies. The system cannot find the file specified.
All I want is to load the dlls from "(working directory)/dlls"
Is this even possible? And what am I doing wrong?
Thanks in advance!
References simply aren't resolved relative to the working directory of the process - they're resolved relative to the assembly which is trying to load them (or from the GAC of course).
It's not clear why you want to do this, but basically you should make sure the DLL is available in the same location as the executable.

From where is my silverlight application dll is loaded/used during debugging?

I've created a new Silverlight 3 from template and started a debugging session. However, when I looked to the modules window I saw the following:
The path to my Silverlight3Application.dll was lacking (even though the pdb was found just fine). I made sure that it isn't just a UI issue, indeed I could delete the Silverlight3Application.dll file that was located next to the PDB just fine without any issues.
Questions:
Where is my DLL actually loaded from UPDATE in runtime?
Why isn't it loaded from the expected location?
Is it possible to make it load from the location next to the PDB file, where I actually expected it to load from?
Update 1
What I really need is to find out the location of my Silverlight3Application.dll in runtime, using Reflection, for example.
However, just as the modules window hides the real location, so does reflection:
Assembly: {Silverlight3Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null} System.Reflection.Assembly {System.Reflection.RuntimeAssembly}
FullName: "Silverlight3Application, Version=1.0.0.0, Culture=neutral,
publicKeyToken=null" string
ImageRuntimeVersion: "v2.0.50727" string
IsDynamic: false bool
Location: "" string
I've tried located this assembly manually using Prcocess Explorer and its location seemed rather random:
C:\Users\Vitaly\AppData\Local\assembly\dl3\G1KDTYO5.XJ3\6GQ19BER.4OW\5e5cbf28\50366acf_1a3ecc01\Silverlight3Application.dll
Anyone knows how I can find the location of the assembly in runtime? If nothing else works, using external tools is an option, however, I must be able to execute the tool from code. I'll be happy to hear ideas.
Thanks!
By default, Silvelight DLL is located in \Bin\Debug of your Silverlight project.
If you want to see where an actuall DLL is loaded from:
output path is visible in Visual Studio Output Window during build
use ProcessMonitor.
Also see http://msdn.microsoft.com/en-us/library/cc838164%28v=vs.95%29.aspx for detailed description of Silverlight project structure.
To your Update1: see How do I get the path of the assembly the code is in?
Have you considered how the assembly is actually executed in your browser? It comes from a .XAP file, not via any DLLs built/stored under your project folders. More specifically, your project builds a DLL, which is then packaged into the XAP file, which is in turn served to your web browser, which unpacks the XAP file, reads the manifest, and loads the specified DLL entry point.
The path to the DLL from the XAP root is, well, the file name (unless you've done customized the XAP yourself). That's probably why there isn't any path specified.

Categories