none
Unexpected error with EventArgs namespace. RRS feed

  • Question

  • I have two C# applications A & B. A>>B. A is an old one which I debugged years ago and it's been my workhorse. B is much smaller but still needs some improvement, so I have been stealing code blocks from A to improve B. Today I worked for about 6 hours with B and then all of a sudden it started giving me dozens of compile errors. One o them is actually known on the web.

    Severity	Code	Description	Project	File	Line	Suppression State
    Error	CS0246	The type or namespace name 'EventArgs' could not be found (are you missing a using directive or an assembly reference?)	SQLServerSampleCodes	C:\VCSharp_Projects\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\Form1.cs	184	Active

    I restarted the computer to no avail. There are other similar errors.

    Application A still compiles with no problems. EventArgs are there in abundance.Console now is underlined red as well as String.Empty, Exception, etc.

    What can be done?

    Thanks, - MyCatAlex




    • Edited by MyCatAlex Thursday, January 16, 2020 3:19 PM
    Monday, January 13, 2020 10:09 PM

Answers

  • If you have not done so already add a using statement for system or preface it with System.

    Example

    private void GetButton_Click(object sender, System.EventArgs e)


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by MyCatAlex Tuesday, January 14, 2020 12:26 AM
    Monday, January 13, 2020 11:33 PM
    Moderator

