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
Thanks for sharing, this is a fantastic article post.Really looking forward to read more. Really Cool.
Wow, great article post.
I am so grateful for your blog post.Really thank you! Will read on...
Thanks-a-mundo for the article.Much thanks again. Great.
Thanks for the article.Thanks Again. Much obliged.
Really appreciate you sharing this blog post.Thanks Again. Fantastic.
Major thanks for the blog post.Really looking forward to read more. Great.
Im grateful for the post.Thanks Again. Awesome.
I am so grateful for your blog.Much thanks again. Really Great.
Really appreciate you sharing this blog post.Thanks Again. Keep writing.
Very informative blog.Thanks Again.
Major thankies for the blog.Really thank you! Keep writing.
I truly appreciate this post.Thanks Again. Cool.
Im thankful for the article.Much thanks again. Will read on...
Fantastic blog post.Really looking forward to read more. Really Great.
A round of applause for your article post.Thanks Again. Want more.
Fantastic blog article.Thanks Again. Will read on...
Major thankies for the blog article.Thanks Again. Will read on...
Hey, thanks for the blog post.Thanks Again. Great.
Really informative article post.Thanks Again. Great.
This is one awesome post.Thanks Again. Will read on...
I think this is a real great article. Awesome.
Fantastic article.Really looking forward to read more. Awesome.
I am so grateful for your article post.Really thank you! Want more.
Thanks again for the blog article.Really thank you! Keep writing.
Very informative blog. Will read on...
Awesome article.Much thanks again. Cool.
Wow, great post.Really looking forward to read more. Awesome.
I really like and appreciate your blog.Really thank you! Cool.
Awesome article.Thanks Again. Really Great.
Very good blog article. Keep writing.
Very informative article post. Cool.
I truly appreciate this blog post. Cool.
Very good post.
I am so grateful for your article post. Really Great.
I am so grateful for your post.Thanks Again. Awesome.
Very neat article post.Much thanks again.
Awesome post.Really looking forward to read more. Fantastic.
I cannot thank you enough for the blog post.Really looking forward to read more. Really Great.
A big thank you for your blog post.Much thanks again. Keep writing.
I appreciate you sharing this blog article. Cool.
Thank you ever so for you blog post.Thanks Again. Really Cool.
Appreciate you sharing, great blog post.Really looking forward to read more. Fantastic.
Thanks so much for the blog article. Cool.
I loved your blog post.Really looking forward to read more. Cool.
I truly appreciate this article post.Much thanks again. Will read on...
Thanks a lot for the blog.Really thank you! Fantastic.
I truly appreciate this blog.
wow, awesome post.Thanks Again. Awesome.
I really liked your blog post.Much thanks again. Much obliged.