Makale numarası: 872800 - Son Gözden Geçirme: 18 Mayıs 2007 Cuma - Gözden geçirme: 3.5

Düzeltme: Uygulamasını çalıştıran her zaman Web hizmeti istemcileri serileştirme derlemelerini yeniden

Sistem İpucuBu makale, kullandığınızdan farklı bir işletim sistemine yöneliktir. Sizinle ilgili olmayabilecek makale içeriği devre dışı bırakıldı.

Bu Sayfada

Hepsini aç | Hepsini kapa

Belirtiler

Bir Web hizmetine çağıran uygulama sonraki ça?r?lar karşılaştırıldığında ilk arama yapmak için beklenenden daha uzun sürebilir. Bu gecikme, uygulamayı çalıştırın, her zaman oluşur.

Not Bu düzeltme, Microsoft .NET Framework 1.1 Service Pack 1 çalışan bir sistemde uygulanamaz. .NET Framework 1.1 Service Pack 1 yüklü ve bu makalede açıklanan belirtinin karşılaşmış olan, 890673 bir çözünürlük elde etmek için Microsoft Knowledge Base makalesinde açıklanan düzeltme toplaması paketini isteyin. Daha fazla bilgi için, Microsoft Bilgi Bankası'ndaki makaleyi görüntülemek üzere aşağıdaki makale numarasını tıklatın:
890673  (http://support.microsoft.com/kb/890673/ ) .NET Framework 1.1 Service Pack 1 Sonrası XML Web hizmetleri ve XML Messaging düzeltme toplaması paketi 8'in kullanılabilirliği

Neden

Web hizmeti proxy'si bir seri hale getirme derlemesi kullanır ve seri hale getirme derlemesi, çalışma anında dinamik olarak derlenir için bir istemci uygulamasını ilk kez çalıştırdığınızda, gecikme oluşur. Seri hale getirme derlemesi serializes ve istemcinin isteğine ve sunucu sonuçları isteği için döndürülen bilgileri deserializes. Ek süre ilk arama, seri hale getirme derlemesi derlemesini nedeniyle oluşur.

Çözüm

Bu düzeltme, pregenerated derlemeler kullanan uygulamaları çalışan bilgisayarlarda da yüklenmesi gerekir. Bu sorunu gidermek için aşağıdaki adımları izleyin:
  1. Edinin ve sonra düzeltmeyi yükleyin. Bunu yapmak için şu adımları izleyin:
    1. Düzeltme aşağıdaki düzeltme paketinde edinin:
      890673  (http://support.microsoft.com/kb/890673/ ) .NET Framework 1.1 Service Pack 1 Sonrası XML Web hizmetleri ve XML Messaging düzeltme toplaması paketi 8'in kullanılabilirliği
    2. Düzeltmeyi bir klasöre ayıklayın.
    3. Bilgisayarınızda düzeltmeyi yüklemek için düzeltme</a1> çift tıklatın.
  2. Seri hale getirici derleme pregenerate. Bir proxy derlemesi için seri hale getirici derlemeleri üreten en az, bir örnek konsol uygulaması aşağıdadır. Bu uygulamanın daha karmaşık bir sürümü için "Ek bilgi" bölümüne bakın. Basit bir seri hale getirici pregenerator oluşturmak için aşağıdaki adımları izleyin:
    1. PreGen adlı yeni bir Microsoft Visual C# .NET konsol uygulaması oluşturun.
    2. Class1.cs dosyayı Pregen.cs için yeniden adlandırın.
    3. Replace all the existing code in the PreGen.cs file with the following code.
      namespace PreGenNS {
          using System;
          using System.Collections;
          using System.IO;
          using System.Reflection;
          using System.Xml.Serialization;
          using System.Text;
          using System.Globalization;
          using System.Web.Services.Protocols;
          using System.Threading;
          using System.CodeDom.Compiler;
          
          public class Pregen {
              public static int Main(string[] args) {
                  if (args.Length != 1) {
                      Console.WriteLine("usage: ");
                      Console.WriteLine("  pregen assembly");
                      return 1;
                  }
                  Pregen pregen = new Pregen();
                  return pregen.Run(args[0]);
              }
      
              int Run(string assemblyName) {
                  
                  try {
                      GenerateAssembly(assemblyName);
                  }
                  catch (Exception e) {
                      if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                          throw;
                      }
                      Error(e, "Error: ");
                      return 1;
                  }
                  return 0;
              }
      
              void GenerateAssembly(string assemblyName) {
                  Assembly assembly = LoadAssembly(assemblyName, true);
                  Type[] types = assembly.GetTypes();
                  ArrayList mappings = new ArrayList();
                  ArrayList importedTypes = new ArrayList();
                  XmlReflectionImporter importer = new XmlReflectionImporter();
                  for (int i = 0; i < types.Length; i++) {
                      Type type = types[i];
                      if (HttpWebClientProtocol.GenerateXmlMappings(type, mappings)) {
                          importedTypes.Add(type);
                      }
                  }
                  if (importedTypes.Count > 0) {
                      Type[] serializableTypes = (Type[])importedTypes.ToArray(typeof(Type));
                      XmlMapping[] allMappings = (XmlMapping[])mappings.ToArray(typeof(XmlMapping));
                      
                      bool gac = assembly.GlobalAssemblyCache;
                      string codePath = gac ? Environment.CurrentDirectory : Path.GetDirectoryName(assembly.Location);
                      string serializerName = assembly.GetName().Name + ".XmlSerializers" ;
                      string location = Path.Combine(codePath, serializerName + ".dll");
      
                      CompilerParameters parameters = new CompilerParameters();
                      parameters.TempFiles = new TempFileCollection(codePath);
                      parameters.GenerateInMemory = false;
                      parameters.IncludeDebugInformation = false;
                      parameters.TempFiles = new TempFileCollection(codePath, true);
                      Assembly serializer = XmlSerializer.GenerateSerializer(serializableTypes, allMappings, parameters);
                      if (serializer == null) {
                          Console.Out.WriteLine("Failed pregenerate serializer for '{0}'", assembly.Location);
                      }
                      else {
                          AssemblyName name = serializer.GetName();
                          Console.Out.WriteLine("Serialization Assembly Name: {0}", name.ToString());
                          Console.Out.WriteLine("Generated serialization assembly for assembly {0} --> '{1}'.", assembly.Location, location);
                      }
                  }
                  else {
                      Console.Out.WriteLine("Assembly '{0}' does not contain any serializable types.", assembly.Location);
                  }
              }
      
              static Assembly LoadAssembly(string assemblyName, bool throwOnFail) {
                  Assembly assembly = null;
                  string path = Path.GetFullPath(assemblyName).ToLower(CultureInfo.InvariantCulture);
                  if (File.Exists(path)) {
                      assembly = Assembly.LoadFrom(path);
                  }
                  else {
                      try {
                          assembly = Assembly.Load(assemblyName);
                      }
                      catch (Exception e) {
                          if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                              throw;
                          }
                          Error(e, "Error: ");
                      }
                      if (assembly == null) {
                          string justName = Path.GetFileNameWithoutExtension(assemblyName);
                          try {
                              assembly = Assembly.Load(justName);
                          }
                          catch (Exception e) {
                              if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                                  throw;
                              }
                              Error(e, "Error: ");
                          }
                      }
                  }
                  if (assembly == null) {
                      if (throwOnFail)
                          throw new InvalidOperationException("Cannot load assembly " + assemblyName);
                      return null;
                  }
                  return assembly;
              }
      
              static void Error(Exception e, string prefix) {
                  Console.Error.WriteLine(prefix + e.Message);
                  if (e.InnerException != null) {
                      Error(e.InnerException, "  - ");
                  }
              }
      
              static void Warning(Exception e) {
                  Console.Out.WriteLine("  - " + e.Message);
                  if (e.InnerException != null) {
                      Warning(e.InnerException);
                  }
              }
          }
      }
      
    4. System.Web.Services.dll başvuru ekleme dosyası.
    5. Projeyi derleyin.
    6. PreGen.exe dosyayı proxy koduna sahip bir derleme içeren klasöre kopyalayın. Örneğin, Web hizmeti istemci kodu içeren derlemeye PreGen.exe dosyayı kopyalayın.
    7. Web hizmeti için serializers hazırlıklı PreGen.exe kullanarak pregenerate dosya. Örneğin, proxy kodunuzu WindowsApplication1.exe dosyasında, aşağıdaki komutu bir komut isteminde çalıştırın:

      PreGen.exe WindowsApplication1.exe

      Not Bir .dll dosyası, istemci derleme adımı g komutunu çalıştırırsanız olarak kaydedildiği aynı klasörde oluşturulur.
    8. Istemci kod, Microsoft Visual Studio .NET IDE içinde açın.
    9. Solution Explorer'da genişletin Web başvurusu düğüm. Örneğin, başvuru service1 localhost kullanarak eklediyseniz, LocalHost genişletin.
    10. Reference.Map genişletin ve sonra Reference.cs dosyasını çift tıklatın.
    11. Aşağıdaki kodu. bulun
          [System.Diagnostics.DebuggerStepThroughAttribute()]
          [System.ComponentModel.DesignerCategoryAttribute("code")]
          [System.Web.Services.WebServiceBindingAttribute(Name="Service1Soap", Namespace="http://tempuri.org/")]
    12. K adımda kodu aşağıdaki kodla değiştirin.
      [System.Diagnostics.DebuggerStepThroughAttribute()]
      [System.ComponentModel.DesignerCategoryAttribute("code")]
      [System.Web.Services.WebServiceBindingAttribute(Name="Service1Soap", Namespace="http://tempuri.org/")]
      [System.Xml.Serialization.XmlSerializerAssemblyAttribute(CodeBase="<DLL Name>")]
      
    13. Web hizmeti istemcinizi yeniden oluşturun.

      Not Istemciniz özniteliği nedeniyle yeniden oluşturmak zorunda. Istemciniz, artık MySerializers.dll serializers içeren derlemede çalıştırma bir bağımlılık vardır. Bu nedenle, uygulamanızla birlikte bu derlemeyle dağıtmak ve derleme burada istemciniz yükler konumda kullanılabilir yapmak gerekir.

