Answered by:
How do I Exclude auto generated (DataSet) classes from code analysis

Question
-
The Code Analysis tool appears to be including auto generated code that was generated by a DataSet file (XSD). Namely it comes back with a CA2240 Implement ISerializable correctly message. The top of the auto generated file contains this header.
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18052
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
Does anyone know how to resolve this?
Steps to reproduce.
- Create a new project (Class Library)
- Add a new DataSet.
- Add a new table adapter to the dataset; I added a text query for AdventureWorks2012.Person.Person
- Set Code Analysis rule set in project properties to "Microsoft Managed Recommended Rules"
- Run Code Analysis.
Expected:
No Issues found
Actual:
2 instances of
CA2240 Implement ISerializable correctly
Add an implementation of GetObjectData to type 'DataSet1'.
CodeAnalysisDemo - DataSet1.Designer.cs (Line xx)Tuesday, September 24, 2013 9:38 PM
Answers
-
Hi tx018,
The similar issue has been submitted to the connect report here:
http://connect.microsoft.com/VisualStudio/feedback/details/465841/datasets-and-code-analysis
Reference:
http://stackoverflow.com/questions/5789972/ca2240-warning-for-dataset-and-datatable-within
Best Regards,
Jack Zhai[MSFT]
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Marked as answer by tx018 Thursday, September 26, 2013 2:59 PM
Thursday, September 26, 2013 2:17 AM
All replies
-
Hi tx018,
The similar issue has been submitted to the connect report here:
http://connect.microsoft.com/VisualStudio/feedback/details/465841/datasets-and-code-analysis
Reference:
http://stackoverflow.com/questions/5789972/ca2240-warning-for-dataset-and-datatable-within
Best Regards,
Jack Zhai[MSFT]
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Marked as answer by tx018 Thursday, September 26, 2013 2:59 PM
Thursday, September 26, 2013 2:17 AM -
I appreciate the answer you attempted to give me. But, it leaves out the fact that the check box intended to exclude generated code is misleading because it does not actually exclude generated code. I will have to ignore all those warnings.
Thursday, September 26, 2013 2:59 PM -
I have a similar issue. Have you resolved this issue or suppressed warnings. What could be consequences if we suppress this warnings ? I really don't want to mess with auto generated code to solve this issue
Saranhya
Tuesday, January 3, 2017 5:30 AM