开发者

Code behaves weird when platform target is set to Any CPU like WPF projects is ?

This code should give me a collection of FilterInfo objects, representing the connected devices in the chosen category, which in this case is webcams.

FilterInfoCollection collection = new FilterInfoCollection(FilterCategory.VideoInputDevice);

I tested this in a console application, and it worked great, but when i bring the code into WPF, it only returns one object.

I tried using it directly in xaml codebehind and in viewmodel bound to xaml controls, but same result.

This is so bloody frustrating Thanks in advance =)

开发者_高级运维

EDIT:

I found the cause, the WPF project "Platform Target" is set to "Any CPU", and the console app is set to x86. When i set the console app "Platform target" to "any cpu" it does exactly the same.

But unfortunately, the WPF project wont run when set to x86


Taking a guess here but it sounds like the FilterInfoCollection is returning a difference based on whether the drivers are x64 or x86.

If you force it to compile in x86 mode then it's able to retrieve all of the x86 drivers.

Any CPU mode is going to execute in either x64 or x86 depending on the OS installed. If it's a 64bit OS, then it will run in x64 mode. This means it's only going to return x64 based drivers, of which it sounds like there is just one installed on your system.

Regarding issues in running a WPF application with a platform target of x86, you should provide more detail such as what error(s) you are seeing. There shouldn't be an issue here: Setting platform target to x86 on my x64 laptop prevent some WPF types to load properly


Have you tried to change Target Framework from 4.0 to 3.5? Cause I had a similar issue and when I changed target framework it was good.


I tried creating a new WPF project in the same solution, and now it works. Sometimes i hate code with a passion... =P

Thanks for your help though! I will keep my eyes open if this thing happens again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