Bug 30821

Summary: Compilation generates CS1701 warning
Product: [Mono] Compilers Reporter: Finn Nielsen <fannatxamarin>
Component: C#Assignee: Marek Safar <masafa>
Status: VERIFIED FIXED    
Severity: minor CC: masinha, mono-bugs+mono, naqeeba, peter.collins
Priority: ---    
Version: 3.12.0   
Target Milestone: 4.6.0 (C8)   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Example solution generating CS 1701 warning

Description Finn Nielsen 2015-06-04 16:37:32 UTC
Created attachment 11470 [details]
Example solution generating CS 1701 warning

In one of my small projects I am experiencing the CS1701 warning. I have found a way to reproduce it - I hope.

I have ubuntu 14.04 LTS with MonoDevelop 5.7. mono --version returns:
Mono JIT compiler version 3.12.1 (tarball Fri Mar  6 19:14:08 UTC 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            sgen

Procedure in in MonoDevelop:
1. Create a new console application solution. 
2. Add NuGet package Quartz.NET (at time of writing version is 2.3.2). This also adds packages Common.Logging and Common.Logging.Core both version 3.0.0.
3. To the main program add the line of code:
Console.WriteLine(new Quartz.Impl.StdSchedulerFactory());
4. Compile - all is fine.
5. Now update Common.Logging and Common.Logging.Core (at time of writing highest version is 3.1.0).
6. Compile -> generates CS1701 warning for Common.Logging.Core version issues between 3.0.0 and 3.1.0.
7. Remove the added line of code:
Console.WriteLine(new Quartz.Impl.StdSchedulerFactory());
8. Compile - all is fine.

Naturally, my issue is that in my real project I cannot remove the code using Quartz.NET. :o

When I build the solution using xbuild I get the following output:
XBuild Engine Version 12.0
Mono, Version 3.12.1.0
Copyright (C) 2005-2013 Various Mono authors

Build started 6/4/2015 10:01:33 PM.
__________________________________________________
Project "/home/me/Documents/CS1701Example/CS1701Example.sln" (rebuild target(s)):
	Target ValidateSolutionConfiguration:
		Building solution configuration "Debug|x86".
	Target Rebuild:
		Project "/home/me/Documents/CS1701Example/CS1701Example/CS1701Example.csproj" (Rebuild target(s)):
			Target CoreClean:
				Deleting file '/home/me/Documents/CS1701Example/CS1701Example/obj/x86/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs'
				Deleting file '/home/me/Documents/CS1701Example/CS1701Example/bin/Debug/CS1701Example.exe.config'
				Deleting file '/home/me/Documents/CS1701Example/CS1701Example/bin/Debug/CS1701Example.exe.mdb'
				Deleting file '/home/me/Documents/CS1701Example/CS1701Example/bin/Debug/CS1701Example.exe'
				Deleting file '/home/me/Documents/CS1701Example/CS1701Example/bin/Debug/Quartz.dll'
				Deleting file '/home/me/Documents/CS1701Example/CS1701Example/bin/Debug/Common.Logging.Core.dll'
				Deleting file '/home/me/Documents/CS1701Example/CS1701Example/bin/Debug/Common.Logging.dll'
				Deleting file '/home/me/Documents/CS1701Example/CS1701Example/obj/x86/Debug/CS1701Example.exe'
				Deleting file '/home/me/Documents/CS1701Example/CS1701Example/obj/x86/Debug/CS1701Example.exe.mdb'
				Deleting file '/home/me/Documents/CS1701Example/CS1701Example/obj/x86/Debug/CS1701Example.csproj.FilesWrittenAbsolute.txt'
			Target PrepareForBuild:
				Configuration: Debug Platform: x86
			Target CopyFilesMarkedCopyLocal:
				Copying file from '/home/me/Documents/CS1701Example/packages/Quartz.2.3.2/lib/net40/Quartz.dll' to '/home/me/Documents/CS1701Example/CS1701Example/bin/Debug/Quartz.dll'
				Copying file from '/home/me/Documents/CS1701Example/packages/Common.Logging.Core.3.1.0/lib/net40/Common.Logging.Core.dll' to '/home/me/Documents/CS1701Example/CS1701Example/bin/Debug/Common.Logging.Core.dll'
				Copying file from '/home/me/Documents/CS1701Example/packages/Common.Logging.3.1.0/lib/net40/Common.Logging.dll' to '/home/me/Documents/CS1701Example/CS1701Example/bin/Debug/Common.Logging.dll'
			Target GenerateSatelliteAssemblies:
			No input files were specified for target GenerateSatelliteAssemblies, skipping.
			Target CoreCompile:
				Tool /usr/lib/mono/4.5/mcs.exe execution started with arguments: /noconfig /debug:full /debug+ /optimize- /out:obj/x86/Debug/CS1701Example.exe Program.cs Properties/AssemblyInfo.cs obj/x86/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs /target:exe /define:DEBUG /nostdlib /platform:x86 /reference:/usr/lib/mono/4.5/System.dll /reference:../packages/Quartz.2.3.2/lib/net40/Quartz.dll /reference:../packages/Common.Logging.Core.3.1.0/lib/net40/Common.Logging.Core.dll /reference:../packages/Common.Logging.3.1.0/lib/net40/Common.Logging.dll /reference:/usr/lib/mono/4.5/System.Core.dll /reference:/usr/lib/mono/4.5/mscorlib.dll /warn:4
CSC:  warning CS1701: Assuming assembly reference `Common.Logging.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e' matches assembly `Common.Logging.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e'. You may need to supply runtime policy
			Target _CopyAppConfigFile:
				Copying file from '/home/me/Documents/CS1701Example/CS1701Example/app.config' to '/home/me/Documents/CS1701Example/CS1701Example/bin/Debug/CS1701Example.exe.config'
			Target DeployOutputFiles:
				Copying file from '/home/me/Documents/CS1701Example/CS1701Example/obj/x86/Debug/CS1701Example.exe.mdb' to '/home/me/Documents/CS1701Example/CS1701Example/bin/Debug/CS1701Example.exe.mdb'
				Copying file from '/home/me/Documents/CS1701Example/CS1701Example/obj/x86/Debug/CS1701Example.exe' to '/home/me/Documents/CS1701Example/CS1701Example/bin/Debug/CS1701Example.exe'
		Done building project "/home/me/Documents/CS1701Example/CS1701Example/CS1701Example.csproj".
Done building project "/home/me/Documents/CS1701Example/CS1701Example.sln".

Build succeeded.

Warnings:

/home/me/Documents/CS1701Example/CS1701Example.sln (rebuild) ->
(Rebuild target) ->
/home/me/Documents/CS1701Example/CS1701Example/CS1701Example.csproj (Rebuild) ->
/usr/lib/mono/4.5/Microsoft.CSharp.targets (CoreCompile target) ->

	CSC:  warning CS1701: Assuming assembly reference `Common.Logging.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e' matches assembly `Common.Logging.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e'. You may need to supply runtime policy

	 1 Warning(s)
	 0 Error(s)

Time Elapsed 00:00:01.7757720


I have attempted adding binding redirect using the app.config file, this changes nothing.
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

If I complete the procedure on Windows in Visual Studio 2012 then it compiles fine after updating Common.Logging and Common.Logging.Core to 3.1.0, both with and without the binding redirect.

The attachment contains a MonoDevelop solution with the above procedure at step 6 - the warning. It also contains the binding redirect. Note, MonoDevelop must download the packages from nuget!
Comment 1 Marek Safar 2015-06-18 05:59:58 UTC
mcs is too aggressive here, it reports the warning even if assembly reference is never used. .net compiler reports this only for "used" assemblies.

Removing not needed assemblies 

/reference:../packages/Common.Logging.Core.3.1.0/lib/net40/Common.Logging.Core.dll
/reference:../packages/Common.Logging.3.1.0/lib/net40/Common.Logging.dll

in your case fixes the warning
Comment 2 Marek Safar 2016-08-22 15:03:25 UTC
*** Bug 43468 has been marked as a duplicate of this bug. ***
Comment 3 Marek Safar 2016-08-22 15:31:18 UTC
Fixed in master and Mono 4.6
Comment 4 Naqeeb 2016-08-23 13:17:31 UTC
I have checked this issue with latest C8 build and observed thai it is working fine. I am not getting 'CS1701' warning when build the project. Here is the screencast for the same: http://www.screencast.com/t/oeBiz8IDzB

Environment info: https://gist.github.com/NaqeebAnsari/f9edc8d9a2b9d61c06fb845364364fef

Hence closing this issue.