Daha fazla bilgi

Derleme bağlama

XmlSerializerAssemblyAttribute özniteliği için sağladığınız bağımsız değişkenin türü seri hale getirici derleme yüklenir biçimini belirler. CodeBase bağımsız değişkeni kullanılırsa, seri hale getirici derleme LoadFrom yöntemini kullanarak yüklenmeyecektir. AssemblyName bağımsız değişkeni kullanılırsa, seri hale getirici derleme LoadWithPartialName yöntemini kullanarak yüklenmeyecektir. Derleme yükleme hakkında daha fazla bilgi için aşağıdaki Microsoft Web sitesini ziyaret edin:
http://blogs.msdn.com/suzcook/ (http://blogs.msdn.com/suzcook/)
Genel Derleme Önbelleği (GAC için) seri hale getirici birleştirmelerini yüklemek istiyorsanız, AssemblyName bağımsız değişkenini kullanın ve tam olarak nitelenmiş bir derleme adı sağlamanız gerekir.

Akıllı istemci yöntemleri kullanarak dağıtılmış uygulamaları

Proxy içeren derlemeye yüklenir ve yerel bilgisayardan yürütülür XmlSerializerAssemblyAttribute özniteliği için CodeBase sözdizimini kullanmak tercih olur. Bu durumda, seri hale getirici derleme aynı klasöre proxy içeren bir derleme olarak dağıtılması. Derleme bir akıllı istemci dağıtım senaryosunda, HTTP üzerinden LoadFrom yöntemini kullanarak yükledi, örneğin, seri hale getirme derlemesi doğru XmlSerializerAssemblyAttribute özniteliği tarafından yüklenmeyecek. Bu sorun, proxy derleme Yükleme içerik yerine ortak dil çalışma zamanı yükleyicinin ait LoadFrom içeriğinde varolduğundan ve yoklama oluşmaz nedeniyle oluşur. To work around this problem, use the other AssemblyName syntax that is supported by the attribute with a dummy assembly name.
[System.Xml.Serialization.XmlSerializerAssemblyAttribute(AssemblyName="LoadMySerializerAssemblyNow")]
Your application can then implement a handler for the AppDomain's AssemblyResolve event to intercept the request to load the serializer assembly and load it from the correct location.
private void Form1_Load(object sender, System.EventArgs e)
{
			AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
}
static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
 {
			Assembly a = null;
			string serializationAssemblyPartialName = "LoadMySerializerAssemblyNow";
if (args.Name == serializationAssemblyPartialName)
	{string sSerializersDLL = "<Name Of The Serializer DLL>";
string smartDeploymentHostLocation = "<Full path location to the Serializer DLL>";
a = Assembly.LoadFrom(smartDeploymentHostLocation + sSerializersDLL);
}
			return a;
		}

