Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#7 Error registering a FileStream instance

closed
nobody
5
2012-02-15
2012-02-14
Anonymous
No

Castle Windows is not handling an invalid operation exception while introspecting a FileStream - the Stream ReadTimeout and WriteTimeout properties are defined to throw an exception for derived classes that do not support timeouts.

Here's my code:

var container = new WindsorContainer();
container.Register(Component.For<IStreamSource>().ImplementedBy<StreamTailer>());
Stream fs = new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
container.Register(Component.For<Stream>().Instance(fs).);
IStreamSource tailer = container.Resolve<IStreamSource>();
container.Register(Component.For<IStreamSource>().Instance(tailer));

The last line above throws an exception and kills the app. Here's the stack trace:

Application exiting due to unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Timeouts are not supported on this stream.
at System.IO.Stream.get_ReadTimeout()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at Castle.Core.ReflectionBasedDictionaryAdapter.GetPropertyValue(Object target, PropertyInfo property)
at Castle.Core.ReflectionBasedDictionaryAdapter.Read(IDictionary targetDictionary, Object valuesAsAnonymousObject)
at Castle.Core.ReflectionBasedDictionaryAdapter..ctor(Object target)
at Castle.Windsor.WindsorContainer.Resolve[T](Object argumentsAsAnonymousType)
at ConsoleApplication1.Program.Main(String[] args) in C:\Users\rizzuto\p4root\SDMPNeovestAdapter\ProofOfConcept\Program.cs:line 36
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Discussion

  • Jonathon Rossi
    Jonathon Rossi
    2012-02-15

    • status: open --> closed