I tried to make the installer be able to send GET/POST requests to certain http server and then convert the response into a Csharp object. Then I used the Newtonsoft.Json Library for the installer (.msi file), but when I ran the installer, it failed. The error message said it cannot find the dll file.
Then I put the Newtonsoft.Json.dll in the same folder with the installer, but this didn't help.
Is there a way to let the installer know where to load the dll file?
Here is the error message:
System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
File name: 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
at WixSharpSetup.Dialogs.WelcomeDialog.WelcomeDialog_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
You must either insert the Newtonsoft.Json.dll into DefaultRefAssemblies or you can reference it in the specific Custom Action (in case you are using this approach).
You must either insert the
Newtonsoft.Json.dllintoDefaultRefAssembliesor you can reference it in the specific Custom Action (in case you are using this approach).
I added this line for the Program.cs file:
project.DefaultRefAssemblies.Add("PATH_TO_DLL");
but it failed to compile. PATH_TO_DLL is the same path of Newtonsoft.Json.dll that the Wixsharp project uses
Is there any sample code for inserting a Dll file to DefaultRefAssemblies?
Error Message:
System.IO.FileLoadException
HResult=0x80131621
Message=API restriction: The assembly '' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.
Source=mscorlib
StackTrace:
at System.Reflection.RuntimeAssembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection, Boolean fSkipIntegrityCheck, SecurityContextSource securityContextSource)
at System.Reflection.Assembly.ReflectionOnlyLoad(Byte[] rawAssembly)
at WixSharp.Utils.OriginalAssemblyFile(String file)
at WixSharp.Compiler.PackageManagedAsm(String asm, String nativeDll, String[] refAssemblies, String outDir, String configFilePath, Nullable`1 platform, Boolean embeddedUI, String batchFile)
at WixSharp.Compiler.GenerateWixProj(Project project)
at WixSharp.Compiler.BuildWxs(Project project, String path, OutputType type)
at WixSharp.Compiler.BuildWxs(Project project, OutputType type)
at WixSharp.Compiler.Build(Project project, String path, OutputType type)
at WixSharp.Compiler.Build(Project project, OutputType type)
at WixSharp.Project.BuildMsi(String path)
at WixSharp472.Program.Main() in
Could you please try using the filename instead of path?
My sample code (succesfully using Newtonsoft.Json):
DefaultRefAssemblies = new List<string>
{
typeof(JsonConverter).Module.Name,
}
Could you please try using the filename instead of path?
My sample code (succesfully using Newtonsoft.Json):
DefaultRefAssemblies = new List<string> { typeof(JsonConverter).Module.Name, }
project.DefaultRefAssemblies = new List
This doesn't work for me. I got the same error message.
There is a sample "DTF_ExternalAssembly" that you can have a look at.
But it looks to me that you are doing it right anyway. I only would use Location property instead:
C#
project.DefaultRefAssemblies.Add(typeof(JsonConverter.Utils).Assembly.Location);
You may need to debug to see at runtime
Newtonsoft.Json.dll.Assembly.LoadFrom. If it fails then it can be because it's targeting wrong runtime or other dependencies are missing. But you will need to be under debugger.
Thank you all for the efforts you made. For now I am going to use XML instead of Json, since XML doesn't require extra DLL
There is a sample "DTF_ExternalAssembly" that you can have a look at.
But it looks to me that you are doing it right anyway. I only would useLocationproperty instead:project.DefaultRefAssemblies.Add(typeof(JsonConverter.Utils).Assembly.Location);You may need to debug to see at runtime
- if the assembly is deployed along side with your custom action assembly distributed. Stop at breakpoint in your CA and chec the location of your executing assembly and if its parent folder contains
Newtonsoft.Json.dll.- if the assembly can be loaded manually with
Assembly.LoadFrom. If it fails then it can be because it's targeting wrong runtime or other dependencies are missing.But you will need to be under debugger.
I used the following code and fixed the issue:
project.DefaultRefAssemblies.Add(typeof(JsonConverter).Assembly.Location);
Thanks for your good example.
You are welcome.