Alternatif pregenerator örnek

Seri hale getirici pregenerator örnek uygulama daha gelişmiş bir sürümünü aşağıdadır. Bu sürüm, imzalanmış bir seri hale getirici birleştirmeler oluşturma izin verir. Şu kodu kullanın.
namespace PreGenNS 
{
	using System;
	using System.Collections;
	using System.IO;
	using System.Reflection;
	using System.Xml.Serialization;
	using System.Text;
	using System.Globalization;
	using System.Web.Services.Protocols;
	using System.Threading;
	using System.CodeDom.Compiler;
	using System.Diagnostics;
	using System.Text.RegularExpressions;

	public class Pregen 
	{
		private static bool _verbose = true;

		
		// We use this as the standard suffix on all the serializer DLLs.
		// It must match the short name of the proxy assembly class with 
		const string SerializerSuffix = ".Serializer.dll";

		
		/// Key in the app config file with path of AssemblyInfo file.
		private const string AssemblyInfoAppKey = "AssemblyInfoFile";

		//private const string CSCCmd = "csc.exe";
		// Obtain the full path for the compiler, just in case the path is not set correctly

		private readonly string CSCCmd = System.Runtime.InteropServices.RuntimeEnvironment.RuntimeDirectory() + "csc.exe";

		public static int Main(string[] args) {		
			// Are we in a recursive call?
			//TODO: could really use a single value -- use filesToDelete...
			if (AppDomain.CurrentDomain.GetData(CallingAppDomainKey) == null) {
				return RunSlave(args);
			}

			string dllName = "";
			bool invalidUsage = false;

			if(args.Length == 1)
			{
				dllName = args[0];
			}
			else if(args.Length == 2)
			{
				if(!(args[0] == "/Q" || args[0] == "/q"))
				{
					invalidUsage = true;
				}
				else
				{
					dllName = args[1];
					_verbose = false;
				}
			}
			else 
			{
				invalidUsage = true;
			}

			if (invalidUsage)
			{
				Console.WriteLine("usage: ");
				Console.WriteLine(" pregen [/Q] assembly");
				return 1;
			}
			

			// Update Private path setting in current application domain
			if (updatePrivatePath() != 0)
			{
				return 1;
			}
			
			Pregen pregen = new Pregen();
			int rc = pregen.Run(dllName);
			//Console.Read();
			return rc;
		}


