Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method not found: 'Void System.AppDomainSetup.set_ApplicationBase(System.String)'. #1357

Closed
Cobollatin opened this issue Oct 22, 2023 · 7 comments

Comments

@Cobollatin
Copy link

Cobollatin commented Oct 22, 2023

Hello, I got this error when compiling with a managed action. It works when I remove it. Do you have any idea how to fix it? Thanks in advance.

The project

var project = new Project("MyProduct",
    new Dir(@"%ProgramFiles%\My Company\My Product"),
    new ManagedAction(WindowsInstallerActions.GetDll))

The line triggering the error var installerPath = Compiler.BuildMsi(project);

The custom action:

public class WindowsInstallerActions
    {

        [CustomAction]
        public static ActionResult GetDll(Session session)
        {
            var tempDirectory = Path.Combine(Path.GetTempPath(), "Serverli");
            Directory.CreateDirectory(tempDirectory);
            var dllPath = Path.Combine(tempDirectory, "Serverli-agent.dll");
            var isFilePresent = System.IO.File.Exists(dllPath);
            // Check integrity of dll
            var isFileValid = true;

            if (isFilePresent && isFileValid) return ActionResult.Success;

            // Download dll
            var httpClient = new HttpClient();
            var responseStreamTask = httpClient.GetStreamAsync("http://ipv4.download.thinkbroadband.com/5MB.zip");
            var responseStreamTaskContinueWith = responseStreamTask
                .ContinueWith(task =>
                {
                    if (task.IsFaulted)
                    {
                        Exception? ex = task.Exception;
                        while (ex is AggregateException && ex.InnerException != null)
                            ex = ex.InnerException;
                        var errorDialog = new Dialog
                        {
                            Title = "Error",
                            Width = 370,
                            Height = 270
                        };
                        isFileValid = false;
                        return;
                    }
                    else if (task.IsCanceled)
                    {
                    }

                    using var fileStream = new FileStream(dllPath, FileMode.Create, FileAccess.Write, FileShare.None,
                        bufferSize: 4096, useAsync: true);
                    task.Result.CopyToAsync(fileStream);
                });

            responseStreamTaskContinueWith.Wait();
            return ActionResult.Success;
        }

    }
Stack trace:
   at WixSharp.Utils.Clone(AppDomain domain, String name)
   at WixSharp.Utils.ExecuteInTempDomain[T](Func`2 action)
   at WixSharp.Utils.ExecuteInTempDomain[T](Action`1 action)
   at WixSharp.Compiler.PackageManagedAsm(String asm, String nativeDll, String[] refAssemblies, String outDir, String configFilePath, Nullable`1 platform, Boolean embeddedUI, String batchFile)
   at WixSharp.Compiler.ProcessCustomActions(Project wProject, XElement product)
   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 ServiceClass in ServiceFile:Line 

Dependencies:

    <PackageReference Include="WixSharp-wix4.WPF" Version="2.0.2" />
    <PackageReference Include="WixSharp_wix4" Version="2.0.2" />
    <PackageReference Include="WixSharp_wix4.bin" Version="2.0.2" />
    ....
    <TargetFramework>net6.0</TargetFramework>
@oleg-shilo
Copy link
Owner

oleg-shilo commented Oct 23, 2023

It looks like some assembly is missing (or the wrong version) during the build.
It's hard to diagnose without having the project to troubleshoot.

Why don't you try to do something as simple as managed events? They are a great low-effort alternative to setup managed custom actions. Something like that:

var project = new ManagedProject("MyProduct",
    new Dir(@"%ProgramFiles%\My Company\My Product"),
    . . .);
    
project.AfterInstall = arg =>
{
    if (arg.IsInstalling || arg.IsUpgrading)
    {
        // do your get dll stuff
    }
    else
    {
        // possibly remove the downloaded dll
    }
};

BTW AfterInstall is elevated so you will not have any problems with the permissions.

@Cobollatin
Copy link
Author

I don't have AfterInstall available in Project. I am using those versions

    <PackageReference Include="WixSharp-wix4.WPF" Version="2.0.2" />
    <PackageReference Include="WixSharp_wix4" Version="2.0.2" />
    <PackageReference Include="WixSharp_wix4.bin" Version="2.0.2" />

@oleg-shilo
Copy link
Owner

oleg-shilo commented Oct 23, 2023

It needs to be ManagedProject
This is the sample for ManagedProject:

static void project_AfterInstall(SetupEventArgs e)

@Cobollatin
Copy link
Author

I get the same error when using the ManagedProject.
On the other hand, do you know why it fails when using WUI.WixUI_Minimal?
I tried installing all the Wix toolsets without success, I also tried to debug the build steps of wixsharp without success. Thanks for reading me :)
image
image

@oleg-shilo
Copy link
Owner

The error about a method not being found in the assembly. Meaning that the assembly is not what is expected to be. Any chance you are building on .NET instead of .NET Framework?

Debugging build steps is easier than one can think. Wir WixSharp 4. Remove from the project file the post-build event, which runs the MSI builder assembly and now you can run the builder by yourself with F5 and breakpoints.

This model can help you understand how it all works:
https://github.com/oleg-shilo/wixsharp/wiki/Managed-Setup-Model

@Cobollatin
Copy link
Author

I am using .Net core, I was able to debug the Wix build by generating only the wsx and the build command, thank you! I had to add some properties and attributes. However, I can't make the custom actions compile. I am using the library to create installers programmatically; I don't know if that may be the cause. I only need to install a windows service; I want the installer to fetch the service binaries and install them with some configuration that is inside the msi. Currently, I am embedding the binaries because I can't make the actions work. Is it possible to use the library to achieve this?
image

@oleg-shilo
Copy link
Owner

I am using .Net core

It explains. WiX (not WixSharp) does not support .NET Core family. Only .NET Framework.

That's why I always recommend creating a WixSharp project from the VS WixSharp template (it comes as a VS extension).

There is no other way. If you are building CA then it has to be .NET Framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants