Patrik Capay SK
Patrik Capay SK

Reputation: 107

VLC.DotNet System.ComponentModel.Win32Exception: '%1 is not a valid Win32 application'

Working with:
Visual Studio 2017
NET framework 3.5
building for Any CPU
using 32-bit VLC version 2.2.6
using Vlc.DotNet (because i think it's only one that is working on any NET framework...)

I created new Form just for testing, how this library works (or if works)
used drag and drop method for "VlcControl" and one Button
All code is below:

Form.cs:

using System;
using System.IO;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter = "( *.mp4) | *.mp4"
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                vlcControl1.SetMedia(new FileInfo(Path.GetFileName(ofd.FileName)));
                vlcControl1.Play();
            }
        }
    }
}

Form.Designer.cs (Generated)

namespace WindowsFormsApp2
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.vlcControl1 = new Vlc.DotNet.Forms.VlcControl();
            ((System.ComponentModel.ISupportInitialize)(this.vlcControl1)).BeginInit();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(12, 255);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(260, 42);
            this.button1.TabIndex = 1;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // vlcControl1
            // 
            this.vlcControl1.BackColor = System.Drawing.Color.Black;
            this.vlcControl1.Location = new System.Drawing.Point(12, 12);
            this.vlcControl1.Name = "vlcControl1";
            this.vlcControl1.Size = new System.Drawing.Size(260, 237);
            this.vlcControl1.Spu = -1;
            this.vlcControl1.TabIndex = 2;
            this.vlcControl1.Text = "vlcControl1";
            this.vlcControl1.VlcLibDirectory = new System.IO.DirectoryInfo("C:\\Program Files (x86)\\VideoLAN\\VLC");
            this.vlcControl1.VlcMediaplayerOptions = null;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 309);
            this.Controls.Add(this.vlcControl1);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.vlcControl1)).EndInit();
            this.ResumeLayout(false);
        }

        #endregion
        private System.Windows.Forms.Button button1;
        private Vlc.DotNet.Forms.VlcControl vlcControl1;
    }
}

Program.cs

using System;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

Now the question is:

After calling "InitializeComponent()", program crashes:

In file: Form.Designer.cs

Line with: ((System.ComponentModel.ISupportInitialize)(this.vlcControl1)).EndInit();

throws System.ComponentModel.Win32Exception: '%1 is not a valid Win32 application'

How can i fix it???

Upvotes: 4

Views: 5700

Answers (2)

Adam Guy
Adam Guy

Reputation: 1

In my case, I've changed the project settings to: Platform Target: x64

Also working: Platform Target: Any CPU Prefer 32-bit: Checked

I'm using .net 4.8 and Visual Studio 2022.

Upvotes: 0

MakS
MakS

Reputation: 131

Just set: Project-> Properties-> Build -> Platform Target = x86

Upvotes: 6

Related Questions