Is it possible to compile a WDK driver with .net native?

As far as you know did anyone ever tried building a windows driver using C# and compiling it in .net native?

It’s been a couple of stressing day working on a C driver using WDK, and i really wondered: why not C++ ? and i found out it could actually be done with some precautions.

And now i’m raising the bar: .net native, why not ? (or maybe some C# transpiler if any reliable exist) i could not find any attempt at this…

but sound reasonable…

Is it feasible to develop SMS and IVR system platform using .net MVC?

I am working for a Non-Profit Organisation Sangath,Goa. For our Project ToQuitToQuit aims to develop and then preliminarily evaluate, a contextually appropriate intervention, that can be delivered using mobile text messaging to large numbers of tobacco users, quickly and at low cost.

To deliver this intervention we have planned to develop SMS and IVR system internally only for Sangath which can be use by various projects in future.

I have past experience in software development. I am good in .net MVC, SQL and learning Angular2+4&5.

I am trying to collect some information prior to start developing IVR and SMS systems platform. Is it a good idea to go with .net MVC, SQL Server and Angular? How to begin with? What all steps should I follow?

Any help/information would be appreciated.

I have Visual Studio 2019 and have installed all the developer kits/targeting frameworks looking to use .Net 4.6.1 but have issues

I have Visual Studio 2019 and have installed all the developer kits/targeting frameworks looking to use .Net 4.6.1 for entity framework 6.2.0 but when I go to the project properties I do not see anything besides .Net Core 2.2 in the targeting frameworks? I could use some help figuring out what I am doing wrong.

Visual Studio 2019

ayuda !! cuestionario en .NET

Estoy desarrollando un cuestionario en .net teniendo conexion con sql server. El problema radica en el formulario estudiante. Selecciona un cuestionario en un comboBox y solo muestra la primera pregunta del cuestionario y luego muestra las otras preguntas cargadas en la bd, es decir en el orden en que se encuentran.

METODO VER_PREGUNTA

Dim query As String = "SELECT * FROM PREGUNTAS INNER JOIN CUESTIONARIO ON  PREGUNTAS.ID_CUESTIONARIO = CUESTIONARIO.ID_CUESTIONARIO WHERE PREGUNTAS.ID_CUESTIONARIO = " & ComboBox1.SelectedValue & "" Dim comando As New SqlCommand(query, conex) Dim pueb As New SqlDataAdapter(comando) datos = New DataSet pueb.Fill(datos, "PREGUNTAS") PREGUNTALabel1.Text = datos.Tables("PREGUNTAS").Rows(0).Item("PREGUNTA").ToString 

CONDICIONES EN EL BOTON

Dim query As String = "SELECT * FROM CUESTIONARIO INNER JOIN PREGUNTAS ON PREGUNTAS.ID_CUESTIONARIO= CUESTIONARIO.ID_CUESTIONARIO WHERE PREGUNTAS.ID_CUESTIONARIO= " & ComboBox1.SelectedValue & "" Dim comando As New SqlCommand(query, conex) Dim pueb As New SqlDataAdapter(comando) MsgBox(query) datos = New DataSet pueb.Fill(datos, "RESPUESTA") If ComboBox1.SelectedValue = 1 Then     Call ver_pre()     Call ver_res()  End If If ComboBox1.SelectedValue = 2 Then     Call ver_pre()     Call ver_res() End If 

RadioButtonsList dentro de un updatepanel no trae el valor chequeado .NET

Tengo un radio button list (el cual cargo por un databind) dentro de un update panel en modo async.

El tema es cuando quiero leer el valor chequeado, ya que no lo trae una vez disparado el trigger… Viendo el control, noto que los valores llegan bien, con lo cual supongo que ningún postback los está vaciando, pero así y todo no logro hacer que devuelva el valor chequeado..

El form

    <div class="form-group">         <div class="col-sm-12">             <div class="row">                 <a class="menu-trigger" href="javascript:ocultar()" style="display: block; position: fixed; align-self: auto; text-align: right">Cerrar</a>                 <br />                 <br />                 <asp:ScriptManager ID="scrEncuesta" AjaxFrameworkMode="Enabled" runat="server" />                 <asp:UpdatePanel ID="pnEncuesta" runat="server">                     <Triggers>                         <asp:AsyncPostBackTrigger ControlID="btEncuesta" />                     </Triggers>                     <ContentTemplate>                         <div class="box">                             <asp:Label ID="lbEncuesta" Text="" runat="server" />                             <div class="box-body">                                 <div class="form-group">                                     <asp:RadioButtonList ID="rdl1" runat="server" AutoPostBack="false">                                     </asp:RadioButtonList>                                 </div>                                 <div class="form-group">                                     <asp:LinkButton ID="btEncuesta" Text="Votar" CssClass="" runat="server" />                                 </div>                             </div>                         </div>                      </ContentTemplate>                  </asp:UpdatePanel>              </div>         </div> 

el trigger en el CB

Protected Sub btEncuesta_Click(sender As Object, e As EventArgs) Handles btEncuesta.Click      Dim m As String      m = CStr(rdl1.SelectedValue) <-- llega completo sin el item que está seleccionado  End Sub 

Alguna idea del porqué?

Gracias!

como puedo pasar una lista de objetos a un for en .Net C#

Hola muy buen dia Comunidad Stack Overflow

como puedo pasar estas listas de objetos que traen información a un for e ir barriendo la información de acuerdo al tamaño del listado e irlo asignando a cada una de las variables

Codigo de Listas

//Obtener ID's correspondientes    listaIDS=buscaId(listaTrafico,trafico, operadores, monedas, lineaNegocio);   //Asigna los Id a los elementos de la lista listaTrafico=validaAsignaDatos(listaTrafico,listaIDS, arrOperador, arrMoneda, arrTrafico, listaErrores); 

o si existe otra alternativa de hacerlo ya se empleando otro método u arreglo muchas gracias por su tiempo Comunidad

Simple .NET encryption for a beginner who wants to secure information at rest in app.config and in memory

I’m a reasonably competent developer who is happy to admit I’m a complete beginner when it comes to encryption (specifically .NET / C#). I have an application which holds some AWS credentials (access and secret key in an application configuration file (app.config). I have to do this as the machine the app runs on is not a VM, it’s a physical machine outside AWS, so it must have an IAM user with an access and secret key in order to authenticate. Initially I had just stored the credentials in the app.config file and used SecureString to encrypt at rest. The problem is, in order to use the credentials I must decrypt them in memory to a normal string. Even though I’m a complete dummy when it comes to hacking/encryption I believe this is an issue because as soon as the secure string is turned into a string, it’s in plain text in memory which means an attacker could somehow peek at the data and get the credentials.

So I want a better method to protect the credentials both at rest, and possibly while being used in memory. The AWS credentials object will only take plain strings as the access and secret key, so I guess at some point I have to decrypt them, but is there any better way / method to protect these values at rest and/or in memory?

I know there are a wealth of encryption libraries, but they are very imposing for a beginner who isn’t super familiar with salts/hashes and all that. Does anyone know of a good step by step easy to understand tutorial and/or library/plug in I can use to offer better protection? It’s hard to assess one library or technique versus any other when you don’t know the jargon. All I know is that AES-256 is probably the right ‘level’ of protection needed.

I have found lots of libraries and tutorials, but many of them assume a certain level of knowledge around encryption. I’m happy to learn, but I need some pointers and tips on how to get started, or a library that might abstract some of the heavy lifting. I dont’ want to roll my own thing here, I want to use something established. But my limited understanding means I can’t get my head around how secure using encryption of any kind would be, as I guess I’d have to – at some point – store some kind of key somewhere in the file system that could be found and used to decrypt the data.

Assistance appreciated, and please be gentle – as I said I’m a beginner here, and am happy to admit my ignorance in the hopes that people can suggest helpful solutions 🙂

What are some good performance patterns in .net core?

I’ve read through this article: https://docs.microsoft.com/en-us/aspnet/core/performance/performance-best-practices?view=aspnetcore-2.2 and I’m interested in learning more. The stuff that’s listed here is pretty generic, so I’m looking for specific coding patterns which we can implement in our codebase to be more performant.

Some simple (not necessarily correct) examples:

  • Use IEnumerable instead of List
  • Don’t parse Enums to strings.

Convert between .NET decimal and Java BigDecimal

Background

In many languages we have built-in data types for representing decimal floating point numbers. In .NET that’s decimal, and in Java we have BigDecimal.

Now these are fundamentally different types. The .NET decimal is a fixed size value type, so its representable range and precision are limited (±1.0 x 10^(-28) to ±7.9228 x 10^28).

On the other hand, the Java BigDecimal is arbitrary range and precision. Due to this it’s not fixed size, but the length of its internal byte array depends on the size and precision of the represented number.

Due to this it’s impossible to implement guaranteed lossless conversion between these two types (it’s possible in the .NET->Java direction, but not the other way around).

What I want to implement is a “best effort” conversion, which throws an exception if the Java BigDecimal doesn’t fit into a .NET decimal.

Requirements

The language is Java.
I have the following type, which models the internal representation of a .NET decimal.

public class DotNetDecimal {     public final int mantissaLsb;      public final long mantissaMsb;      public final int exponentAndSign;      public DotNetDecimal(int mantissaLsb, long mantissaMsb, int exponentAndSign) {         this.mantissaLsb = mantissaLsb;         this.mantissaMsb = mantissaMsb;         this.exponentAndSign = exponentAndSign;     } } 

This is based on a suggestion for a Protobuf representation (which is also the motivation for this whole conversion story) described here.

What I’d like to have is a class with the following signature.

public class DecimalHelper {     public static BigDecimal fromDotNetDecimal(DotNetDecimal value) {         ...     }      public static DotNetDecimal toDotNetDecimal(BigDecimal value) throws Exception {         ...     } } 

And the requirements are the following.

  • fromDotNetDecimal should convert to a BigDecimal, which is always possible, and it’s implementation is relatively straightforward.
  • toDotNetDecimal is trickier, we have the following cases:
    • If value can be exactly represented as a .NET decimal, then convert it.
    • If value is in the range of what a .NET decimal can represent, but its fractional part has more digits (too high precision), then convert it, and round it so that it fits into a .NET decimal. This is where we lose precision.
    • If value is out of the range of what a .NET decimal can represent, then all bets are off, throw an exception.

Implementation

This is my implementation, with a fare amount of comments.

public class DecimalHelper {     public static final BigDecimal minValue;     public static final BigDecimal maxValue;      static {         minValue = new BigDecimal(BigInteger.valueOf(0xffffffffL).shiftLeft(32).add(BigInteger.valueOf(0xffffffffL))                 .shiftLeft(32).add(BigInteger.valueOf(0xffffffffL)).negate());         maxValue = new BigDecimal(BigInteger.valueOf(0xffffffffL).shiftLeft(32).add(BigInteger.valueOf(0xffffffffL))                 .shiftLeft(32).add(BigInteger.valueOf(0xffffffffL)));     }      public static BigDecimal fromDotNetDecimal(DotNetDecimal value) {         long mantissaMsbUpper = value.mantissaMsb >>> 32;         long mantissaMsbLower = value.mantissaMsb & 0xffffffffL;         BigInteger integer = BigInteger.valueOf(mantissaMsbUpper).shiftLeft(32)                 .add(BigInteger.valueOf(mantissaMsbLower)).shiftLeft(32)                 .add(BigInteger.valueOf(value.mantissaLsb & 0xffffffffL));          BigDecimal decimal = new BigDecimal(integer, (value.exponentAndSign & 0xff0000) >> 16);         if (value.exponentAndSign < 0) {             decimal = decimal.negate();         }          return decimal;     }      public static DotNetDecimal toDotNetDecimal(BigDecimal value) throws Exception {         if (value.compareTo(minValue) < 0) {             throw new Exception("Input number is out of range.");         }          if (value.compareTo(maxValue) > 0) {             throw new Exception("Input number is out of range.");         }          // The largest representable number with DotNetDecimal has 29 decimal digits.         if (value.precision() > 29) {             // If the precision of the BigDecimal is more than 29, we have to decrease it to             // 29, and do rounding. With this we're losing some precision, but this only             // happens to either very large numbers, or numbers with a lot of fraction digits.             // In this case it's certainly not a round number, otherwise the previous range             // checks would've failed.             // This call will remove (with rounding) as many digits from the fractional             // parts as needed to make the total number of digits 29.             value = value.setScale(value.scale() - (value.precision() - 29), BigDecimal.ROUND_HALF_UP);         }          // The representation of the mantissa in DotNetDecimal has 96 bits, so we cannot         // represent more.         if (value.unscaledValue().bitLength() > 96) {             // Even if we're inside the range of the min and max DotNetDecimal, and we don't             // have more than 29 decimal digits, it might be that the unscaled value is             // still more than 96 bits, which can not be represented with a DotNetDecimal.             // This is the case for a number like 9.9999999999999999999999999999 (exactly 29             // digits).             // In this case, we decrease the scale with one more.             value = value.setScale(value.scale() - 1, BigDecimal.ROUND_HALF_EVEN);         }          // At this point we know that value is in the range of what DotNetDecimal can         // represent, with the same precision, so the last thing to do is to transform         // to the representation.         boolean isNegative = value.compareTo(BigDecimal.valueOf(0)) < 0;         if (value.scale() >= 0) {             // In this case the unscaled value is the mantissa, and the scale and the sign             // has to go into the exponent_and_sign.              // For simplicity, we negate the number if it's negative.             if (isNegative) {                 value = value.negate();             }              var bytes = value.unscaledValue().toByteArray();              long msb = unscaledBytesToMsb(bytes);              int lsb = unscaledBytesToLsb(bytes);              int exponentAndSign = value.scale() << 16;              if (isNegative) {                 // We have to set the first (MSB) bit to 1.                 exponentAndSign = exponentAndSign | 0x80000000;             }              return new DotNetDecimal(lsb, msb, exponentAndSign);         } else {             // In this case the unscaled value is not the real mantissa, we have to scale it             // up, and the exponent will be zero.             if (isNegative) {                 value = value.negate();             }              // We create a new BigInteger by multiplying the original number by ten to the             // power of the negation of the scale.             var scaledUp = value.unscaledValue().multiply(BigInteger.valueOf(10).pow(-value.scale()));              var bytes = scaledUp.toByteArray();              long msb = unscaledBytesToMsb(bytes);              int lsb = unscaledBytesToLsb(bytes);              // Since scale() is negative, we know it's a round number, so the exponent is 0.             int exponentAndSign = 0;              if (isNegative) {                 // We have to set the first (MSB) bit to 1.                 exponentAndSign = exponentAndSign | 0x80000000;             }              return new DotNetDecimal(lsb, msb, exponentAndSign);         }     }      // NOTE: When we build the mantissa MSB and the LSB, before bitwise ORing the     // byte to the accumulator in every iteration,     // we need to interpret the byte as an unsigned number.     // So instead of simply doing (msb | bytes[i]), we do (msb | ((long)bytes[i] & 0xFF))     // Otherwise the byte would be automatically casted to a long, and interpreted     // as a negative number, so all its higher bits would be set to 1.     private static int unscaledBytesToLsb(byte[] bytes) {         var bytesLength = bytes.length;          // If the first byte in the array is 0, then it was included only for the sign         // bit, we have to ignore it.         int startIndex = bytes[0] == 0 ? 1 : 0;          int lsb = 0;         int j = 0;         // Convert the LSB part:         for (int i = bytesLength - 1; i >= startIndex && i >= bytesLength - 4; i--) {             lsb = lsb | ((int) bytes[i] & 0xFF) << (j * 8);             j++;         }          return lsb;     }      private static long unscaledBytesToMsb(byte[] bytes) {         var bytesLength = bytes.length;          // If the first byte in the array is 0, then it was included only for the sign         // bit, we have to ignore it.         int startIndex = bytes[0] == 0 ? 1 : 0;          long msb = 0;         int j = 0;         // Convert the MSB part:         for (int i = bytesLength - 5; i >= startIndex; i--) {             msb = msb | ((long) bytes[i] & 0xFF) << (j * 8);             j++;         }          return msb;     } } 

(The fromDotNetDecimal implementation is based on this answer.)

I’m pretty confident the implementation is mostly correct, because I tested it with a wide range of inputs. I know the code is probably rather naive in terms of optimizations, but I’m not worried about perf too much.

What I’d be interested in is any suggestions/mistakes you can see in terms of the correctness of the code, if you can think of any edge case that’s not correctly covered.

Авторизация через Cookies в ASP .NET Core MVC

Авторизация работает только по протоколу HTTPS.

В конфигурации сервисов

services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => //CookieAuthenticationOptions     {         options.LoginPath = new PathString("/Account/Login");     }); 

В конвейере

app.UseAuthentication(); 

Метод, через который проходит авторизация после проверки пользователя

    private async Task Authenticate(string userName)     {         var claims = new List<Claim>         {             new Claim(ClaimsIdentity.DefaultNameClaimType, userName)         };         var id = new ClaimsIdentity(claims, "ApplicationCookie", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);         await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(id));     } 

Если в свойствах отладки включаю SSL, то авторизация работает, иначе после SignInAsync я попадаю снова на страницу логина (в этот момент HttpContext.User.Identity.IsAuthenticated == false)

при публикации на локальном IIS то же самое. Работает только через HTTPS.