Bug 4161 - CS0584: Internal compiler error: Cannot cast from source type to destination type. (while compiling Magnum library)
Summary: CS0584: Internal compiler error: Cannot cast from source type to destination ...
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2012-03-30 12:52 UTC by Pablo Ruiz García
Modified: 2012-04-02 04:11 UTC (History)
1 user (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 on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Pablo Ruiz García 2012-03-30 12:52:22 UTC
Hi,

While debugging another issue on a component using topshelf/magnum libreries, I found I was unable to build magnum code using mono, as building fails with the following message:


        Reflection/ReflectiveVisitorBase.cs(123,42): error CS0584: Internal compiler error: Cannot cast from source type to destination type.
        Reflection/ReflectiveVisitorBase.cs(123,25): error CS0266: Cannot implicitly convert type `object' to `System.Func<TVisitor,object,bool>'. An explicit conversion exists (are you missing a cast?)


I've tried with both dmcs & "mcs -skd:4", which same results.

To repo this issue, download the attached 'magnum.tgz' file, and follow this steps:

tar -xvzf magnum.tgz
cd magnum.git/src
xbuild Magnum.sln

Compilation will fail with the following errors:

Errors:

/usr/src/magnum.git/src/Magnum.sln (default targets) ->
(Build target) ->
/usr/src/magnum.git/src/Magnum/Magnum.csproj (default targets) ->
/usr/lib/mono/4.0/Microsoft.CSharp.targets (CoreCompile target) ->

        Reflection/ReflectiveVisitorBase.cs(123,42): error CS0584: Internal compiler error: Cannot cast from source type to destination type.
        Reflection/ReflectiveVisitorBase.cs(123,25): error CS0266: Cannot implicitly convert type `object' to `System.Func<TVisitor,object,bool>'. An explicit conversion exists (are you missing a cast?)

         21 Warning(s)
         2 Error(s)

PD: Obiosully the same code compiles fine under ms.net using msbuild.
Comment 1 Pablo Ruiz García 2012-03-30 13:07:01 UTC
The attachment was too big, so bugzilla rejected it.

You can download it from http://netway.org/magnum.tgz

Greets.
Comment 2 Pablo Ruiz García 2012-03-30 13:31:29 UTC
Hi again,

My original report was against mono-2.10.5. But I just tested against mono-2.11 and I got a different compiler error:



                                Internal compiler error at Collections\Algorithms.cs(4439,9):: exception caught while emitting Void Dispose()
                                Unhandled Exception: Mono.CSharp.InternalErrorException: Already created variable `e'
                                  at Mono.CSharp.LocalVariable.CreateBuilder (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Foreach.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.TryFinally.EmitFinallyBody (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.TryFinallyBlock.EmitForDispose (Mono.CSharp.EmitContext ec, IKVM.Reflection.Emit.LocalBuilder pc, Label end, Boolean have_dispatcher) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Iterator.EmitDispose (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.IteratorStorey+DisposeMethod+DisposeMethodStatement.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.ParametersBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.MethodData.Emit (Mono.CSharp.TypeDefinition parent) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.MethodOrOperator.Emit () [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Method.Emit () [0x00000] in <filename unknown>:0
                                [ERROR] FATAL UNHANDLED EXCEPTION: Mono.CSharp.InternalErrorException: Already created variable `e'
                                  at Mono.CSharp.LocalVariable.CreateBuilder (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Foreach.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.TryFinally.EmitFinallyBody (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.TryFinallyBlock.EmitForDispose (Mono.CSharp.EmitContext ec, IKVM.Reflection.Emit.LocalBuilder pc, Label end, Boolean have_dispatcher) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Iterator.EmitDispose (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.IteratorStorey+DisposeMethod+DisposeMethodStatement.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.ParametersBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.MethodData.Emit (Mono.CSharp.TypeDefinition parent) [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.MethodOrOperator.Emit () [0x00000] in <filename unknown>:0
                                  at Mono.CSharp.Method.Emit () [0x00000] in <filename unknown>:0
Microsoft.CSharp.targets: error : Compiler crashed with code: 1.
Comment 3 Marek Safar 2012-04-02 04:11:57 UTC
Already fixed in master