public static void throwUOE(Type expectedType, Ice.Value v) { // // If the object is an unknown sliced object, we didn't find an // value factory, in this case raise a NoValueFactoryException // instead. // if (v is Ice.UnknownSlicedValue) { Ice.UnknownSlicedValue usv = (Ice.UnknownSlicedValue)v; throw new Ice.NoValueFactoryException("", usv.getUnknownTypeId()); } string type = v.ice_id(); string expected; try { expected = (string)expectedType.GetMethod("ice_staticId").Invoke(null, null); } catch (Exception) { expected = ""; Debug.Assert(false); } throw new Ice.UnexpectedObjectException("expected element of type `" + expected + "' but received '" + type, type, expected); }
private int readInstance(int index, ReadValueCallback cb) { Debug.Assert(index > 0); if(index > 1) { if(cb != null) { addPatchEntry(index, cb); } return index; } push(SliceType.ValueSlice); // // Get the instance ID before we start reading slices. If some // slices are skipped, the indirect instance table are still read and // might read other instances. // index = ++_valueIdIndex; // // Read the first slice header. // startSlice(); string mostDerivedId = _current.typeId; Ice.Object v = null; while(true) { bool updateCache = false; if(_current.compactId >= 0) { updateCache = true; // // Translate a compact (numeric) type ID into a class. // if(_compactIdCache == null) { _compactIdCache = new Dictionary<int, Type>(); // Lazy initialization. } else { // // Check the cache to see if we've already translated the compact type ID into a class. // Type cls = null; _compactIdCache.TryGetValue(_current.compactId, out cls); if(cls != null) { try { Debug.Assert(!cls.IsAbstract && !cls.IsInterface); v = (Ice.Object)IceInternal.AssemblyUtil.createInstance(cls); updateCache = false; } catch(Exception ex) { throw new NoValueFactoryException("no value factory", "compact ID " + _current.compactId, ex); } } } // // If we haven't already cached a class for the compact ID, then try to translate the // compact ID into a type ID. // if(v == null) { _current.typeId = ""; if(_compactIdResolver != null) { try { _current.typeId = _compactIdResolver(_current.compactId); } catch(Ice.LocalException) { throw; } catch(System.Exception ex) { throw new Ice.MarshalException("exception in CompactIdResolver for ID " + _current.compactId, ex); } } if(_current.typeId.Length == 0) { _current.typeId = _stream.instance().resolveCompactId(_current.compactId); } } } if(v == null && _current.typeId.Length > 0) { v = newInstance(_current.typeId); } if(v != null) { if(updateCache) { Debug.Assert(_current.compactId >= 0); _compactIdCache.Add(_current.compactId, v.GetType()); } // // We have an instance, get out of this loop. // break; } // // If slicing is disabled, stop unmarshaling. // if(!_sliceValues) { throw new NoValueFactoryException("no value factory found and slicing is disabled", _current.typeId); } // // Slice off what we don't understand. // skipSlice(); // // If this is the last slice, keep the instance as an opaque // UnknownSlicedValue object. // if((_current.sliceFlags & Protocol.FLAG_IS_LAST_SLICE) != 0) { // // Provide a factory with an opportunity to supply the instance. // We pass the "::Ice::Object" ID to indicate that this is the // last chance to preserve the instance. // v = newInstance(Ice.ObjectImpl.ice_staticId()); if(v == null) { v = new Ice.UnknownSlicedValue(mostDerivedId); } break; } startSlice(); // Read next Slice header for next iteration. } // // Unmarshal the instance. // unmarshal(index, v); if(_current == null && _patchMap != null && _patchMap.Count > 0) { // // If any entries remain in the patch map, the sender has sent an index for an instance, but failed // to supply the instance. // throw new Ice.MarshalException("index for class received, but no instance"); } if(cb != null) { cb(v); } return index; }