Results 1 to 7 of 7

Thread: [RESOLVED] NET 5.0 got DllImport CS0246 error

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    597

    Resolved [RESOLVED] NET 5.0 got DllImport CS0246 error

    First touch NET 5.0, but I got CS0246 error, don't know what is the reason.
    Refer to screenshot.
    Attached Images Attached Images  

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: NET 5.0 got DllImport CS0246 error

    So when you showed potential fixes, as instructed by Intellisense, what did it suggest?

  3. #3
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: NET 5.0 got DllImport CS0246 error

    Quote Originally Posted by DaveDavis View Post
    First touch NET 5.0, but I got CS0246 error, don't know what is the reason.
    Refer to screenshot.
    If this is a .NET Core Console App or WPF, the System.Runtime.InteropServices namespace is listed in Dependencies->Frameworks->Microsoft.NETCore.App, so you should be able to use the DllImport attribute class.
    Otherwise, the DllImport could be misspelled.

    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    597

    Re: NET 5.0 got DllImport CS0246 error

    Intellisense is nothing when I am keying in DllImport; The NET Core is different from Winform NETFramework...But sure something is wrong with what I am doing...
    Attached Images Attached Images   

  5. #5
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: NET 5.0 got DllImport CS0246 error

    If System.Runtime.InteropServices is listed under Microsoft.NETCore.App, but errors occur when referencing these classes, then there must be something wrong with the Visual Studio IDE. I tried adding DllImport attribute in .NET Core Winforms project Form1 class without error(s).
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: NET 5.0 got DllImport CS0246 error

    Quote Originally Posted by DaveDavis View Post
    Intellisense is nothing when I am keying in DllImport
    Ugh. Look at the screenshot you provided in post #1. See the Intellisense popup? See how it provides the option to show potential fixes? Maybe you should use that.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    597

    Re: NET 5.0 got DllImport CS0246 error

    OK.
    I recreate the project, then I see DllImport is intellisensed.
    First touching NET CORE gives me a lesson, but it is good to learn something. Thank you everyone.

    Edited: I replace the *.csproj with the new one, the problem also goes away.
    Last edited by DaveDavis; Sep 30th, 2021 at 08:47 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width