title: Compile CSProj in Visual Studio with /CLR:Safe? Fatal Error LNK1302: only support linking safe .netmodules
body: <p>So I am having an issue converting an opensource project (SQLite) to use a different build system and now I'm having trouble linking projects. Essentially I have a VCProj file that has a definition like this:</p>
  
  <pre><code>&lt;Tool
     Name="VCLinkerTool"
     AdditionalOptions="/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp&amp;#x0D;&amp;#x0A;/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp&amp;#x0D;&amp;#x0A;/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp"
     AdditionalDependencies="..\System.Data.SQLite\bin\System.Data.SQLite.netmodule"
     OutputFile="..\bin\System.Data.SQLite.DLL"
     GenerateManifest="false"
     IgnoreDefaultLibraryNames=""
     ModuleDefinitionFile="src\sqlite3.def"
     EmbedManagedResourceFile=""
     DelayLoadDLLs="advapi32.dll"
     RandomizedBaseAddress="1"
     DataExecutionPrevention="0"
     ImportLibrary=""
     KeyFile="..\System.Data.SQLite\System.Data.SQLite.snk"
     CLRUnmanagedCodeCheck="true"
  /&gt;
  </code></pre>
  
  <p>And I am unable to properly link the System.Data.SQLite.netmodule due to the following error:</p>
  
  <blockquote>
    <p>Linking...<br>
    4>..\System.Data.SQLite\bin\System.Data.SQLite.netmodule : fatal error LNK1302: only support  linking safe .netmodules; unable to link pure .netmodule</p>
  </blockquote>
  
  <p>And the System.Data.SQLite.netmodule is generated from a C#/.NET project. How is it I can force it to compile with the <code>/clr:safe</code> option since according to <a href="http://msdn.microsoft.com/en-us/library/9x035d1s%28v=VS.90%29.aspx" rel="nofollow">MSDN</a> this is the way to fix the issue. The problem is is that I don't know how to compile it with <code>/clr:safe</code>. How is it I can do that in the csproj file or in visual studio somewhere? If I am off base in my attempts to fix this please let me know a better way. </p>
  
  <p><strong>UPDATE</strong>:
  So I have determined the issue but I'm not sure why it is an issue. So the interop project (the C project which compiles the sqlite code and links) uses the VCLinkerTool to link to the System.Data.SQLite.netmodule. There is then a C# project that creates the System.Data.SQLite.netmodule using the following command (Anything in {} was added to reduce length):</p>
  
  <p><code>C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /unsafe- /nowarn:1701,1702 /platform:AnyCPU /errorreport:prompt /doc:..\bin\System.Data.SQLite.XML {DLL REFEERENCFES /debug- /filealign:512 /optimize+ /out:obj\Release\System.Data.SQLite.netmodule {RESOURCES AND CS FILES}</code></p>
  
  <p>The problem is with the <code>/platform:AnyCPU</code>. In my build it is <code>/platform:x86</code> and for some reason this causes issues when linking and I'm not sure why but this is what I have narrowed it down to since I can change it to AnyCPU and it will build and link properly. Any insight on this is appreciated.</p>