本文整理汇总了C#中System.Reflection.AssemblyName.SetPublicKeyToken方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyName.SetPublicKeyToken方法的具体用法?C# AssemblyName.SetPublicKeyToken怎么用?C# AssemblyName.SetPublicKeyToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.AssemblyName
的用法示例。
在下文中一共展示了AssemblyName.SetPublicKeyToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RedirectAssembly
public static void RedirectAssembly(string shortName, Version targetVersion, string publicKeyToken)
{
ResolveEventHandler handler = null;
handler = (sender, args) =>
{
// Use latest strong name & version when trying to load SDK assemblies
var requestedAssembly = new AssemblyName(args.Name);
if (requestedAssembly.Name != shortName)
return null;
Debug.WriteLine("Redirecting assembly load of " + args.Name
+ ",\tloaded by " +
(args.RequestingAssembly == null ? "(unknown)" : args.RequestingAssembly.FullName));
requestedAssembly.Version = targetVersion;
requestedAssembly.SetPublicKeyToken(
new AssemblyName("x, PublicKeyToken=" + publicKeyToken).GetPublicKeyToken());
requestedAssembly.CultureInfo = CultureInfo.InvariantCulture;
AppDomain.CurrentDomain.AssemblyResolve -= handler;
return Assembly.Load(requestedAssembly);
};
AppDomain.CurrentDomain.AssemblyResolve += handler;
}
示例2: LoadAssembly
public Assembly LoadAssembly(string name)
{
System.Diagnostics.Debug.Write("Trying to load assembly: " + name);
if (System.IO.File.Exists(name))
{
return Assembly.LoadFrom(name);
}
else
{
string assemblyName = System.IO.Path.GetFileNameWithoutExtension(name);
byte[] publicKeyToekn;
if (GACGeometryKeyTokens.TryGetValue(assemblyName, out publicKeyToekn))
{
AssemblyName an = new AssemblyName();
an.Name = assemblyName;
an.SetPublicKeyToken(publicKeyToekn);
an.Version = mExecutingAssemblyName.Version;
an.CultureInfo = mExecutingAssemblyName.CultureInfo;
an.ProcessorArchitecture = mExecutingAssemblyName.ProcessorArchitecture;
System.Diagnostics.Debug.Write("Assembly: " + assemblyName + "," + an.Version.ToString() + " is in GAC.");
return Assembly.Load(an);
}
}
throw new System.IO.FileNotFoundException();
}
示例3: EmittedAssembly
public EmittedAssembly(string name, string rootNamespace, Version version, CultureInfo culture
, byte[] publicKey, byte[] publicKeyToken)
{
Contracts.Require.IsNotNull("name", name);
Contracts.Require.IsNotEmpty("name", name);
Contracts.Require.IsNotNull("rootNamespace", rootNamespace);
Contracts.Require.IsNotEmpty("rootNamespace", name);
Contracts.Require.IsNotNull("version", version);
Contracts.Require.IsNotNull("culture", culture);
this._classes = new Dictionary<string, EmittedClass>();
this.RootNamespace = rootNamespace ?? name;
_assemName = new AssemblyName(name);
_assemName.Version = version;
_assemName.CultureInfo = culture;
_assemName.SetPublicKey(publicKey);
_assemName.SetPublicKeyToken(publicKeyToken);
#if DEBUG
this._assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(_assemName, AssemblyBuilderAccess.RunAndSave);
this._module = this._assembly.DefineDynamicModule(name, name + ".dll", false);
#else
this._assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(_assemName, AssemblyBuilderAccess.Run);
this._module = this._assembly.DefineDynamicModule(name, name + ".dll", false);
#endif
}
示例4: SetAssemblyResolver
/// <summary>
/// Creates a dictionary of assemblyNames and assemblies and sets the AssemblyResolver for the current AppDomain.
/// </summary>
/// <param name="assemblies">List of loaded assemblies</param>
internal static void SetAssemblyResolver(IEnumerable<Assembly> assemblies)
{
ConcurrentDictionary<string, Assembly> assemblyNames = new ConcurrentDictionary<string, Assembly>(StringComparer.OrdinalIgnoreCase);
foreach (var assembly in assemblies)
{
// Keep a dictionary of assembly names and assemblies. It is used in the AssemblyResolve event handler.
assemblyNames[assembly.FullName] = assembly;
// If the assembly is a signed Open Ria assembly, then also add an entry
// so that it is used in places where the of unsigned version of the assembly is requested
var assemblyName = assembly.GetName();
if(assemblyName.IsOpenRiaAssembly() && assemblyName.IsSigned())
{
var unsignedName = new AssemblyName(assemblyName.FullName);
unsignedName.SetPublicKeyToken(new byte[0]);
assemblyNames[unsignedName.FullName] = assembly;
}
}
loadedAssemblyNames = assemblyNames;
// Unregister the event handler first, in case it was registered before. If it wasn't, this would be a no-op.
AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(AssemblyUtilities.CurrentDomain_AssemblyResolveEventHandler);
// Register the event handler for this call.
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyUtilities.CurrentDomain_AssemblyResolveEventHandler);
}
示例5: TryGetPregeneratedPInvoke
/// <summary>
/// Returns pregenerated interop code for given PInvoke method if one exist
/// </summary>
public static MethodDesc TryGetPregeneratedPInvoke(MethodDesc method)
{
Debug.Assert(method.IsPInvoke);
var metadataType = (MetadataType)method.OwningType;
var module = metadataType.Module;
var assemblyName = ((IAssemblyDesc)module).GetName();
var interopAssemblyName = new AssemblyName();
interopAssemblyName.Name = assemblyName.Name + AssemblyNameSuffix;
interopAssemblyName.Version = assemblyName.Version;
interopAssemblyName.SetPublicKeyToken(interopAssemblyName.GetPublicKeyToken());
interopAssemblyName.CultureName = assemblyName.CultureName;
interopAssemblyName.ContentType = assemblyName.ContentType;
var interopModule = module.Context.ResolveAssembly(interopAssemblyName, false);
if (interopModule == null)
return null;
var pregeneratedMethod = GetMatchingMethod(interopModule, method);
if (pregeneratedMethod == null)
{
// TODO: Better error message
throw new MissingMemberException("Missing method in " + interopAssemblyName.Name + ":" + method.ToString());
}
return pregeneratedMethod;
}
示例6: SetAssemblyName
protected void SetAssemblyName (LoadInfoType loadInfoType, string filename, string name, string version,
string culture, string publicKeyToken, string className)
{
assemblyName = new AssemblyName ();
this.infoType = loadInfoType;
this.className = className;
if (infoType == LoadInfoType.AssemblyName) {
if (version != null)
assemblyName.Version = new Version (version);
if (culture != null) {
if (culture == "neutral")
culture = String.Empty;
assemblyName.CultureInfo = new CultureInfo (culture);
}
if (publicKeyToken != null) {
char[] chars = publicKeyToken.ToCharArray ();
byte[] bytes = new byte [Buffer.ByteLength (chars)];
for (int i = 0; i < Buffer.ByteLength (chars); i++)
bytes [i] = Buffer.GetByte (chars, i);
assemblyName.SetPublicKeyToken (bytes);
}
assemblyName.Name = name;
} else if (infoType == LoadInfoType.AssemblyFilename) {
this.filename = filename;
} else {
;
}
}
示例7: GetAssembly
/// <summary>
/// Returns a "live" System.Reflection.Assembly instance that provides reflective access to the referenced assembly.
/// If the assembly cannot be found or cannot be loaded, the result is null.
/// </summary>
public Assembly/*?*/ GetAssembly(IAssemblyReference/*?*/ assemblyReference) {
if (assemblyReference == null) return null;
var ident = assemblyReference.AssemblyIdentity;
Assembly result = null;
if (!this.assemblyMap.TryGetValue(ident, out result)) {
var name = new System.Reflection.AssemblyName();
if (!String.IsNullOrEmpty(ident.Location))
name.CodeBase = new Uri(ident.Location).ToString();
name.CultureInfo = new System.Globalization.CultureInfo(ident.Culture);
name.Name = ident.Name.Value;
name.SetPublicKeyToken(new List<byte>(ident.PublicKeyToken).ToArray());
name.Version = ident.Version;
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var loadedAssem in loadedAssemblies) {
if (System.Reflection.AssemblyName.ReferenceMatchesDefinition(name, loadedAssem.GetName())) {
result = loadedAssem;
break;
}
}
if (result == null) {
try {
result = Assembly.Load(name);
} catch (System.UriFormatException) {
} catch (System.IO.FileNotFoundException) {
} catch (System.IO.FileLoadException) {
} catch (System.BadImageFormatException) {
}
this.assemblyMap.Add(ident, result);
}
}
return result;
}
示例8: Processor
/// <summary>
/// Create a Processor, indicating whether it is to be schema-aware.
/// </summary>
/// <param name="schemaAware">Set to true if the Processor is to be schema-aware.
/// This requires the Saxon-SA product to be installed, with a valid license key.</param>
/// <param name="loadLocally">Set to true if Saxon-SA is to be loaded from the application
/// directory rather than from the Global Assembly Cache. This option should normally
/// be set only when troubleshooting, for example when using a locally-patched version
/// of the software.</param>
public Processor(bool schemaAware, bool loadLocally) {
if (schemaAware) {
if (loadLocally) {
Assembly asm = Assembly.Load("saxon8sa");
} else {
try {
int[] v = JVersion.getStructuredVersionNumber();
AssemblyName asn = new AssemblyName();
asn.Name = "saxon8sa";
asn.Version = new Version(v[0], v[1], v[2], v[3]);
//asn.Version = new Version(JVersion.getMajorVersion(), JVersion.getMinorVersion());
asn.SetPublicKeyToken(new byte[] { 0xe1, 0xfd, 0xd0, 0x02, 0xd5, 0x08, 0x3f, 0xe6 });
asn.CultureInfo = new CultureInfo("");
Assembly asm = Assembly.Load(asn);
// try to load the saxon8sa.dll assembly
//Assembly asm = Assembly.Load("saxon8sa, Ver=" + JVersion.getProductVersion() + ".0.1, " +
// @"SN=e1fdd002d5083fe6, Loc=neutral");
} catch (Exception e) {
Console.WriteLine("Cannot load Saxon-SA software (assembly saxon8sa.dll version " +
JVersion.getProductVersion() + ".0.1)");
throw e;
}
}
config = JConfiguration.makeSchemaAwareConfiguration(null);
schemaManager = new SchemaManager(config);
} else {
config = new JConfiguration();
}
config.setURIResolver(new DotNetURIResolver(new XmlUrlResolver()));
config.setCollectionURIResolver(new DotNetCollectionURIResolver());
}
开发者ID:pombredanne,项目名称:https-dev.saxonica.com-repos-archive-opensource-,代码行数:41,代码来源:Configuration.cs
示例9: CreateProxyModule
private static ModuleBuilder CreateProxyModule() {
AssemblyName name = new AssemblyName("AutoMapper.Proxies");
name.SetPublicKey(privateKey);
name.SetPublicKeyToken(privateKeyToken);
//AssemblyBuilder builder = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
AssemblyBuilder builder = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
return builder.DefineDynamicModule("AutoMapper.Proxies.emit");
}
示例10: Initialize
private void Initialize()
{
_name = new AssemblyName();
_name.Name = AssemblyCache.GetName(Interface);
_name.Version = AssemblyCache.GetVersion(Interface);
_name.CultureInfo = AssemblyCache.GetCulture(Interface);
_name.SetPublicKeyToken(AssemblyCache.GetPublicKeyToken(Interface));
}
示例11: CreateAssemblyName
public AssemblyName CreateAssemblyName()
{
var assemblyName = new AssemblyName(Name);
assemblyName.Version = new Version(Version);
assemblyName.CultureInfo = new CultureInfo(Culture);
assemblyName.SetPublicKeyToken(FromHexString(PublicKeyToken));
assemblyName.ProcessorArchitecture = ProcessorArchitecture;
return assemblyName;
}
示例12: Initalize
private void Initalize() {
AssemblyName asmname = new AssemblyName();
asmname.Name = "dynTypeCode";
asmname.Version = new Version(0, 0, 0, 0);
asmname.CultureInfo = CultureInfo.InvariantCulture;
asmname.SetPublicKeyToken(new byte[0]);
m_asmBuilder = System.Threading.Thread.GetDomain().
DefineDynamicAssembly(asmname, AssemblyBuilderAccess.Run);
m_modBuilder = m_asmBuilder.DefineDynamicModule("typecodeTypes");
}
示例13: GetAssemblyFullName
public static string GetAssemblyFullName(string name, string version, System.Globalization.CultureInfo culture, string publicKeyToken) {
AssemblyName asmName = new AssemblyName();
asmName.Name = name;
asmName.Version = new Version(version);
asmName.CultureInfo = culture;
if(publicKeyToken != null && publicKeyToken.Length == 2 * PublicKeyTokenBytesLength) {
asmName.SetPublicKeyToken(StringToBytes(publicKeyToken));
}
return asmName.FullName;
}
示例14: GetAssemblyName
private static AssemblyName GetAssemblyName(string codeBase, string fullName)
{
var assemblyName = new AssemblyName();
var parts = fullName.Split(commaArray);
assemblyName.Name = parts[0].TrimEnd(spaceArray);
assemblyName.Version = Version.Parse(GetValue(parts[1]));
assemblyName.CultureInfo = GetCultureInfo(GetValue(parts[2]));
var publicKeyTokenString = GetValue(parts[3]);
if (publicKeyTokenString != "null")
{
assemblyName.SetPublicKeyToken(Conversion.HexStringToByteArray(publicKeyTokenString));
}
else
{
assemblyName.SetPublicKeyToken(new byte[0]);
}
assemblyName.CodeBase = "file:///" + codeBase.Replace('\\', '/');
return assemblyName;
}
示例15: CurrentDomain_AssemblyResolve
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (!args.Name.StartsWith(prefix))
return null;
var name = new AssemblyName(args.Name);
name.SetPublicKeyToken(publicKeyToken);
name.Version = roslynVersion;
Debug.WriteLine("Ref12: Redirecting load of " + args.Name + ",\tfrom " + (args.RequestingAssembly == null ? "(unknown)" : args.RequestingAssembly.FullName));
return Assembly.Load(name);
}