		// Reads private path settings from config file and updates appdomain.  This permits configurable probing that is needed for preserialization.
		static int updatePrivatePath()
		{
			string defaultPrivatePath = System.Configuration.ConfigurationSettings.AppSettings["PregenDefaultPrivatePath"];
			string dynamicPrivatePath = System.Configuration.ConfigurationSettings.AppSettings["PregenDynamicPrivatePath"];
			string env_PREGEN_VALUES = Environment.GetEnvironmentVariable("PREGEN_VALUES");
			string [] replacementBlocks, temp;

			if (_verbose)
				Console.WriteLine("Read PREGEN_VALUES Env Variable, Value = " + env_PREGEN_VALUES);

			//process the dynamic path if the environment variable PREGEN_VALUES is present 
			if (env_PREGEN_VALUES == null || env_PREGEN_VALUES == "")
			{
				if (defaultPrivatePath != null && defaultPrivatePath != "")
				{
					AppDomain.CurrentDomain.AppendPrivatePath(defaultPrivatePath);

					if (_verbose)
						Console.WriteLine("Appended private path with: " + defaultPrivatePath);
				}
			}
			else
			{
				if (dynamicPrivatePath != null && dynamicPrivatePath != "")
				{
					//do substitutions in dynamic path
					replacementBlocks = env_PREGEN_VALUES.ToUpper().Split(";".ToCharArray());
					dynamicPrivatePath = dynamicPrivatePath.ToUpper();

					for(int i = 0; i < replacementBlocks.Length; i++)
					{
						temp = replacementBlocks[i].Split("=".ToCharArray());
						if(temp.Length != 2)
						{
							Console.Error.WriteLine("Invalid Environment Variable format - PREGEN_VALUES");
							return 1;
						}

						dynamicPrivatePath = dynamicPrivatePath.Replace(temp[0],temp[1]);
					}
					
					AppDomain.CurrentDomain.AppendPrivatePath(dynamicPrivatePath);

					if (_verbose )
						Console.WriteLine("Appended private path with: " + dynamicPrivatePath);
				}
			}
			return 0;
		}
		
