[Test] // DefineVersionInfoResource (String, String, String, String, String)
	public void TestDefineVersionInfoResource2_Culture_NotSupported ()
	{
		AssemblyName aname = new AssemblyName ();
		aname.CultureInfo = new CultureInfo ("nl-BE");
		aname.Name = "lib";
		aname.Version = new Version (3, 5, 7);

		AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
			aname, AssemblyBuilderAccess.RunAndSave,
			tempDir);

		// AssemblyCulture
		Type attrType = typeof (AssemblyCultureAttribute);
		ConstructorInfo ci = attrType.GetConstructor (new Type [] { typeof (String) });
		CustomAttributeBuilder cab = new CustomAttributeBuilder (
			ci, new object [1] { "doesnotexist" });
		ab.SetCustomAttribute (cab);

		ab.DefineVersionInfoResource ("A", "1.0", "C", "D", "E");

		try {
			ab.Save ("lib.dll");
			Assert.Fail ("#A1");
		} catch (ArgumentException ex) {
			// Culture name doesnotexist is not supported
			Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
			Assert.IsNull (ex.InnerException, "#A3");
			Assert.IsNotNull (ex.Message, "#A4");
			Assert.IsTrue (ex.Message.IndexOf ("doesnotexist") != -1, "#A5");
			Assert.AreEqual ("name", ex.ParamName, "#A6");
		}

		ab = AppDomain.CurrentDomain.DefineDynamicAssembly (aname,
			AssemblyBuilderAccess.RunAndSave, tempDir);

		// AssemblyCulture
		attrType = typeof (AssemblyCultureAttribute);
		ci = attrType.GetConstructor (new Type [] { typeof (String) });
		cab = new CustomAttributeBuilder (ci, new object [1] { "neutral" });
		ab.SetCustomAttribute (cab);

		ab.DefineVersionInfoResource ("A", "1.0", "C", "D", "E");

		try {
			ab.Save ("lib.dll");
			Assert.Fail ("#B1");
		} catch (ArgumentException ex) {
			// Culture name neutral is not supported
			Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
			Assert.IsNull (ex.InnerException, "#B3");
			Assert.IsNotNull (ex.Message, "#B4");
			Assert.IsTrue (ex.Message.IndexOf ("neutral") != -1, "#B5");
			Assert.AreEqual ("name", ex.ParamName, "#B6");
		}
	}
 private static void SetVersionInformation(AssemblyBuilder asmBldr, object typeLib, AssemblyName asmName)
 {
     string strName = null;
     string strDocString = null;
     int dwHelpContext = 0;
     string strHelpFile = null;
     ((ITypeLib) typeLib).GetDocumentation(-1, out strName, out strDocString, out dwHelpContext, out strHelpFile);
     string product = string.Format(CultureInfo.InvariantCulture, Environment.GetResourceString("TypeLibConverter_ImportedTypeLibProductName"), new object[] { strName });
     asmBldr.DefineVersionInfoResource(product, asmName.Version.ToString(), null, null, null);
     SetTypeLibVersionAttribute(asmBldr, typeLib);
 }
        [System.Security.SecurityCritical]  // auto-generated
        private static void SetVersionInformation(AssemblyBuilder asmBldr, Object typeLib, AssemblyName asmName)
        {
            // Extract the name of the typelib.
            String strTypeLibName = null;
            String strDocString = null;
            int dwHelpContext = 0;
            String strHelpFile = null;
            ITypeLib pTLB = (ITypeLib)typeLib;
            pTLB.GetDocumentation(-1, out strTypeLibName, out strDocString, out dwHelpContext, out strHelpFile);

            // Generate the product name string from the named of the typelib.
            String strProductName = String.Format(CultureInfo.InvariantCulture, Environment.GetResourceString("TypeLibConverter_ImportedTypeLibProductName"), strTypeLibName);

            // Set the OS version information.
            asmBldr.DefineVersionInfoResource(strProductName, asmName.Version.ToString(), null, null, null);

            // Set the TypeLibVersion attribute
            SetTypeLibVersionAttribute(asmBldr, typeLib);
        }
Пример #4
0
	[Test] // DefineVersionInfoResource (String, String, String, String, String)
	public void TestDefineVersionInfoResource2_Culture_NotSupported ()
	{
		AssemblyName aname = new AssemblyName ();
		aname.CultureInfo = new CultureInfo ("nl-BE");
		aname.Name = "lib";
		aname.Version = new Version (3, 5, 7);

		AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
			aname, AssemblyBuilderAccess.RunAndSave,
			tempDir);

		// AssemblyCulture
		Type attrType = typeof (AssemblyCultureAttribute);
		ConstructorInfo ci = attrType.GetConstructor (new Type [] { typeof (String) });
		CustomAttributeBuilder cab = new CustomAttributeBuilder (
			ci, new object [1] { "doesnotexist" });
		ab.SetCustomAttribute (cab);

		ab.DefineVersionInfoResource ("A", "1.0", "C", "D", "E");

		try {
			ab.Save ("lib.dll");
			Assert.Fail ("#A1");
		} catch (CultureNotFoundException ex) {
		}

		ab = AppDomain.CurrentDomain.DefineDynamicAssembly (aname,
			AssemblyBuilderAccess.RunAndSave, tempDir);

		// AssemblyCulture
		attrType = typeof (AssemblyCultureAttribute);
		ci = attrType.GetConstructor (new Type [] { typeof (String) });
		cab = new CustomAttributeBuilder (ci, new object [1] { "neutral" });
		ab.SetCustomAttribute (cab);

		ab.DefineVersionInfoResource ("A", "1.0", "C", "D", "E");

		try {
			ab.Save ("lib.dll");
			Assert.Fail ("#B1");
		} catch (CultureNotFoundException ex) {
		}
	}