Announcement

Collapse
No announcement yet.

[CLOSED] [#21] Unable to cast object of type ~IndexerDeclaration' to type ~PropertyDeclaration'

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    [CLOSED] [#21] Unable to cast object of type ~IndexerDeclaration' to type ~PropertyDeclaration'

    I have a class with a pair of property indexers. This class has been not only compiling, but running and working fine. Until today. Not sure what I did, but my machine is no longer able to build this project due to this error. Others on the team seem fine with it. Suggestions?

    Severity Code Description Project File Line Suppression State
    Error 2018-02-15T17:23:19:631 Error Unable to cast object of type 'ICSharpCode.NRefactory.CSharp.IndexerDeclaration' to type 'ICSharpCode.NRefactory.CSharp.PropertyDeclaration '. at A.J.A()
    at A.c.A(IConstructorBlock )
    at A.c.GetConstructorInjectors(IConstructorBlock )
    at Bridge.Translator.Plugins.GetConstructorInjectors( IConstructorBlock constructorBlock)
    at Bridge.Translator.ConstructorBlock.GetInjectors()
    at Bridge.Translator.ConstructorBlock.EmitInitMembers ()
    at Bridge.Translator.ConstructorBlock.EmitCtorForInst antiableClass()
    at Bridge.Translator.ConstructorBlock.DoEmit()
    at Bridge.Translator.AbstractEmitterBlock.Emit()
    at Bridge.Translator.ClassBlock.EmitInstantiableBlock ()
    at Bridge.Translator.ClassBlock.DoEmit()
    at Bridge.Translator.AbstractEmitterBlock.Emit()
    at Bridge.Translator.EmitBlock.DoEmit()
    at Bridge.Translator.AbstractEmitterBlock.Emit()
    at Bridge.Translator.Emitter.Emit()
    at Bridge.Translator.Translator.Translate()
    at Bridge.Build.BridgeCompilerTask.Execute() CIN.Bridge C:\Projects\CIN_2008\Rio\branches\Dev\Application\ WebUI\CIN.Bridge\Models\ObservableCollection.cs 13

    #2
    Hi. Any chance we could get a code sample or Deck demonstrating how to reproduce?

    I'll ask around with the dev team a let you know if we have any suggestions.

    Comment


      #3
      I tried something on Deck, but of course it works. https://deck.net/8947c681b6a6c6916f086edabb5c76d6

      My full code is below. Please remember this code has been working in my project for a while now. The only thing I did was add a new Bridge.NET project through the "Add New Project.." dialog, choosing Bridge.NET. I have the VSIX extension. I'm not sure what version that was. My projects are all set to 16.7.0. After I got this error, I tried updating all nuget packages to 16.7.1. I get a different error. It changed to something about GetOverloadName(), and not being able to find a method with that signature. There were 3 instances of that error. They all came from static classes with no constructor.

      using System;
      using System.Collections;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Linq;
      using System.Runtime.CompilerServices;
      using Bridge;
      using Retyped;
      
      namespace CIN.Bridge.Models
      {
          /// <summary>
          /// Most base class for "ObservableCollection".  Wraps a kendo ObservableArray
          /// </summary>
          /// <typeparam name="T"></typeparam>
      
      
          public class ObservableCollection<T> : kendo_ui.kendo.data.ObservableArray, IList<T>, IList, INotifyCollectionChanged, INotifyPropertyChanged
          {
              //private readonly kendo_ui.kendo.data.ObservableArray _items;
      
      
              private bool _isReadOnly;
              private bool _busy;
              public ObservableCollection() : this(new T[]{})
              {
      
              }
      
              public ObservableCollection(IEnumerable<T> items) : base(items.Cast<object>().ToArray())
              {
              }
      
              public new void init(object[] array)
              {
                  Console.WriteLine("In our init method");
              }
      
              public virtual IEnumerable<T> Items => this.As<IEnumerable<T>>();
      
              public IEnumerator<T> GetEnumerator()
              {
                  for (int i = 0; i < base.length; i++)
                  {
                      yield return base[i].As<T>();
                  }
              }
      
              IEnumerator IEnumerable.GetEnumerator()
              {
                  return GetEnumerator();
              }
      
              public void Add(T item)
              {
                  AssertNotReadOnly();
                  base.push(item);
              }
      
      
      
              public void CopyTo(T[] array, int arrayIndex)
              {
                  throw new NotImplementedException();
              }
      
              public int Add(object item)
              {
                  AssertNotReadOnly();
                  //ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
                  try
                  {
                      this.Add((T)item);
                  }
                  catch (InvalidCastException ex)
                  {
                      throw new ArgumentException("Item is not of the correct type", nameof(item), ex);
                  }
                  return (int) (base.length - 1);
              }
      
              public void Clear()
              {
                  base.empty();
              }
              void IList.Clear()
              {
                  base.empty();
              }
      
              public bool Contains(object item)
              {
                  if (IsCompatibleObject(item))
                      return this.Contains((T)item);
                  return false;
              }
      
              public int IndexOf(object item)
              {
                  return IndexOf((T) item);
              }
      
              public void Insert(int index, object item)
              {
                  Insert(index, (T) item);
              }
      
              void IList.RemoveAt(int index)
              {
                  ((IList<T>)this).RemoveAt(index);
              }
      
              public void Remove(object item)
              {
                  ((IList<T>)this).Remove((T) item);
              }
      
              object IList.this[int index]
              {
                  get { return this[index]; }
                  set { this[index] = (T) value; }
              }
      
              bool IList.IsReadOnly { get; }
              void ICollection<T>.Clear()
              {
                  base.empty();
              }
      
              public bool Contains(T item)
              {
                  return base.indexOf(item) > 0;
              }
      
              public bool Remove(T item)
              {
                  AssertNotReadOnly();
                  int index = IndexOf(item);
                  if (index < 0) return false;
      
                  base.splice(index, 1);
                  return true;
              }
      
              public void CopyTo(Array array, int arrayIndex)
              {
                  throw new NotImplementedException();
              }
      
              int ICollection.Count => (int)base.length;
      
              int ICollection<T>.Count => (int)base.length;
      
              bool ICollection<T>.IsReadOnly => _isReadOnly;
      
              public bool Busy
              {
                  get { return _busy; }
              }
      
              public int IndexOf(T item)
              {
                  return (int)base.indexOf(item);
              }
      
              public void Insert(int index, T item)
              {
                  AssertNotReadOnly();
                  if (index < 0 || index > base.length) throw new ArgumentOutOfRangeException(nameof(index), "Index outside of the bounds of the array");
                  base.splice(index, 0, item);
              }
      
              void IList<T>.RemoveAt(int index)
              {
                  base.splice(index, 1);
              }
      
              public T this[int index]
              {
                  get { return (T)base[index]; }
                  set
                  {
                      AssertNotReadOnly();
                      base[index] = value;
                  }
              }
      
              private static bool IsCompatibleObject(object value)
              {
                  if (value is T)
                      return true;
                  if (value == null)
                      return (object)default(T) == null;
                  return false;
              }
      
              private void AssertNotReadOnly()
              {
                  if (_isReadOnly) throw new NotSupportedException("Collection is Read Only");
              }
              public event NotifyCollectionChangedEventHandler CollectionChanged;
      
              /// <summary>Raises the <see cref="E:System.Collections.ObjectModel.ObservableCollection`1.CollectionChanged" /> event with the provided event data.</summary>
              /// <param name="e">The event data to report in the event.</param>
              protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
              {
                  if (this.CollectionChanged == null)
                      return;
                  this._busy = true;
                  try
                  {
                      this.CollectionChanged((object)this, e);
                      trigger("change");
                  }
                  finally
                  {
                      this._busy = false;
                  }
              }
      
              public event PropertyChangedEventHandler PropertyChanged;
      
              protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
              {
                  PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
              }
      
              protected void NotifyPropertyChanged(string propertyName)
              {
                  this.trigger("change", new { field = propertyName });
              }
          }
      }

      Comment


        #4
        After upgrading to 16.7.1, I now get this:
        Severity Code Description Project File Line Suppression State
        Error 2018-02-16T10:53:28:269 Error Method not found: 'System.String Bridge.Contract.OverloadsCollection.GetOverloadNam e(Boolean, System.String, Boolean, Boolean)'. at A.J.A()
        at A.c.A(IConstructorBlock )
        at A.c.GetConstructorInjectors(IConstructorBlock )
        at Bridge.Translator.Plugins.GetConstructorInjectors( IConstructorBlock constructorBlock)
        at Bridge.Translator.ConstructorBlock.GetInjectors()
        at Bridge.Translator.ConstructorBlock.EmitCtorForStat icClass()
        at Bridge.Translator.ConstructorBlock.DoEmit()
        at Bridge.Translator.AbstractEmitterBlock.Emit()
        at Bridge.Translator.ClassBlock.EmitStaticBlock()
        at Bridge.Translator.ClassBlock.DoEmit()
        at Bridge.Translator.AbstractEmitterBlock.Emit()
        at Bridge.Translator.EmitBlock.DoEmit()
        at Bridge.Translator.AbstractEmitterBlock.Emit()
        at Bridge.Translator.Emitter.Emit()
        at Bridge.Translator.Translator.Translate()
        at Bridge.Build.BridgeCompilerTask.Execute() Rio.UI.Bankruptcy C:\Projects\CIN_2008\Rio\branches\Dev\Application\ WebUI\UI\Rio.UI.Bankruptcy\App.cs 9
        Last edited by geoffrey.mcgill; 2018-02-16 @ 07:39 PM.

        Comment


          #5
          We were able to reproduce the issue. It appears the problem occurs when using Bridge Test or Bridge Aspect.

          Do you have Bridge Aspect installed in your project?

          We don't have a fix available yet, but we're working on it right now.

          Comment


            #6
            Yes, I have Bridge.Aspect installed. We haven't started using it for what we really intended, but unfortunately I ported a bunch of code from a prior C# project, and it's littered with [NotNull] attributes. I'm currently using the attribute from Bridge.Aspect. I'll look to see how hard it is to remove it from the project though.

            For the record, do you think both the errors I received under 16.7.0 (the property indexer) and the error under 16.7.1 (the GetOverloadName) are related to Bridge.Aspect?

            Comment


              #7
              For the record, do you think both the errors I received under 16.7.0 (the property indexer) and the error under 16.7.1 (the GetOverloadName) are related to Bridge.Aspect?
              They are both somewhat related to Bridge Aspect. Unfortunately, we did release a new update for Aspect on the release of Bridge 16.7.1, and because of that, our unit tests did not catch the GetOverloadName signature change.

              We've already made the change to release new Test and Aspect packages with every new Bridge release, and that will ensure all the unit tests are run on every release. We'll also be making some CI changes to run the Test and Aspect unit tests on each commit to Bridge.

              The GetOverloadName defect was hiding the property indexer defect. We're working on a fix for both right now.

              Comment


                #8
                Are you using [NotNull] to inform ReSharper? Is this attribute coming from the JetBrains.Annotations lib?

                Comment


                  #9
                  Looks like I was wrong about the unit tests not running on each build. They were. We just didn't have a test for this specific case that failed.

                  Comment


                    #10
                    Awesome!!! Think we're gonna love our new premium support LOL!

                    Yea, the [NotNull] thing was from ReSharper. We use them pretty regularly (well, some of us do). The great news for us is that Bridge.NET is allowing us to copy huge sections of code from our previous version of the app which was in Silverlight. But, as you can imagine, there's lots of things that don't line up one to one. So, in order to make things easy on us, I had copied over the NotNullAttribute. It wasn't really working, but it meant we didn't have to remove them all.
                    After we knew we were going to pay for Bridge.NET and get to use the Aspects (which we're counting on for NotifyPropertyChanged and maybe validation), I realized you had a similar NotNullAttribute. So, I commented out mine and started using yours.

                    So, what I have done right now is reverse that so I can unreference Bridge.Aspect. I'm building again!

                    Thanks, and we look forward to the fix!

                    Comment


                      #11
                      This defect was fixed and released in Bridge.Aspect v1.3.0.

                      https://github.com/objectdotnet/Aspect/issues/21

                      Comment

                      Working...
                      X