The other day while working in Visual Studio 2008, I encountered an unexpected error while attempting to create a DataGrid by dragging a table from the Data Sources pane onto a form (something we've all done many times).
At first Visual Studio appeared to be creating the DataGrid and associated components (BindingSource, TableAdapter, etc.) correctly but then Visual Studio threw an error:
|
An error occurred while performing the drop:
Length cannot be less than zero. Parameter name: length |

|
The error message might have been useful if I had access to the Visual Studio source code – but I was just using Visual Studio, not building it. Needless to say, the error message was of little help. J So I did what we all do in such situations, used trial-and-error.
The project calls a WCF service through a proxy generated by NetCfSvcUtil.exe; as an experiment, I decided to remove the WCF proxy from the project (and any calls to the proxy) to see what happened.
… VOILA …
Visual Studio was then able to create the DataGrid with no problem.
To verify what I had observed, I added the WCF proxy (and any associated calls) back into the project and deleted the DataGrid. Just as before, when I tried to create the DataGrid, Visual Studio threw the same error – so now I know where to start looking for the problem.
When I checked out the source file for the WCF proxy I realized that there was no namespace declaration. As you may know, if you run the NetCFSvcUtil without specifying the "/namespace" option then the types are not placed within a namespace….
So as an attempt at a solution, I created the WCF proxy so that the contained types were in a namespace (and added the appropriate using statement to the form class) – I then deleted the DataGrid from the form. Now when I dragged the table from the DataSource pane to the form, the DataGrid was created without any trouble - putting the types in a namespace completely resolved the problem. The program also compiles and runs as expected.
Now things are working – My assumption at this point was that there must have been a type name conflict (or something similar) between the WCF proxy types and the DataGrid-related types; seemed a reasonable assumption.
… BUT… here's the thing …
To confirm my assumption about the name conflict, I created the WCF proxy so that the contained types were not in a namespace (and of course removed the associated using statements) but left the generated DataGrid place. If there were a type name conflict between the DataGrid-related types and the WCF proxy the compiler should report the error
… BUT … get this …
The code compiles and runs perfectly --- the namespace was required for Visual Studio to create the DataGrid (and/or associated components) but the namespace is not required for the code to compile and run -- what?!?!
So what does this all mean? … At this point my guess is that Visual Studio and the DataGrid creation process have a type name sensitivity that may not be consistent with the .NET CF language requirements. If that is the case it would appear to indicate a possible bug but can't be 100% certain until the problem is narrowed down specifically.
I haven't had a chance to narrow down things further quite yet but I hopefully will shortly. As soon as I have the answer I'll post it here.
One thing to keep in mind, if you do run into the error I describe above, look for any possible name conflicts or classes outside of a namespace. It seems that there's a good chance that that's the source of the problem.
I hope to have more to report soon.
Posted
Apr 08 2008, 10:32 AM
by
jim-wilson