Problem With Dot Net Builder Classes in C# WPF applications

2 views (last 30 days)
I am trying to use the Matlab DotNetBuilder to use a function I have in matlab in c# but I am having exceptions thrown whenever I try and initialise the matlab class.The code below throws "
An unhandled exception of type 'System.TypeInitializationException' occurred in myProgram.exe Additional information: The type initializer for 'myMatlabNamespace.MatlabClass' threw an exception.
Uncommenting the initialisation of MWArray makes it throw
An unhandled exception of type 'System.BadImageFormatException' occurred in PresentationCore.dll
Additional information: Could not load file or assembly 'MWArray, Version=2.11.1.0, Culture=neutral, PublicKeyToken=xxxxxxxx' or one of its dependencies. An attempt was made to load a program with an incorrect format.
using System;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
using myMatlabNamespace;
namespace WPF
{
public partial class myMainWindow : Window
{
public myMainWindow()
{
InitializeComponent();
}
private void runMatlabStuffButton_Click(object sender, RoutedEventArgs e)
{
var obj = new MatlabClass();
MWArray[] fooish = new MWArray[60];
}
}
}
Looking at similar questions on MathWorks and other forums it seems like this problem is usually caused by trying to run a 32 bit .NET assembly on a 64 Bit machine but that is not what I an trying to do.I compiled the .NET assembly on the windows 7 X64 matlab 2011b version, targeting .NET 4.0 , and I am running the assembly on VS2012, .NET 4.5, platform X64.So there shouldn't be any compatibility issues.Does anyone know how I can solve this problem? Any help will be greatly appreciated.
Also Note: The matlabClass seems to work just fine when I start a project as a console application and use it over there but it just won't work on my WPF application, this is even though both compile in x64, is there something I have to do to make DotNetBuilder classes work in WPF applications? I even thought there must have been something wrong with my particular WPF project because it's a big project with many classes and all so I tried creating a completely new WPF project then adding the matlab class but it still won't work! Is there something I have to do to make dotNetBuilder classes work on WPF applications? Please help

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!