Skip to content

Instantly share code, notes, and snippets.

@graphnode
Created March 17, 2016 15:54
Show Gist options
  • Save graphnode/e5b3ebab8632f49338a3 to your computer and use it in GitHub Desktop.
Save graphnode/e5b3ebab8632f49338a3 to your computer and use it in GitHub Desktop.
DllImport fail on native compilation.
D:\Projects\sfmlcore\bin\Debug\dnxcore50\win7-x64\native>sfmlcore.exe
Hello World!
ILCompiler failed generating code for this method; execution cannot continue.
This is likely because of a feature that is not yet implemented in the compiler.
Method: [System.Resources.ResourceManager]System.Resources.ResourceManager..ctor
Reason: System.IO.FileNotFoundException: Assembly not found: System.Private.CoreLib.WinRTInterop
at ILCompiler.CompilerTypeSystemContext.GetModuleForSimpleName(String simpleName, Boolean throwIfNotFound)
at Internal.TypeSystem.Ecma.EcmaModule.ResolveAssemblyReference(AssemblyReferenceHandle handle)
at Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(EntityHandle handle)
at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey key)
at Internal.TypeSystem.Ecma.EcmaModule.GetObject(EntityHandle handle)
at Internal.TypeSystem.Ecma.EcmaModule.ResolveTypeReference(TypeReferenceHandle handle)
at Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(EntityHandle handle)
at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey key)
at Internal.TypeSystem.Ecma.EcmaModule.GetObject(EntityHandle handle)
at Internal.TypeSystem.Ecma.EcmaModule.ResolveMemberReference(MemberReferenceHandle handle)
at Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(EntityHandle handle)
at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey key)
at Internal.TypeSystem.Ecma.EcmaModule.GetObject(EntityHandle handle)
at Internal.JitInterface.CorInfoImpl.resolveToken(CORINFO_RESOLVED_TOKEN& pResolvedToken)
at Internal.JitInterface.CorInfoImpl.resolveToken_wrapper(IntPtr _this, IntPtr& exception, CORINFO_RESOLVED_TOKEN& pResolvedToken)
using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication
{
[StructLayout(LayoutKind.Sequential)]
public class OpenFileName
{
public int structSize;
public IntPtr dlgOwner = IntPtr.Zero;
public IntPtr instance = IntPtr.Zero;
public string filter;
public string customFilter = null;
public int maxCustFilter = 0;
public int filterIndex = 0;
public string file;
public int maxFile;
public string fileTitle;
public int maxFileTitle;
public string initialDir;
public string title;
public int flags = 0;
public short fileOffset = 0;
public short fileExtension = 0;
public string defExt;
public IntPtr custData = IntPtr.Zero;
public IntPtr hook = IntPtr.Zero;
public string templateName = null;
public IntPtr reservedPtr = IntPtr.Zero;
public int reservedInt = 0;
public int flagsEx = 0;
}
public class Program
{
[DllImport("comdlg32.dll")]
public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var ofn = new OpenFileName();
ofn.structSize = Marshal.SizeOf(ofn);
ofn.filter = "All files\0*.*\0Log files\0*.log\0Batch files\0*.bat\0";
ofn.file = new string(new char[256]);
ofn.maxFile = ofn.file.Length;
ofn.fileTitle = new string(new char[64]);
ofn.maxFileTitle = ofn.fileTitle.Length;
ofn.initialDir = @"C:\";
ofn.title = "Open file called using platform invoke...";
ofn.defExt = "txt";
if (GetOpenFileName(ofn))
{
Console.WriteLine("Selected file with full path: {0}", ofn.file);
Console.WriteLine("Selected file name: {0}", ofn.fileTitle);
Console.WriteLine("Offset from file name: {0}", ofn.fileOffset);
Console.WriteLine("Offset from file extension: {0}", ofn.fileExtension);
}
Console.WriteLine("Goodbye World!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment