title: TypeLoadException only in VS2013 and only for VB.NET
body: <p>I've tried everything in my knowledge to fix this but as I can't here I am asking for help.</p>
  
  <p>Basically I have an issue with some VB.NET code that throws a TypeLoadException.
  This is code that was written ages ago and has always worked without a problem.</p>
  
  <ul>
  <li>If the code is built in VS2013 it fails. </li>
  <li>If the code is built in VS2017 it works.</li>
  <li>If the project is built in VS2017 and opened in VS2013 (without rebuilding) is works. After a rebuild, problem comes back.</li>
  </ul>
  
  <p>I converted the code to C# and it works even if built in VS2013.</p>
  
  <p>The only thing that I have done recently is to clean up temporary files in my system (Win7 64) so I am thinking maybe something happened due to this but my knowledge of Visual Studio isn't sufficient to understand what could be happening.</p>
  
  <p>Before I try to repair VS2013 wanted to know if this happened to someone else and if a solution was found. </p>
  
  <p>To add to the confusion the problem exists only with generic classes!</p>
  
  <p>I have created sample code to run in a console application to replicate the problem and here it is:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Imports System.Runtime.CompilerServices
  
  Module Module1
  
      Sub Main()
  
          Dim ng As New NonGenericClass
          ng.WriteToLog() ' Works
  
          Dim g = New GenericClass(Of IO.FileInfo)
          g.WriteToLog() ' Fails with TypeLoadException
  
      End Sub
  
  End Module
  
  Public Class GenericClass(Of T)
      Implements IHasLogger
  
      Public Sub WriteToLog()
          Log.Info("some message")
      End Sub
  
  
  End Class
  
  Public Class NonGenericClass
      Implements IHasLogger
  
      Public Sub WriteToLog()
          Log.Info("some message")
      End Sub
  
  End Class
  
  Public Interface ILogger
  
      Sub Info(message As String)
  
  End Interface
  
  Public Class Logger
      Implements ILogger
  
      Public Sub Info(message As String) Implements ILogger.Info
          Debug.Print(message)
      End Sub
  End Class
  
  Public Interface IHasLogger
  
  
  
  End Interface
  
  Public Module LoggerMixin
  
      &lt;Extension&gt;
      Public Function Log(Of T As IHasLogger)(this As T) As ILogger
          Return New Logger
      End Function
  
  
  End Module
  </code></pre>
  
  <p>I assume the issue is with the visual basic compiler at this point as c# has no problems. </p>
  
  <p>Using VS2017 is not an option because the project uses controls from DevExpress and I don't have a license for a version compatible with VS2017.</p>
  
  <p>Thanks for your help.</p>
  
  <p><strong>-- UPDATE -- (Exception information)</strong></p>
  
  <p>System.TypeLoadException: Could not load type 'ConsoleApplication1.GenericClass<code>1' from assembly 'ConsoleApplication13, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
     at ConsoleApplication1.GenericClass</code>1.WriteToLog()
     at ConsoleApplication1.Module1.Main() in E:\Projects\Temp\ConsoleApplication13\ConsoleApplication13\Module1.vb:line 13</p>
  
  <p><strong>-- FIX --</strong></p>
  
  <p>As suggested by <em>TnTinMn</em> using Me.Log (as opposed to just Log) allows to circumvent the problem. For now I will go with that.
  And now that I come to think of it in C# you would need to call this.Log which is equivalent to Me.Log in VB.NET so my comments about it working in C# don't really apply.</p>
  
  <p>Thanks to all for the help. If anyone knows or finds out why this happens I would still like to know :-)</p>