Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by frarees · Aug 07, 2013 at 10:45 AM · crashcoroutineienumeratormonodelegate

Internal compiler error

This code throws an internal compiler error.

 public delegate IEnumerator SimpleRoutine ();
 
 public void FUNC (SimpleRoutine onStarted = null) {
     onStarted = onStarted ?? delegate { yield break; };
 }

Looking at the console log, Mono throws this:

 Unhandled Exception: Mono.CSharp.InternalErrorException: myscriptatsomepath.cs (174,42): ---> System.NotSupportedException: Operation is not supported.
   at Mono.CSharp.YieldBreak.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Statement target) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.Statement.Clone (Mono.CSharp.CloneContext clonectx) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.Block.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Statement t) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.ExplicitBlock.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Statement t) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.ToplevelBlock.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Statement t) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.Statement.Clone (Mono.CSharp.CloneContext clonectx) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.Statement.PerformClone () [0x00000] in <filename unknown>:0 
   at Mono.CSharp.AnonymousMethodExpression.CompatibleMethod (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeInferenceContext tic, System.Type return_type, System.Type delegate_type) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.AnonymousMethodExpression.Compatible (Mono.CSharp.ResolveContext ec, System.Type type) [0x00000] in <filename unknown>:0 
   --- End of inner exception stack trace ---
   at Mono.CSharp.AnonymousMethodExpression.Compatible (Mono.CSharp.ResolveContext ec, System.Type type) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.AnonymousMethodExpression.ImplicitStandardConversionExists (Mono.CSharp.ResolveContext ec, System.Type delegate_type) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.Convert.ImplicitConversionExists (Mono.CSharp.ResolveContext ec, Mono.CSharp.Expression expr, System.Type target_type) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.Nullable.NullCoalescingOperator.ConvertExpression (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.Nullable.NullCoalescingOperator.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.Assign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.SimpleAssign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.ExpressionStatement.ResolveStatement (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 
   at Mono.CSharp.ToplevelBlock.Resolve (Mono.CSharp.FlowBranching parent, Mono.CSharp.BlockContext rc, Mono.CSharp.ParametersCompiled ip, IMethodData md) [0x00000] in <filename unknown>:0 
  
 (Filename:  Line: 0)

Is this a known issue? Any workaround? Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ArkaneX · Aug 07, 2013 at 11:47 AM

You can't use yield inside anonymous delegate. You can read the details here: http://blogs.msdn.com/b/ericlippert/archive/2009/08/24/iterator-blocks-part-seven-why-no-anonymous-iterators.aspx

Instead of using anonymous delegate, you can simply declare a standard method:

 public delegate IEnumerator SimpleRoutine();
 
 public static void FUNC(ref SimpleRoutine onStarted)
 {
     onStarted = onStarted ?? SimpleRoutineExample;
 }
 
 public static IEnumerator SimpleRoutineExample()
 {
     yield break;
 }

I've changed the signature of FUNC method as well, because by default delegates aren't passed by reference.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image frarees · Aug 07, 2013 at 12:16 PM 0
Share

Good to know. Thanks! Anyway, shouldn't Unity/$$anonymous$$ono handle the error in other way than internal error which may be not very helpful?

avatar image ArkaneX · Aug 07, 2013 at 01:30 PM 0
Share

It's hard to say why there is no exact error message in Unity. If you compile this code in Visual Studio or $$anonymous$$onoDevelop, then the proper compilation error is displayed.

As a side note: when compiling your code, my version of $$anonymous$$onoDevelop complains about 'SimpleRoutine onStarted = null', stating that 'Default parameter specifiers are not permitted'. But in Unity it compiles without any problems :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

c# Using an IEnumerator yield WaitForSeconds to temporarily pause a While loop 3 Answers

Coroutine won't run sometimes and other times it runs. 0 Answers

Can't get past WaitForSeconds in my coroutine 1 Answer

Coroutine doesn't work when called from another method. 3 Answers

Issue With Simultaneous ReadPixels Calls 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges