c# - "Value cannot be null.\r\nParameter name: typeName" when receiving queue messages -
i have error above
"value cannot null.\r\nparameter name: typename"
this stack trace:
> " @ system.runtimetype.gettype(string typename, boolean throwonerror, boolean ignorecase, boolean reflectiononly, > stackcrawlmark& stackmark)\r\n @ system.type.gettype(string > typename, boolean throwonerror)\r\n @ > x.queuehelper.getbody[t](brokeredmessage brokeredmessage)\r\n @ > x.queuehelper.<>c.<receivemessage>b__3_0(brokeredmessage message)"
the code have follows
i send message without exceptions(this controller action)
[httppost] [validateantiforgerytoken] public actionresult create([bind(include="id,nombre,nit,nombrerepresentantelegal,telefonorepresentantelegal,nombrecontacto,telefonocontacto,propiedadesextra")] empresa empresa) { if (modelstate.isvalid) { var propiedadeslist = formvalues in request.form.todictionary() join propiedades in unitofwork.propiedadrepository.get() on formvalues.key equals propiedades.nombre propiedades.entidad.nombre == "empresa" select new { clave = formvalues.key, valor = formvalues.value }; xelement el = new xelement("root",propiedadeslist.select(kv => new xelement(kv.clave, kv.valor))); empresa.propiedadesextra = el.tostring(); queuehelper.sendmessage("empresa", empresa, queueconnectionstring); //unitofwork.empresarepository.insert(empresa); //unitofwork.save(); return redirecttoaction("index"); } return view(empresa); }
the sendmessage this:
public static void sendmessage<t>(string queuname, t objeto, string connectionstring) { queueclient client =queueclient.createfromconnectionstring(connectionstring, "empresa"); brokeredmessage message = new brokeredmessage(objeto); message.contenttype = objeto.gettype().name; client.send(new brokeredmessage(message)); }
then on console application want receive messages process them.
so have this:
static void main(string[] args) { try { string connectionstring = cloudconfigurationmanager.getsetting("microsoft.servicebus.connectionstring"); console.writeline("press key continue"); console.readkey(); queuehelper.receivemessage("empresa", connectionstring); } catch (exception ex) { throw ex; } }
and this:
public static void receivemessage(string queuname, string connectionstring) { queueclient client = queueclient.createfromconnectionstring(connectionstring, "empresa"); // configure callback options onmessageoptions options = new onmessageoptions(); options.autocomplete = false; options.autorenewtimeout = timespan.fromminutes(1); // callback handle received messages client.onmessage((message) => { try { empresa empresa = getbody<empresa>(message); // process message queue //console.writeline("body: " + ); console.writeline("messageid: " + message.messageid); // remove message queue message.complete(); } catch (exception ex) { // indicates problem, unlock message in queue message.abandon(); } }, options); }
and getbody method
public static t getbody<t>(brokeredmessage brokeredmessage) { var ct = brokeredmessage.contenttype; type bodytype = type.gettype(ct, true); var stream = brokeredmessage.getbody<stream>(); datacontractserializer serializer = new datacontractserializer(bodytype); xmldictionaryreader reader = xmldictionaryreader.createbinaryreader(stream, xmldictionaryreaderquotas.max); object deserializedbody = serializer.readobject(reader); t msgbase = (t)deserializedbody; return msgbase; }
apparently problem in line:
type bodytype = type.gettype(ct, true);
Comments
Post a Comment