I am preparing a setup project for my application. i need to construct database connection string and then run the script file based on the connection string and update the application config files as well.

i have this WPF Sql Connection User Control which enables me to construct the database connection string from user input.

The problem is that when i try to launch the WPF Sql Connection User Control from an installer class i get this exception.

Error 1001: Assembly.GetEntryAssembly() returns null. Set the Application.ResourceAssembly property or use the pack syntax to specify the assembly to load the resource from.

here is the App.xaml.cs code

        Uri uri = new Uri(@"/WpfApplication1;component/MainWindow.xaml", UriKind.Relative);
        var window = Application.LoadComponent(uri);

my installer class has this code to launch the application.

    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);
        var thread = new System.Threading.Thread(StartDatabaseUserControl);
        thread.SetApartmentState(System.Threading.ApartmentState.STA);
        thread.Start();
        thread.Join();
    }

Thanks,


Implemented Solution

well i have got it working in a different way.

Changing the custom action property "Installer Class" to false in the visual studio setup project worked for me.

i had to add another entry point and set it as project startup object. don't even need to add any code in the App.xaml.cs file.

this is the new entry point

   [STAThread]
    private static void Main(string[] args)
    {
        TargetDirectory = args[0];

        var app = new App();
        app.InitializeComponent();
        app.Run();
    }
1

There are 1 answers

0
Default Writer On

The GetEntryAssembly method can return null when a managed assembly has been loaded from an unmanaged application. For example, if an unmanaged application creates an instance of a COM component written in C#, a call to the GetEntryAssembly method from the C# component returns null, because the entry point for the process was unmanaged code rather than a managed assembly.

MSDN