All replies

  • If you have not done so already add a using statement for system or preface it with System.

    Example

    private void GetButton_Click(object sender, System.EventArgs e)


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by MyCatAlex Tuesday, January 14, 2020 12:26 AM
    Monday, January 13, 2020 11:33 PM
    Moderator
  • It surely WORKED but what about this:

    Severity	Code	Description	Project	File	Line	Suppression State
    Error	CS0246	The type or namespace name 'DateTime' could not be found (are you missing a using directive or an assembly reference?)	SQLServerSampleCodes	C:\VCSharp_Projects\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\Form1.cs	730	Active
    

    Console is missing, Exception is missing, etc. I will mark you post as answer but I want explanations why this thing is going on?

    Thanks, - MyCatAlex

    Tuesday, January 14, 2020 12:26 AM
  • It works for System.DateTime too. Many thanks, - MyCatAlex
    Tuesday, January 14, 2020 12:28 AM
  • Now it compiles but gives me this exception:

    System.IO.FileNotFoundException
      HResult=0x80070002
      Message=Could not load file or assembly 'Microsoft.SqlServer.SqlEnum, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
      Source=SQLServerSampleCodes
      StackTrace:
       at SQLServerSampleCodes.Form1.Fillcombo_SQLCodePackages_PG1() in C:\VCSharp_Projects\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\Form1.cs:line 121
       at SQLServerSampleCodes.Form1.pushFillCombo_pg1_Click(Object sender, EventArgs e) in C:\VCSharp_Projects\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\Form1.cs:line 791
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at SQLServerSampleCodes.Program.Main() in C:\VCSharp_Projects\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\Program.cs:line 19
    

    What is the problem?

    - MyCatAlex

    Tuesday, January 14, 2020 12:46 AM
  • After I fixed that, it is now asking for another dll or something else? How come it worked flawlessly for months without them?

    System.MissingMethodException
      HResult=0x80131513
      Message=Method not found: 'Microsoft.SqlServer.Management.Common.ISfcConnection Microsoft.SqlServer.Management.Sdk.Sfc.ISfcHasConnection.GetConnection(Microsoft.SqlServer.Management.Sdk.Sfc.SfcObjectQueryMode)'.
      Source=SQLServerSampleCodes
      StackTrace:
       at SQLServerSampleCodes.Form1.Fillcombo_SQLCodePackages_PG1() in C:\VCSharp_Projects\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\Form1.cs:line 119
       at SQLServerSampleCodes.Form1.pushFillCombo_pg1_Click(Object sender, EventArgs e) in C:\VCSharp_Projects\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\Form1.cs:line 789
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at SQLServerSampleCodes.Program.Main() in C:\VCSharp_Projects\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\Program.cs:line 19

    -MyCatAlex




    • Edited by MyCatAlex Tuesday, January 14, 2020 1:06 AM
    Tuesday, January 14, 2020 12:59 AM
  • Hi MyCatAlex,

    Thanks you for posting here.

    According to the error message, you did not add the required NuGet package.

    Please follow these steps to add them: 

    1. Click the Reference of the project. 

    2. Select Manage NuGet Packages.

    3. Search for the required NuGet package and download.

    As for Microsoft.SqlServer.SqlEnum, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91',it is related to SQL Server 2017 and SSMS 2017. The related file will be included in the installation of SSMS 2017.

    You can solve this problem by installing SQL Server Management Studio (SSMS) 17 or later version.

    Download SQL Server Management Studio (SSMS)

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 14, 2020 1:51 AM
  • The file Microsoft.SqlServer.SqlEnum, part of SMO SQL-Management Objects is expected.

    Go to project references, find Microsoft.SqlServer.SqlEnum, select properties and look at Copy Local, if its false and Path points to the GAC try changing copy local to true.

    Also note SMO is specific to a specific version of SQL-Server so a version of SQL-Server 2017 is different than SQL-Server 2012.

    SMO is also installable from Solution Explorer, NuGet package Manager. The first one has multiple versions.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Tuesday, January 14, 2020 1:53 AM
    Moderator
  • According to the error message, you did not add the required NuGet package.

    Please follow these steps to add them: 

    1. Click the Reference of the project. 

    2. Select Manage NuGet Packages.

    3. Search for the required NuGet package and download.

    You can solve this problem by installing SQL Server Management Studio (SSMS) 17 or later version.

    Download SQL Server Management Studio (SSMS)

    Hope this could be helpful.

    Best Regards,

    Timon



    Timon hi, My version of Microsoft SSMS is 18. I believe I installed nuGet but now cannot find it. I have Microsoft.SqlServer.SqlEnum referenced. I have Microsoft.SqlServer.Smo referenced in this project. Still I get the Exception which is hard to explain.

    Thanks, - MyCatAlex

    Tuesday, January 14, 2020 11:28 PM
  • Karen hi,

    I found out that I have NuGet installed and under Tools tab in SSMS I have a tab Nuget Package Manager. I have SMO installed for sure. Still I get the Exception which I have already posted but want to do it again.

    System.MissingMethodException
      HResult=0x80131513
      Message=Method not found: 'Microsoft.SqlServer.Management.Common.ISfcConnection Microsoft.SqlServer.Management.Sdk.Sfc.ISfcHasConnection.GetConnection(Microsoft.SqlServer.Management.Sdk.Sfc.SfcObjectQueryMode)'.
      Source=SQLServerSampleCodes
      StackTrace:
       at SQLServerSampleCodes.Form1.Fillcombo_SQLCodePackages_PG1() in C:\VCSharp_Projects\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\Form1.cs:line 120
       at SQLServerSampleCodes.Form1.pushFillCombo_pg1_Click(Object sender, EventArgs e) in C:\VCSharp_Projects\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\Form1.cs:line 790
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at SQLServerSampleCodes.Program.Main() in C:\VCSharp_Projects\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\SQLServerSampleCodes\Program.cs:line 19
    

    What Shall I do?

    - MyCatAlex

    Tuesday, January 14, 2020 11:48 PM
  • SMO as mentioned before is version specific to the version of SQL-Server that is installed so you can try different versions of SMO via NuGet Package Manager.

    Let's say I is SMO with SQL-Server 2012, all works correctly then use the exact same code on another computer with SQL-Server 2014 (or any other version of SQL-Server) with the same references, on the computer with SQL-Server 2014 the code will not compile. Why? Because there are differences in the underlying classes and Interfaces that it will not compile.

    I've dealt with this while writing the following TechNet article while at home used SQL-Server 2012, at work I needed to change all references for SMO libraries for SQL-Server 2017.

    https://social.technet.microsoft.com/wiki/contents/articles/52098.smosql-server-vb-net-part-1.aspx

    Hopefully this makes sense.

    If you don't have SSMS installed, install it, remove the references from your project them add them in from SSMS. In my case they are under C:\Program Files(x86)\Microsoft SQL Server\130\SDK\Assemblies for SQL-Server 2012. 


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, January 15, 2020 12:10 AM
    Moderator