		int Run(string assemblyName) 
		{

			try 
			{
				GenerateAssembly(assemblyName);
			}
			catch (Exception e) 
			{
				if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) 
				{
					throw;
				}
				Error(e, "Error processing " + assemblyName + ": ");
				return 1;
			}
			return 0;
		}



		// Generates the serializer assembly for the proxy assembly specified
		void GenerateAssembly(string assemblyName) 
		{
			Assembly assembly = LoadAssembly(assemblyName, true);
			Type[] types = assembly.GetTypes();
			ArrayList mappings = new ArrayList();
			ArrayList importedTypes = new ArrayList();
			XmlReflectionImporter importer = new XmlReflectionImporter();

			
			//Obtain the imported serializable types
			for (int i = 0; i < types.Length; i++) 
			{
				Type type = types[i];
				if (HttpWebClientProtocol.GenerateXmlMappings(type, mappings)) 
				{
					importedTypes.Add(type);
				}
			}
			if (importedTypes.Count <= 0) {
				Console.Out.WriteLine("Assembly '{0}' does not contain any serializable types.", assembly.Location);
				return;
			}
 
			{
				Type[] serializableTypes = (Type[])importedTypes.ToArray(typeof(Type));
				XmlMapping[] allMappings = (XmlMapping[])mappings.ToArray(typeof(XmlMapping));

				bool wasError = false;
				bool gac = assembly.GlobalAssemblyCache;
				string codePath = gac ? Environment.CurrentDirectory : Path.GetDirectoryName(assembly.Location);

				//adjust compiler params
				CompilerParameters parameters = new CompilerParameters();
				parameters.GenerateInMemory = false;
				parameters.IncludeDebugInformation = false;
				parameters.TempFiles = new TempFileCollection(codePath, true);
				
				//generate the serializer
				Assembly serializer = XmlSerializer.GenerateSerializer(serializableTypes, allMappings, parameters);
				if (serializer == null) {
					Console.Out.WriteLine("Failed pregenerate serializer for '{0}'", assembly.Location);
					wasError = true;
				}
				else 
				{
					serializer = null;
				}

				// Determine whether there is an assemblyInfoFile in the config file.
				string assemblyInfoFile = System.Configuration.ConfigurationSettings.AppSettings[AssemblyInfoAppKey];
				if (assemblyInfoFile != null) { 
					if (! File.Exists(assemblyInfoFile)) {
						Console.WriteLine("ERROR: AssemblyInfo file: {0} does not exist.", assemblyInfoFile);
						wasError = true;
					}
				}

				if (!wasError) {
					// Recompile the Serializer, same options, except to include the assemblyInfo file and
					// adjust the output name.

					// We have to find 
					//		1. a .cs file (the serializer source)
					//		2. a .cmdline file (the compiler options used)
					// among the temp files from the first compile.
					
					string csFile		= null;
					string cmdlineFile	= null;

					foreach (string curFile in parameters.TempFiles ) {
						string fileNameLC = curFile.ToLower();
						if (fileNameLC.EndsWith(".cs") ) {
							csFile = curFile;
						}
						else if (fileNameLC.EndsWith(".cmdline")) {
							cmdlineFile = curFile;
						}
						//Do not care about the other files...
					}
					if (csFile == null || cmdlineFile == null) {
						Console.WriteLine("Error: needed to rebuild, but cannot find either .cs or .cmdline file\n");
						DeleteTempFiles(parameters);
						return;
					}

					// So now we have found the file and the cmdline args.  We only need run the compiled application after 
					// adjusting the parameters to include the AssemblyInfo file and to change the output.
					
					// Typical calling options to csc for this sequence are:
					//		csc /noconfig @xxx.cmdline
					// we'll change this to expand the contents of the cmdline file

					// build the right name for the target serializer.
					//TODO: we should be able to read the attribute from the proxy DLL and match our output
					// to that name.
					string serializerName = Path.GetDirectoryName(assembly.Location) + @"\" 
											+ assembly.GetName().Name + SerializerSuffix;

					string cmdLine = AdjustCmdLine(cmdlineFile, assemblyInfoFile, serializerName);

					ProcessStartInfo ps = new ProcessStartInfo(CSCCmd, cmdLine);
					ps.WindowStyle = ProcessWindowStyle.Hidden;
					Process p = Process.Start(ps);
					p.WaitForExit();
					int rc = p.ExitCode;
					if (rc > 0) {
						//TODO: put useful handling here...
						Console.WriteLine("ERROR: Compiler problem, rc = {0}", rc);
						wasError = true;
					}

					//TODO: Cannot ditch temp assembly because the assembly is now loaded.
					DeleteTempFiles(parameters);

					if (!wasError) {
						Console.Out.WriteLine("Generated Serialization Assembly Name: {0}", serializerName);
					}
					Console.Out.WriteLine("Done");
				}
			}
		}


