{"action":"closed","issue":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/20279","repository_url":"https://api.github.com/repos/dotnet/coreclr","labels_url":"https://api.github.com/repos/dotnet/coreclr/issues/20279/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/20279/comments","events_url":"https://api.github.com/repos/dotnet/coreclr/issues/20279/events","html_url":"https://github.com/dotnet/coreclr/issues/20279","id":367051984,"node_id":"MDU6SXNzdWUzNjcwNTE5ODQ=","number":20279,"title":"different behavior in dllimport in netcoreapp2.0 vs netstandard2.0 in Linux","user":{"login":"roozbehid-ic","id":19397034,"node_id":"MDQ6VXNlcjE5Mzk3MDM0","avatar_url":"https://avatars1.githubusercontent.com/u/19397034?v=4","gravatar_id":"","url":"https://api.github.com/users/roozbehid-ic","html_url":"https://github.com/roozbehid-ic","followers_url":"https://api.github.com/users/roozbehid-ic/followers","following_url":"https://api.github.com/users/roozbehid-ic/following{/other_user}","gists_url":"https://api.github.com/users/roozbehid-ic/gists{/gist_id}","starred_url":"https://api.github.com/users/roozbehid-ic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roozbehid-ic/subscriptions","organizations_url":"https://api.github.com/users/roozbehid-ic/orgs","repos_url":"https://api.github.com/users/roozbehid-ic/repos","events_url":"https://api.github.com/users/roozbehid-ic/events{/privacy}","received_events_url":"https://api.github.com/users/roozbehid-ic/received_events","type":"User","site_admin":false},"labels":[{"id":244582102,"node_id":"MDU6TGFiZWwyNDQ1ODIxMDI=","url":"https://api.github.com/repos/dotnet/coreclr/labels/area-Interop","name":"area-Interop","color":"d4c5f9","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/dotnet/coreclr/milestones/18","html_url":"https://github.com/dotnet/coreclr/milestone/18","labels_url":"https://api.github.com/repos/dotnet/coreclr/milestones/18/labels","id":3246413,"node_id":"MDk6TWlsZXN0b25lMzI0NjQxMw==","number":18,"title":"3.0","description":".NET Core 3.0, next major release after 2.1. See [official release dates](https://github.com/dotnet/core/blob/master/roadmap.md) for details.\r\n\r\nWe will move important issues from Future to 3.0 as the priorities and dates for next release become more clear.","creator":{"login":"karelz","id":5776068,"node_id":"MDQ6VXNlcjU3NzYwNjg=","avatar_url":"https://avatars2.githubusercontent.com/u/5776068?v=4","gravatar_id":"","url":"https://api.github.com/users/karelz","html_url":"https://github.com/karelz","followers_url":"https://api.github.com/users/karelz/followers","following_url":"https://api.github.com/users/karelz/following{/other_user}","gists_url":"https://api.github.com/users/karelz/gists{/gist_id}","starred_url":"https://api.github.com/users/karelz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karelz/subscriptions","organizations_url":"https://api.github.com/users/karelz/orgs","repos_url":"https://api.github.com/users/karelz/repos","events_url":"https://api.github.com/users/karelz/events{/privacy}","received_events_url":"https://api.github.com/users/karelz/received_events","type":"User","site_admin":false},"open_issues":248,"closed_issues":309,"state":"open","created_at":"2018-04-05T22:09:22Z","updated_at":"2018-11-06T20:53:51Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2018-10-05T04:04:07Z","updated_at":"2018-11-06T20:53:51Z","closed_at":"2018-11-06T20:53:50Z","author_association":"NONE","body":"I've found some strange behavior when targeting netstandard2.0 and cost me at least 10 hours to find easy/strange fix.\r\n\r\nfoo.c:\r\n\r\n    #include <stdio.h>\r\n    void foo(void)\r\n    {\r\n      puts(\"Hello, I'm a shared library\");\r\n    }\r\n\r\nrun following commands in your bash \r\n     \r\n     gcc -c -fpic foo.c\r\n     gcc -shared -o libfoo.so foo.o\r\n\r\n     \r\ntest.csproj\r\n\r\n      <Project Sdk=\"Microsoft.NET.Sdk\">\r\n      \r\n        <PropertyGroup>\r\n          <OutputType>Exe</OutputType>\r\n          <TargetFramework>netstandard2.0</TargetFramework>\r\n        </PropertyGroup>\r\n      </Project>        \r\n\r\nProgram.cs\r\n\r\n      using System;\r\n      using System.Runtime.InteropServices;\r\n      \r\n      namespace cs\r\n      {\r\n          class Program\r\n          {\r\n              [DllImport(\"foo\")]\r\n              private static extern void foo();\r\n      \r\n              static void Main(string[] args)\r\n              {\r\n                 foo();\r\n                  Console.WriteLine(\"Hello World!\");\r\n              }\r\n          }\r\n      }\r\n\r\nSo now if you run it with TargetFramework as netcoreapp2.0. It will work.\r\n\r\nIf you run it with TargetFramework as netstandard2.0 you will get an exception on foo module not found.\r\n\r\n      Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'foo': The specified module could not be found. (Exception from HRESULT: 0x8007007E)\r\n      at cs.Program.foo()\r\n      at cs.Program.Main(String[] args) in /mnt/d/Projects/test/bugtest/cs/Program.cs:line 13\r\n\r\nWhat I experienced in my bigger project being compiled as netstandard2.0 was that with presence of foo.dll, it would generate \"bad image format exception\".\r\nBut renaming it to libfoo.so I would get \"no module found\" which was way more challenging as I was pointing the problem to my C++ code and probably something being wrong with it!\r\n\r\nAnyway I know this is a console app so it should be netcoreapp2.0 but it is a common mistake that I do (and assume many others) which also end up in a binary that runs anyway! (if it is a wrong target why compiler does not warn?!)\r\n\r\n-----------------------------\r\nAdditional info:\r\nRan in WSL (ubuntu 16.04)\r\ndotnet --version : 2.1.104"}}
{"actor":{"display_login":"roozbehid-ic"}}