Verify the assembly name without using AssemblyName

I need to get a qualified assembly name without using AssemblyName, because I get a System.IO.FileLoadException (assemblies are not available).

I manage strings, not assemblies. If I have a string, I want to get the strings as the following for the string variables asm1 and asm2.

FullName = "CalidadCodigo.ParserSQL.Reglas.AnalisisSintactico"

Assembly = "CalidadCodigo.ParserSQL.AnalisisSintactico"

Version = "Version = 1.0.0.0"

Culture = "Culture = Neutral"

Public token = "PublicKeyToken = 9744987c0853bf9e"

any suggestions, sample code?

var asm1 = "CalidadCodigo.ParserSQL.Reglas.AnalisisSintactico,CalidadCodigo.ParserSQL.AnalisisSintactico, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744987c0853bf9e"; var asm2 = "CalidadCodigo.ParserSQL.Reglas.AnalisisSintactico, CalidadCodigo.ParserSQL.AnalisisSintactico , Version=1.0.0.0 , Culture=neutral, PublicKeyToken=9744987c0853bf9e "; 

an exception was thrown: System.IO.FileLoadException: El nombre de ensamblado o el cรณdigo base dado no in Valido. (Excepciรณn de HRESULT: 0x80131047).

System.Reflection.AssemblyName.nInit (Assembly & Assembly, Boolean forIntrospection, Boolean raiseResolveEvent) System.Reflection.AssemblyName.nInit () System.Reflection.AssemblyName..ctor (String AssemblyName)

+4
source share
3 answers

Can you just separate by commas, trim the lines, and then check the expected prefix of each part?

 List<string> parts = name.Split(',') .Select(x => x.Trim()) .ToList(); string name = parts[0]; string assembly = parts.Count < 2 ? null : parts[1]; string version = parts.Count < 3 ? null : parts[2]; string culture = parts.Count < 4 ? null : parts[3]; string token = parts.Count < 5 ? null : parts[4]; if (version != null && !version.StartsWith("Version=")) { throw new ArgumentException("Invalid version: " + version); } // etc 
+5
source

Jon's answer does not account for array types that may have a comma in the type name, as in "System.String [,], mscorlib, ...." - see http://msdn.microsoft.com/en-us/library /yfsftwz6.aspx for details.

It's better here:

 int index = -1; int bcount = 0; for (int i = 0; i < aqtn.Length; ++ i) { if (aqtn[i] == '[') ++bcount; else if (aqtn[i] == ']') --bcount; else if (bcount == 0 && aqtn[i] == ',') { index = i; break; } } string typeName = aqtn.Substring(0, index); var assemblyName = new System.Reflection.AssemblyName(aqtn.Substring(index + 1)); 
+4
source

If you know that the order of information is the same for each input, you can use the string.Split() function, then assign each variable a line at a specific position.

Example:

 string s = "a,as,sd,ad"; string[] data = s.Split(new char[] { ',' }); 

then you are using the liek dataset:

 fullname = data[0].Trim(); ... 
0
source

All Articles