-
Notifications
You must be signed in to change notification settings - Fork 510
NativeCallable Attribute could not be found #6187
Comments
You have to define your own, like this: corert/tests/src/Simple/SharedLibrary/NativeCallable.cs Lines 5 to 14 in 998d168
The attribute is not officially exposed from any SDK. The compiler will match it by namespace and name (it doesn't have to be defined in a special assembly). |
Thanks for your answer. Creating that attribute in my assembly corrected the compiler error. When I publish (dotnet publish -r win-x64 -c debug), I get the compiled HelloWorld exe file. When I view this exe file using dependency walker, I don't see the callable method that I added. static void Main(string[] args)
{
CallMe(4, 5);
}
[DllImport("HelloWorld.exe", CallingConvention = CallingConvention.StdCall)]
public static extern void CallMe(int a, int b); The .Net Framework CPU architecture is set to x64 and the call of "CallMe" does load the assembly, but I get an exception "Unable to find an entry point named 'CallMe' in DLL 'HelloWorld.exe' Is there anything else you can think of that I might be missing to get the entry point exported? |
You need to build a library (DLL file), not an EXE. We don't generate the named exports for EXEs (we technically could, but the compiler doesn't do it). Will DLL work for you or do you need EXE? The instructions to make this work with a DLL are here: #5703. |
@rickge BTW if you want another way to see all the methods inside the compiled .exe, you can use the DUMPBIN tool and the I used this whilst writing a post on CoreRT and it gives loads of useful info. |
Thanks. Actually I wanted a dll, but couldn't figure out how to build it. I created a new .Net Core 2.1 class library and added my NativeCallable attributed method to it and used the command at the above post (or a link from the down in the post where the command is documented: #5154) PS C:\Proj.DotNet\SampleCoreRT\CoreLibNative> dotnet build /t:LinkNative /p:NativeLib=Shared Restore completed in 49.43 ms for C:\Proj.DotNet\SampleCoreRT\CoreLibNative\CoreLibNative.csproj. Build FAILED. C:\Proj.DotNet\SampleCoreRT\CoreLibNative\CoreLibNative.csproj : error MSB4057: The target "LinkNative" does not exist in the project. |
I think you need to do |
I'm getting closer and am sorry to be such a bother. The publish creates a .lib, which I didn't expect for a win-x64 target, but I get an error when it is looking for a debug symbols file. PS C:\Proj.DotNet\SampleCoreRT\CoreLibNative> dotnet publish /p:NativeLib=Static -r win-x64 Restore completed in 70.92 ms for C:\Proj.DotNet\SampleCoreRT\CoreLibNative\CoreLibNative.csproj. "/OUT:bin\Debug\netcoreapp2.1\win-x64\native\CoreLibNative.lib" |
This looks like a regression introduced by #5588. You should be able to ignore this error for now. |
If you want a DLL, you need to specify |
My bad on the static vs shared. When I use Shared, I get an error finding a library .def file. I'm guessing I need to do a build step to create the .def file per #5154 or create the .def on my own?
|
I left off the configuration option. Using:
created the desired dll with the desired entry point. |
I've created the HelloWorld example and successfully published using the ILCompiler alpha version '1.0.0-alpha-26807-01', and created a win-x64 exe. I wanted to add a new class with a native callable method exposed and attempted to add the following test class into my HelloWorld namespace:
However, I am not able to find where the NativeCallable attribute is defined. My project is a .Net Core 2.1 version and I've opened it with Visual Studio 15.7.6.
The error I get indicates the attribute isn't found.
Program.cs(21,4): error CS0246: The type or namespace name 'NativeCallableAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\208005772\Documents\Visual Studio 2017\Projects\SampleCoreRT\SampleCoreRT\SampleCoreRT.csproj]
Program.cs(21,4): error CS0246: The type or namespace name 'NativeCallable' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\208005772\Documents\Visual Studio 2017\Projects\SampleCoreRT\SampleCoreRT\SampleCoreRT.csproj]
The text was updated successfully, but these errors were encountered: