public static ObjectBase LoadObject(string _filePath, string _name)
{
ObjectBase module = null;
try
{
IFormatter formatter = new BinaryFormatter();
Stream streamRead = new FileStream(_filePath, FileMode.Open, FileAccess.Read, FileShare.None);
object ob = formatter.Deserialize(streamRead);
module = (ob as ObjectBase);
streamRead.Close();
}
catch (Exception ex)
{
return null;
}
finally
{
}
return module;
}
每次运行这个函数时,我都会遇到异常:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Operation is not valid due to the current state of the object.
at Cognex.VisionPro.Implementation.Internal.ccComFactory.CreateInstance()
at Cognex.VisionPro.FGGigE.Implementation.Internal.CogAcqFifoGigE._com()
at Cognex.VisionPro.FGGigE.Implementation.Internal.CogAcqFifoGigE..ctor(SerializationInfo info, StreamingContext context)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.SerializationInvoke(IRuntimeMethodInfo method, Object target, SerializationInfo info, StreamingContext& context)
at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder) at System.Runtime.Serialization.ObjectManager.DoFixups()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
at My code file.
Message: "Operation is not valid due to the current state of the object." Source: "Cognex.VisionPro.FGGigE" StackTrace:
at Cognex.VisionPro.Implementation.Internal.ccComFactory.CreateInstance()
at Cognex.VisionPro.FGGigE.Implementation.Internal.CogAcqFifoGigE._com()
at Cognex.VisionPro.FGGigE.Implementation.Internal.CogAcqFifoGigE..ctor(SerializationInfo info, StreamingContext context)
有人有想法吗?我非常感谢你们的帮助!
CogAcqFifoGigE
的实例时出现错误。您能够访问该类型的源代码吗?您可以分享一下ccComFactory.CreateInstance
方法的代码吗? - undefined