title: VS2010 running project with TargetFramework 2.0 and resx files causes FileNotFound 'System.Windows.Forms v4.0'
body: <p>I have a problem with running application from MS Visual Studio 2010. Actually it is a long story and I faced different related problems before. But the project worked for at least half a year without changes. And now I'm trying to run it again, but without effect. At first here is few links about <strong>related problems</strong> that may seem to be the same (but looks like it is not the same - only related):</p>
  
  <p><a href="https://stackoverflow.com/questions/3709295/file-or-assembly-cant-be-found-after-changing-projects-net-target-framework">File (or assembly) can&#39;t be found after changing project&#39;s .NET target-framework from 4.0 to 3.5</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3181813/downgrade-an-application-from-net-4-0-to-3-5">Downgrade an application from .net 4.0 to 3.5</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3398689/issues-with-resx-files-on-vs2010-targeting-3-5-framework">Issues with RESX files on VS2010 targeting 3.5 framework</a></p>
  
  <p>My project has TargetFramework=2.0 and it contains few resx resource files with images and icons for the app. I used to have problems with resource files compilation before, but fixed them, like in the posts in links above. And all worked fine until yesterday (I haven't opened that project for long time, so can't say what exactly has changed in the environment).</p>
  
  <p>And now <strong>the problem itself</strong>: Project build succeeds, but when application is runned, I get a FileNotFoundException in the form designer code 'resources.<em>GetObject</em>("myImageName")':</p>
  
  <pre><code>Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
  at System.RuntimeTypeHandle._GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark&amp; stackMark, Boolean loadTypeFromPartialName)
  at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark&amp; stackMark)
  at System.RuntimeType.PrivateGetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark&amp; stackMark)
  at System.Type.GetType(String typeName, Boolean throwOnError)
  at System.Resources.ResourceReader.FindType(Int32 typeIndex)
  at System.Resources.ResourceReader.DeserializeObject(Int32 typeIndex)
  at System.Resources.ResourceReader.LoadObjectV2(Int32 pos, ResourceTypeCode&amp; typeCode)
  at System.Resources.ResourceReader.LoadObject(Int32 pos, ResourceTypeCode&amp; typeCode)
  at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase, Boolean isString)
  at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase)
  at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)
  at System.Resources.ResourceManager.GetObject(String name)
  [MYAPP stack trace part. Hope you don't need it]
  at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
  at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
  at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
  at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  at System.Threading.ThreadHelper.ThreadStart()
  </code></pre>
  
  <p>I asked the question about <a href="https://connect.microsoft.com/VisualStudio/feedback/details/532584/error-when-compiling-resx-file-seems-related-to-beta2-bug-5252020#tabs" rel="nofollow noreferrer">this problem on Microsoft site</a> and found one more person who have exactly the same issue. But his question was ignored and my isnt answered yet as well.</p>
  
  <p><strong>Environment:</strong>
  Windows 7 x64, .NET 4.0 SP1, VS 2010 Ultimate SP1. Project build configuration: Debug/AnyCPU (I tried Debug/Release for AnyCPU/x86 - all the same. x64 and IA64 - are impossible for this project)</p>
  
  <p><strong>Investigation details:</strong></p>
  
  <ul>
  <li>resx files do not contain references to 4.0 assemplies. Especially it is referencing System.Windows.Forms 2.0 and System.Drawing 2.0</li>
  <li>project doesn't (and can't contain references to any 4.0 assembly, because it has TargetFramwork 2.0)</li>
  <li>Searching the whole project folder for "4.0" entries found <em>strange fact</em>: my exe file has reference to mscorlib 4.0. Actually I can't figure out how it could happen and how to fix it. Though AppDomain.CurrentDomain.GetAssemblies() returns mscorlib 2.0, not 4.0 (and all other .NET assemblies of version 2.0 as well).</li>
  <li>switching resgen to 32bit mode doesn't help. Reverting it also useless.</li>
  <li>changing proj file with notepad to use "correct" version of resgen doesn't help as well</li>
  <li>the whole day of investigation and many other tries were unsuccessful. I even haven't found many people that had the same problem.</li>
  <li>The same is for TargetFramework=3.5, but when setting TargetFramework=4.0, all start working well. Unfortunately, it isn't possible to move to .NET 4.0 currently</li>
  </ul>