Object of type “X” cannot be converted to object o

2019-01-18 09:45发布

(Can't believe this hasn't already been asked, but I can't find a dup)

In Visual Studio with lots of projects, when I first open the solution, I sometimes get the warning Object of type "X" cannot be converted to object of type "X". Generally rebuilding seems to make it go away, but does anyone know what this is caused by, and how to avoid it?

UPDATE I read somewhere that deleting all your resx files and rebuilding can help. I unthinkingly tried this. Not a good idea...

8条回答
Root(大扎)
2楼-- · 2019-01-18 10:30

I had the same error, I tried some solutions above but nothing worked for me, then I removed the content of the value tag of the data tag of my property in resx file.

For example if the property witch produce the error is MyProp in a MyUserControl user control, you will find in resx file a data tag with the name MyUserControl.MyProp, remove the content of it's value tag.

查看更多
虎瘦雄心在
3楼-- · 2019-01-18 10:33

I came across the same problem, and while Marc's answer did help me to understand what was going wrong, it did not solve my problem. Rebuilding did not help, and I was not using serialization in this case.

Turns out my problem was happening because my project had a reference to itself (not quite sure how that happened, perhaps Resharper added the reference without me noticing?), and it was comparing the .cs file with the compiled .dll file. I simply removed the reference.

Hope this helps anyone else with the same issue!

查看更多
登录 后发表回答