Fix Error: An attempt was made to load a program with an incorrect format
While trying to run the sample project ShellObjectWatcherSampleWPF
from the latest version of Windows API Code Pack, I came across the following problem, both in Visual Studio 2008 and 2010:
Or in a search-engine friendly way:
“Cannot create instance of ‘
MainWindow
’ defined in assembly, ‘ShellObjectWatcherSampleWPF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
’. Exception has been thrown by the target of an invocation. Error in markup file ‘MainWindow.xaml’ Line 1 Position 9.”
Checking the internal exception, revealed the following:
"Could not load file or assembly '
Microsoft.WindowsAPICodePack.Shell, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null
' or one of its dependencies. An attempt was made to load a program with an incorrect format."
Now, when we get an error of “incorrect format”, it usually means there is a matching problem between the bitness of the project and the bitness of the machine.
Since my system happens to be x64 based, and the project was compiled as 32bit, we got ourselves a problem.
Usually, this doesn’t matter, since .NET is bit-agnostic (yet another advantage of JIT compilation), but since the project depends heavily on P/Invoke, it does indeed make a difference.
The solution is simply to go to the Project Properties | Build and change the Platform target to x64.
That’s it for now,
Arik Poznanski.
Post Comment
This is very interesting, You are a very skilled blogger. I have joined your feed and look forward to seeking more of your fantastic post. Also, I ave shared your website in my social networks!
avUFNA Some really great info , Gladiolus I detected this.
PbqUeF Really enjoyed this blog post.Much thanks again. Cool.
dEdrGi You have brought up a very good details , regards for the post.
standard information an individual provide on your guests?
ayt2ty You completed a number of nice points there. I did a search on the issue and found nearly all people will have the same opinion with your blog.
3GNRn5 I regard something genuinely interesting about your site so I bookmarked.
CqkyZ0 This blog is extremely good. How was it made ?
iq7ieV I was suggested this website by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my difficulty. You are amazing! Thanks!
54bRNK You have made some good points there. I checked on the internet for more information about the issue and found most people will go along with your views on this web site.
"Привет, #uname!"
"Привет,
"Привет,
"Привет,
"Привет,
"Привет,
"Привет,
"Привет,
"Привет,Uajj3b Way cool! Some very valid points! I appreciate you writing this write-up and the rest of the site is also really good.
XMFZc1 What as Happening i am new to this, I stumbled upon this I have found It absolutely helpful and it has aided me out loads. I hope to contribute & assist other users like its aided me. Great job.
44Y4g5 Your information is very digestible. I enjoy your style of writing. Your points are clear and reasonable and I agree with a lot of your ideas. You have a lot of interesting views. Thank you.
LuB3Bj Your style is so unique compared to other people I ave read stuff from. Thank you for posting when you ave got the opportunity, Guess I will just bookmark this page.
V8db39 Pretty! This has been an extremely wonderful article. Many thanks for supplying these details.
4PuEKX That you are my role designs. Thank you to the write-up
maf2YR Looking for me, I came here for important information. The information is so incredible that I have to check it out. Nevertheless, thanks.
JFOuv8 My brother suggested I might like this website. He was totally right. This post actually made my day. You cann at imagine simply how much time I had spent for this information! Thanks!
EogdJk Simply a smiling visitor here to share the love (:, btw outstanding design.
Valuable information. Lucky me I found your web site by accident, and I am shocked why this accident did not happened earlier! I bookmarked it.
q6ICqI This site was how do you say it? Relevant!! Finally I have found something that helped me. Thank you!
yjJ1pG What as up to every body, it as my first pay a visit of this web site; this website consists of amazing and genuinely good data designed for visitors.
ugASXb I truly enjoy examining on this internet site, it has got wonderful blog posts. Never fight an inanimate object. by P. J. O aRourke.
FHW9nP Thanks, I ave recently been hunting for information about this subject matter for ages and yours is the best I ave found so far.
cbHEPC Some really quality content on this internet site , bookmarked.
2vPtVE Thanks for the blog post. Fantastic.
JkomxQ Wonderful post! We are linking to this particularly great post on our website. Keep up the great writing.
cPEmna You received a really useful blog I have been right here reading for about an hour. I am a newbie along with your accomplishment is very much an inspiration for me.
WsuYdb Very informative post.Really thank you! Keep writing.
VgEfGh Say, you got a nice blog.Much thanks again. Much obliged.
n6uXFH Hello there, You've done an incredible job. I'll certainly digg it and personally recommend to my friends. I am confident they'll be benefited from this site.
U6WPtl Hi there, You have done a great job. I'll certainly digg it and personally recommend to my friends. I'm sure they'll be benefited from this website.
aEwvj2 My spouse and I stumbled over here different web page and thought I may as well check things out. I like what I see so i am just following you. Look forward to going over your web page again.
GPPO7C It's truly a nice and useful piece of info. I am happy that you just shared this helpful info with us. Please stay us up to date like this. Thank you for sharing.
sTH6E1 I am curious to find out what blog platform you're utilizing? I'm experiencing some minor security problems with my latest blog and I'd like to find something more safe. Do you have any solutions?
LiXafI Thanks so much for the article post.Really looking forward to read more. Want more.
This is one awesome blog.Thanks Again. Much obliged.
Fantastic post.Really thank you! Want more.
Im obliged for the article.Really looking forward to read more. Awesome.
Say, you got a nice post.Really thank you!
Very informative blog post.Much thanks again. Want more.
Thank you ever so for you article post.Really thank you! Great.
Very neat blog post.Much thanks again. Much obliged.
This is one awesome blog.Really looking forward to read more. Keep writing.
Say, you got a nice blog post.Thanks Again. Keep writing.
A big thank you for your post.Much thanks again. Great.
wow, awesome blog.Really looking forward to read more. Really Cool.
Fantastic post.Really looking forward to read more. Want more.
I really like and appreciate your post.Really looking forward to read more. Great.