		// Delete temporary files from a CompilerParameters list.
		private void DeleteTempFiles(CompilerParameters cp) {
			ArrayList unDeletedFiles = new ArrayList(10);
			foreach(string fileName in cp.TempFiles) {
				try {
					File.Delete(fileName);
				}
				catch(Exception) {
					unDeletedFiles.Add(fileName);
					//Console.WriteLine("Warning: Unable to delete temp file: {0}, exception={1}(\"{2}\")",
					//	Path.GetFileName(fileName), e.GetType().FullName, e.Message);
				}
			}
			if (unDeletedFiles.Count > 0) {
				// put the list into the calling appDomain's environment for later deletion
				string[] files = new string[unDeletedFiles.Count];
				unDeletedFiles.CopyTo(files);

				//TODO: should really be concatenating to any existing value -- maybe leave as an ArrayList?
				AppDomain.CurrentDomain.SetData(FilesToDeleteKey, files);
			}
		}


		/// Rebuild a commandline for csc, adding assemblyInfoFile to the end of the line and adjusting the 
		/// output file name as specified.
		private string AdjustCmdLine(string cmdlineFile, string assemblyInfoFile, string outputFile) {	
			// Obtain the text from the @ response file that is used by the Framework Serialization builder
			StreamReader file = File.OpenText(cmdlineFile);
			string cmdLine = file.ReadToEnd();
			file.Close();

			// add the assemblyInfo file at the end of the command if it was specified
			if (assemblyInfoFile != null)
				cmdLine = String.Format(@"/noconfig {0} ""{1}""", cmdLine, assemblyInfoFile);

			// replace the /OUT option with our value.
			Regex re = new Regex(@"/OUT:""[^""]+.", RegexOptions.IgnoreCase);
			cmdLine = re.Replace(cmdLine, @"/OUT:""" + outputFile + @"""");

			return cmdLine;
		}

		static Assembly LoadAssembly(string assemblyName, bool throwOnFail) 
		{
			Assembly assembly = null;
			string path = Path.GetFullPath(assemblyName).ToLower(CultureInfo.InvariantCulture);
			if (File.Exists(path)) 
			{
				assembly = Assembly.LoadFrom(path);
			}
			else 
			{
				try 
				{
					assembly = Assembly.Load(assemblyName);
				}
				catch (Exception e) 
				{
					if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) 
					{
						throw;
					}
					Error(e, "Error: ");
				}
				if (assembly == null) 
				{
					string justName = Path.GetFileNameWithoutExtension(assemblyName);
					try 
					{
						assembly = Assembly.Load(justName);
					}
					catch (Exception e) 
					{
						if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) 
						{
							throw;
						}
						Error(e, "Error: ");
					}
				}
			}
			if (assembly == null) 
			{
				if (throwOnFail)
					throw new InvalidOperationException("Cannot load assembly " + assemblyName);
				return null;
			}
			return assembly;
		}

		static void Error(Exception e, string prefix) 
		{
			Console.Error.WriteLine(prefix + e.Message);
			if (e.InnerException != null) 
			{
				Error(e.InnerException, " - ");
			}
		}

		static void Warning(Exception e) 
		{
			Console.Out.WriteLine(" - " + e.Message);
			if (e.InnerException != null) 
			{
				Warning(e.InnerException);
			}
		}

		private static AppDomain DuplicateAppDomain(AppDomain template, string newName) {
			AppDomain res = AppDomain.CreateDomain(newName, template.Evidence, template.SetupInformation);
			return res;
		}

		// keys in AppDomain properties
		private const string CallingAppDomainKey	= "__Calling_AppDomain__";
		private const string FilesToDeleteKey		= "__Files_To_Delete__";

		// Called from Main to set up and run the second copy of the program.
		// args: command-line arguments for second execution
		private static int RunSlave(string[] args) {

			// Start a copy of this program in another application domain
			AppDomain ad = DuplicateAppDomain(AppDomain.CurrentDomain, "serializerAD");
			Assembly ca = Assembly.GetExecutingAssembly();

			// set a marker so target domain knows that it is the subordinate.
			ad.SetData(CallingAppDomainKey, AppDomain.CurrentDomain.FriendlyName);
			ad.SetData(FilesToDeleteKey, new string[0]);

			int rc = ad.ExecuteAssembly(ca.Location, ca.Evidence, args);

			// Now delete any files
			string[] fileList = (string[])ad.GetData(FilesToDeleteKey);

			AppDomain.Unload(ad);

			if (fileList != null) {
				foreach(string fileName in fileList) {
					try {
						File.Delete(fileName);
					}
					catch(Exception e) {
						Console.WriteLine("Warning: Unable to delete temp file: {0}, exception={1}(\"{2}\")",
							Path.GetFileName(fileName), e.GetType().FullName, e.Message);
					}
				}
			}
			return rc;  
		}

	}
}

Referanslar

Daha fazla bilgi için aşağıdaki MSDN Web sitelerini ziyaret edin:
http://msdn2.microsoft.com/en-us/library/y92e0td0(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/y92e0td0(vs.71).aspx)
http://msdn2.microsoft.com/en-us/library/hk7y1596(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/hk7y1596(vs.71).aspx)

Bu makaledeki bilginin uygulandığı durum:
  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.1 Service Pack 1
  • Microsoft Visual Studio .NET 2003 Enterprise Architect
  • Microsoft Visual Studio .NET 2003 Enterprise Developer
  • Microsoft Visual Studio .NET 2003 Professional Edition
  • Microsoft Visual Studio .NET 2003 Academic Edition
Anahtar Kelimeler: 
kbmt kbqfe kbhotfixserver kbtshoot kbdll kbwebservices kbuser kbarchitecture kbfix KB872800 KbMttr
Otomatik TercümeOtomatik Tercüme
ÖNEMLİ: Bu makale, bir kişi tarafından çevrilmek yerine, Microsoft makine-çevirisi yazılımı ile çevrilmiştir. Microsoft size hem kişiler tarafından çevrilmiş, hem de makine-çevrisi ile çevrilmiş makaleler sunar. Böylelikle, bilgi bankamızdaki tüm makalelere, kendi dilinizde ulaşmış olursunuz. Bununla birlikte, makine tarafından çevrilmiş makaleler mükemmel değildir. Bir yabancının sizin dilinizde konuşurken yapabileceği hatalar gibi, makale; kelime dağarcığı, söz dizim kuralları veya dil bilgisi açısından yanlışlar içerebilir. Microsoft, içeriğin yanlış çevrimi veya onun müşteri tarafından kullanımından doğan; kusur, hata veya zarardan sorumlu değildir. Microsoft ayrıca makine çevirisi yazılımını sıkça güncellemektedir.
Makalenin İngilizcesi aşağıdaki gibidir:872800  (http://support.microsoft.com/kb/872800/en-us/ )