Skip to main content
 首页 » 编程设计

c#之Google Checkout 突然返回 : 'GCheckout.XmlSerializers' failed to load'

2024年02月24日20yxwkf

我在使用 Google Checkout ASP.NET 控件“GCheckout”时突然遇到间歇性错误。

第一行代码如下:

 XmlSerializer Ser = new XmlSerializer(ObjectToSerialize.GetType()); //ObjectToSerialize is a CheckoutShoppingCart object 

令我困惑的是,为什么它以前似乎一直有效,现在只是断断续续地返回如下所示的错误。

这个库对我来说是一个巨大的黑盒子,我是一个 VB.NET 的人,而不是 C#。

有人可以提供任何建议吗?

/// <summary> 
/// Makes XML out of an object. 
/// </summary> 
/// <param name="ObjectToSerialize">The object to serialize.</param> 
/// <returns>An XML string representing the object.</returns> 
/// <example> 
/// <code> 
/// Car MyCar1 = new Car(); 
/// byte[] CarBytes = EncodeHelper.Serialize(MyCar1); 
/// string CarXml = EncodeHelper.Utf8BytesToString(CarBytes); 
/// Car MyCar2 = (Car) Deserialize(CarXml, typeof(Car)); 
/// // MyCar2 is now a copy of MyCar1. 
/// </code> 
/// </example> 
public static byte[] Serialize(object ObjectToSerialize) { 
  XmlSerializer Ser = new XmlSerializer(ObjectToSerialize.GetType()); //ObjectToSerialize is a CheckoutShoppingCart object 
  using (MemoryStream MS = new MemoryStream()) { 
    XmlTextWriter W = new XmlTextWriter(MS, new UTF8Encoding(false)); 
    W.Formatting = Formatting.Indented; 
    Ser.Serialize(W, ObjectToSerialize); 
    W.Flush(); 
    W.Close(); 
    return MS.ToArray(); 
  } 
} 
 
The assembly with display name 'GCheckout.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 9. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'GCheckout.XmlSerializers, Version=1.3.2.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. 
File name: 'GCheckout.XmlSerializers, Version=1.3.2.0, Culture=neutral, PublicKeyToken=null' 
 
=== Pre-bind state information === 
LOG: User = NA\MYNAME 
LOG: DisplayName = GCheckout.XmlSerializers, Version=1.3.2.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL 
 (Fully-specified) 
LOG: Appbase = file:///C:/My/Code/BESI/BESI/ 
LOG: Initial PrivatePath = C:\My\Code\BESI\BESI\bin 
Calling assembly : (Unknown). 
=== 
LOG: This bind starts in default load context. 
LOG: Using application configuration file: C:\My\Code\BESI\BESI\web.config 
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config. 
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). 
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/besi/c1115671/77c4386d/GCheckout.XmlSerializers.DLL. 
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/besi/c1115671/77c4386d/GCheckout.XmlSerializers/GCheckout.XmlSerializers.DLL. 
LOG: Attempting download of new URL file:///C:/My/Code/BESI/BESI/bin/GCheckout.XmlSerializers.DLL. 
LOG: Attempting download of new URL file:///C:/My/Code/BESI/BESI/bin/GCheckout.XmlSerializers/GCheckout.XmlSerializers.DLL. 
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/besi/c1115671/77c4386d/GCheckout.XmlSerializers.EXE. 
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/besi/c1115671/77c4386d/GCheckout.XmlSerializers/GCheckout.XmlSerializers.EXE. 
LOG: Attempting download of new URL file:///C:/My/Code/BESI/BESI/bin/GCheckout.XmlSerializers.EXE. 
LOG: Attempting download of new URL file:///C:/My/Code/BESI/BESI/bin/GCheckout.XmlSerializers/GCheckout.XmlSerializers.EXE. 

请您参考如下方法:

这是 XML 序列化的正常异常。 Debug + Exceptions,关闭复选框。使用 Sgen.exe tool预编译序列化程序集,速度要快得多。