Bug 34091 - resgen introduces dependency to versioned System.Windows.Forms
Summary: resgen introduces dependency to versioned System.Windows.Forms
Status: CONFIRMED
Alias: None
Product: Tools
Classification: Mono
Component: resgen ()
Version: unspecified
Hardware: PC All
: --- minor
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-09-19 19:08 UTC by Hin-Tak Leung
Modified: 2017-09-07 10:27 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 34091 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Hin-Tak Leung 2015-09-19 19:08:27 UTC
I am building .net binaries with mono 4.0.x targeting the older .net 2.0 runtime with

/nostdlib /platform:AnyCPU /reference:/usr/lib/mono/2.0/System.dll \
/reference:/usr/lib/mono/2.0/mscorlib.dll \
-lib:/usr/lib/mono/2.0

For command line tool this works. But for a GUI program, I was surprised
to see that when it runs under the older 2.0 runtime, it still tries to access the newer 4.0 System.Windows.Forms.

Then I figure out the problem is resgen when it generates the SWF resource files from the resx files.

I found a work-around by using MS .net 2.0 SDK's resgen under wine.

However, I think resgen should accept a  /nostdlib -lib:/usr/lib/mono/2.0 option, or
offer some manner of targetting an older runtime than in the GAC.
Comment 1 Hin-Tak Leung 2015-09-19 19:10:17 UTC
The problem is that the generated resource files contain explicit reference to Version'ed SWF .
Comment 2 Marek Safar 2015-09-21 06:16:33 UTC
Mono no longer supports 2.0 profile and resgen needs more than only mscorlib to write .resource file.

Best way to workaround it is to use mono's resgen (it can be latest version) and run it with forced 2.0 runtime.

e.g. mono --runtime=v2.0.50727 program.exe

Yo'll have to also set MONO_PATH to Mono 2.0 assemblies.
Comment 3 Hin-Tak Leung 2015-09-21 18:17:09 UTC
I'll give your advice a try soon. Thanks for the tips.

However, I think building binaries targeting an older .net runtime is a genuine need - as a developer one might want to reach a larger set of users, by targeting the older runtime rather than forcing end users to upgrade their net runtime.
Comment 4 Hin-Tak Leung 2015-09-21 18:48:14 UTC
$ MONO_PATH=/usr/lib/mono/2.0 mono --runtime=v2.0.50727 /usr/lib/mono/4.5/resgen.exe test.resx
WARNING: The runtime version supported by this application is unavailable.
Using default runtime: v4.0.30319
Corlib not in sync with this runtime: expected corlib version 117, found 111.
Loaded from: /usr/lib/mono/2.0/mscorlib.dll
Download a newer corlib or a newer runtime at http://www.mono-project.com/download.

Does not regenerate test.resx

I tried moving /usr/lib/mono/2.0/mscorlib.dll aside, then it just does it like under 4.5.

I tried it with the official win32 mono binary under wine, and it behaves the same way:

"c:/Program Files/Mono/bin/mono.exe" --runtime=v2.0.50727 "c:/Program Files/Mono/lib/mono/4.5/resgen.exe" test.resx
WARNING: The runtime version supported by this application is unavailable.
Using default runtime: v4.0.30319
Corlib not in sync with this runtime: expected corlib version 117, found 111.
Loaded from: C:\Program Files\Mono\lib\mono\2.0\mscorlib.dll
Download a newer corlib or a newer runtime at http://www.mono-project.com/download.
Comment 5 Hin-Tak Leung 2015-09-24 19:47:56 UTC
I think I see the problem,

mcs/tools/resgen/monoresgen.cs, around line 36, does:


swf = Assembly.Load (Consts.AssemblySystem_Windows_Forms);

and Consts.AssemblySystem_Windows_Forms is fixed at compile-time to (FxVersion = '4.0.0.0'):

AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=" + FxVersion + ", Culture=neutral, PublicKeyToken=b77a5c561934e089";

for a 4.0 profile.

Also as it does the full name, it only loads from the GAC - this means even if you try to change FxVersion to 2.0, you still need to put the 2.0 version of SWF into GAC for it to work; and MONO_PATG has no effect.

I think 

swf = Assembly.LoadFrom ("System.Windows.Forms");

may work... I'll give that a try.