问题
I am sorry about the title of this post, but I've no idea how to describe my problem.
So, I've got the following really simple code:
dynamic obj = new myClass(); // In my case it is a COM object
int FileCount = 0;
FileCount = obj.SomeMethod();
But at runtime I get something like this:
Whats going on there? Why isn't Filecount = 0? Why is it null?
回答1:
Are you in Release build?. If FileCount is not used somewhere else the variable might be optimized out by the compiler. Try doing that in Debug build. Also this can be caused by pdb files mismatch. Clean all your output dirs and recompile the application.
回答2:
Optimised out I should think, the initialisation is certainly pointless
int FileCount = obj.SomeMethod();
Because it's dynamic all sorts of compiler magic happen to evade errors, daresay this one is down to all the code that gets whapped in behind the scenes to deal with obj being dynamic.
来源:https://stackoverflow.com/questions/8065735/object-doesnt-take-value