0

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 related problems that may seem to be the same (but looks like it is not the same - only related):

File (or assembly) can't be found after changing project's .NET target-framework from 4.0 to 3.5

Downgrade an application from .net 4.0 to 3.5

Issues with RESX files on VS2010 targeting 3.5 framework

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).

And now the problem itself: Project build succeeds, but when application is runned, I get a FileNotFoundException in the form designer code 'resources.GetObject("myImageName")':

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& stackMark, Boolean loadTypeFromPartialName)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.RuntimeType.PrivateGetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& 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& typeCode)
at System.Resources.ResourceReader.LoadObject(Int32 pos, ResourceTypeCode& 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()

I asked the question about this problem on Microsoft site and found one more person who have exactly the same issue. But his question was ignored and my isnt answered yet as well.

Environment: 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)

Investigation details:

  • resx files do not contain references to 4.0 assemplies. Especially it is referencing System.Windows.Forms 2.0 and System.Drawing 2.0
  • project doesn't (and can't contain references to any 4.0 assembly, because it has TargetFramwork 2.0)
  • Searching the whole project folder for "4.0" entries found strange fact: 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).
  • switching resgen to 32bit mode doesn't help. Reverting it also useless.
  • changing proj file with notepad to use "correct" version of resgen doesn't help as well
  • the whole day of investigation and many other tries were unsuccessful. I even haven't found many people that had the same problem.
  • 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
Community
  • 1
  • 1
Sasha
  • 8,197
  • 4
  • 48
  • 74
  • The .resx file contains resources that are encoded in base64. Which prevents you from seeing that one of them has a reference to a 4.0 assembly embedded. You'll need to switch back to .NET 4, remove the resources, switch to 3.5 and add them back. – Hans Passant May 30 '12 at 13:54
  • I haven't changed anything in the resx file since it was working fine. So, how cluld reference to Winforms 4.0 be added there? WE have source control in this project and it says that file wasn't changed. I read on some forum to check resx file for the string "j00" in the first line of binary data and replace it with "j0y". I suppose it is the version of referenced DLL you've mentioned. But it is equal to "j0y" as expected. – Sasha May 30 '12 at 16:26
  • One more thing: after 2 days of investigation this problem became global and now reproduces in all projects With TargetFramework < 4 and with many resources (strange, but not all resources thogh), so changing all that by hands is almost impossible. There should be other way I hope – Sasha May 30 '12 at 16:30
  • I tried your recommendation, but even readding resource by hands, using TargetFramework=2.0 doesn't help in this situation =(. Tee same exception. – Sasha May 30 '12 at 17:08

0 Answers0