Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all 8156 articles
Browse latest View live

Performance problems when using Entity Framework 6 and SQL Server 2016

$
0
0

I was using VS2015 with EntityFramework 6 for mapping mySQL Server 2012 database. Everything worked fine until upgrade theSQL Server to 2016 version. Now, when I update my database model, Visual Studio crash. Other problem is that sometimes I have that error while running the application:"TCP semaphore timeout period has expired"

Anyone knows issues about compatibility between EF6 and SQLServer 2016?

Thanks,



XmlWriter.WriteAttributeString() not converting to UTF-8

$
0
0

I have the following code to create an XML file. Why is it not doing a UTF-8 conversion on the string passed in?

using System.IO;
using System.Text;
using System.Xml;

namespace TestXmlWriter
{
    class Program
    {
        private static readonly Encoding utf8NoBOM = new UTF8Encoding(false);

        static void Main(string[] args)
        {
            Stream stream = new FileStream("c:\\temp\\test.xml", FileMode.Create, FileAccess.ReadWrite);
            XmlWriter xmlWriter = new XmlTextWriter(stream, utf8NoBOM);
            xmlWriter.WriteStartDocument();

            xmlWriter.WriteStartElement("bear");
            xmlWriter.WriteAttributeString("version", "CONSULTOR_TÉCNICO");

            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();
            xmlWriter.Flush();
            stream.Close();
        }
    }
}

Output:

<?xml version="1.0" encoding="utf-8"?><bear version="CONSULTOR_TÉCNICO" />

What do I have to do to get correct UTF-8 output?

thanks - dave


What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

Windows Media Encoder 9 Series is not available anymore.

Sometimes cannot get a System.DirectoryServices.Protocols.SearchResponse

$
0
0
I am using the System.DirectoryServices.Protocols library to connect to an LDAP source. I have not had any issues with eDirectory, but I am having some trouble with Active Directory.

The Active Directory server is running on a Windows 2003 machine.

Here's a summary of the code I've been using (try catches were removed):
LdapConnection con = new LdapConnection(new LdapDirectoryIdentifier(Server, Port));
con.SessionOptions.SecureSocketLayer = false;
con.Credential = new NetworkCredential(Username, Password);
con.AuthType = AuthType.Basic;
con.Bind();
SearchRequest request = new SearchRequest(DN,FILTER,System.DirectoryServices.Protocols.SearchScope.Subtree);
SearchResponse response = (SearchResponse)con.SendRequest(request); //this is the line that throws a DirectoryOperationException

Here's the stack trace from the exception:
System.DirectoryServices.Protocols.DirectoryOperationException was caught
  Message="An operation error occurred."
  Source="System.DirectoryServices.Protocols"
  StackTrace:
       at System.DirectoryServices.Protocols.LdapConnection.ConstructResponse(Int32 messageId, LdapOperation operation, ResultAll resultType, TimeSpan requestTimeOut, Boolean exceptionOnTimeOut)
       at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request, TimeSpan requestTimeout)
       at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request)
       at <the line that I call from>

Here's the message that was stored in the response of the DirectoryOperationException:
"00000000: LdapErr: DSID-0C090627, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, vece"
I think this error message is a little fishy because when I debug line by line, it successfully passes the con.Bind() line.

Now it continues like this for an hour or so. Afterwards, I am able to authenticate succesfully every time. In summary, it works sometimes. I thought the server might have gone down. However, I can login and browse succesfully using a third party LDAP client. This gives me strong reason to believe that it's not the servers issue, but an issue with my code.

If I am missing any information I will try my best to get it for you as quickly as possible. Thank you in advanced for your help!

Keep it dry, shy and tell the other guy.

HTMLHelp API - ShowHelp does not work properly after installing KB4471329-x64 or KB4462919

$
0
0

Hello,

Not sure what the best forum is for a Win32 API/KB breakage is, but starting here.

Recently KB4471329 was installed on our client computers as part of regular updates and compliance.  When this KB is applied to our computers, it changes the way Help.ShowHelp works.  Previously we were able to call this API in response to an F1 press and ask the API to show a specific CHM book that was part of a larger set of books and display a specific page.  This allowed the software to launch help to a specific page, but allow the user to browse to any other book in our integrated setup.

We use the form:

      Help.ShowHelp(this, @"../../../HelpFiles/Master.chm", @"SiteA.chm::/SiteA.htm");

After install of this KB, the behavior is changed.  The help book is properly launched.  The contents listing (tree view) shows the help topics on the left, but the main view shows a blank page with the following text:

 "This page can’t be displayed.  Make sure the web address //ieframe.dll/dnserrordiagoff.htm# ..."

If we remove the KB from the machine, then F1 works properly again and the content of the page is shown in the right hand view.

We've created a sample program that illustrates this and would like to provide it.  Using it, you can see the effect before and after installing KB4471329.  Your test machine needs to have KB4471329 (or equivalent) installed to see the problem.  Remove it to see the problem undone.  What is the best way to provide the sample?

We are hoping to bring this to the attention of Microsoft so that an updated patch could be created.

We do not see any workaround in the code that we can do to keep the overall integrated book displaying.

Lastly, here is a related posting that seems to point out the same issue:

https://developercommunity.visualstudio.com/content/problem/364201/showhelp-with-double-colon-does-not-workkb4462919.html

Thanks,


Brian R.

How to get a timestamp with microsecond value.

$
0
0

In my C# project, while a UDP packet arriving, I need to log a timestamp with microsecond value.

Below is a sample function to use microsecond timestamp:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace datetimetest
{
    class Program
    {
        static void Main(string[] args)
        {
            for(int i=0;i<10;i++)
            {
                long currentTick = DateTime.Now.Ticks;
                Console.WriteLine("currentTick:{0};  timestamp:{1}", currentTick, new DateTime(currentTick).ToString("HH:mm:ss.ffffff"));
            }
            Console.ReadLine();
        }
    }
}

I got below result:

currentTick:636844467783194613;timestamp:12:06:18.319461
currentTick:636844467783204613;timestamp:12:06:18.320461
currentTick:636844467783214613;timestamp:12:06:18.321461
currentTick:636844467783214613;timestamp:12:06:18.321461
currentTick:636844467783214613;timestamp:12:06:18.321461
currentTick:636844467783214613;timestamp:12:06:18.321461
currentTick:636844467783214613;timestamp:12:06:18.321461
currentTick:636844467783214613;timestamp:12:06:18.321461
currentTick:636844467783214613;timestamp:12:06:18.321461
currentTick:636844467783214613;timestamp:12:06:18.321461

My questions are:

1. On some PCs, the last 4 numbers would never change. In above case, the last 4 numbers are always "4613". Why?

2. Is there any better way to get the timestamp with microsecond value?

Any comments are highly appreciated. 


اقرب توكيل سيمنس البحيرة (01225025360) توكيل صيانة ثلاجات سيمنس(0235695244) الشرقية

الاصلاح الفورى ثلاجات سيلتال ( 0235695244 ) ثلاجات سيلتال ( 01225025360 ) المنوفية


Can we create object of Interface??

$
0
0

Can we create object of interface? like below:

IDemo obj = new IDemo();   

if no, then why not?

Note: I know we can create instance of interface.


Thanks!! http://gurunguns.wordpress.com

Shared projects, recompile for ever ref, or just once?

$
0
0
Just a curious question, if I have a solution with 3 class libraries that refrence one shared project, does the shared project get recompiled each time, so a total of three times, or is it just compiled once and embedded into each other dll.

delete pagedList.mvc package from References

$
0
0

I have deleted PagedList package from References while it is still in Package.config and when I reinstall it it dose not show in References any more

Also I try to restore NUGET package but I don't have the option of Enable Restore NUGET package

What should I do to restore this specific packages

Can we create object of Interface??

$
0
0

Can we create object of interface? like below:

IDemo obj = new IDemo();   

if no, then why not?

Note: I know we can create instance of interface.


Thanks!! http://gurunguns.wordpress.com

الشركه المعتمده لصيانه ثلاجات شارب 01225025360 $$ 01014723434 $$ 0235695244 الشرقية

الشركه المعتمده لصيانه ثلاجات طومسون 01225025360 $$ 01014723434 $$ 0235695244 السويس

Can we create object of Interface??

$
0
0

Can we create object of interface? like below:

IDemo obj = new IDemo();   

if no, then why not?

Note: I know we can create instance of interface.


Thanks!! http://gurunguns.wordpress.com

Shared projects, recompile for ever ref, or just once?

$
0
0
Just a curious question, if I have a solution with 3 class libraries that refrence one shared project, does the shared project get recompiled each time, so a total of three times, or is it just compiled once and embedded into each other dll.

Want to protect worksheet name of excel in C#.net

$
0
0
I am using below code and want to protect worksheet Name , I have locked and unlocked some cells with certain range but not able to lock worksheet name

Maniging OCSP requests and responces with .NET only

$
0
0

Hi.

 

I've researching info on how to create a valid OCSP Request, and parsing it's corresponding OCSP Response. But so far, all I've been able to find is the use of 3rd party Tools like openSSL and certutil, or APIs like Bouncy Castle or PSPKI Module. I cannot use anything that it's not absolutely free (no OpenSource licensing). Just pure code.

 

I'm trying to see if I can construct the HTTP URL required for that; but it's been difficult to find any good sample.

 

Is there any good .NET sample or library available that could provide some guidance?

 

Thank you.

loss some data when send and recieve data using udp C#

$
0
0

Hello everyone

i don't know if this forum is right place to write my question or not.

i create app on my pc to send and receive data using udp protocol. i use code to monitor data recieving on my server and i found some data lossing when sending from my pc.

I'm trying to solve this issue for long time but i fall

my pc internet connection is fiper optic

Can anyone help me to fix this problem and save my time, please?
these are codes that i use on my pc

code of sending:

        public async Task LinesAsPara(LineCollection Lines)
        {
            CancelTask = false;
            taskToken = new CancellationTokenSource();
            CancellationToken ct = taskToken.Token;

            if (Monitor.IsEntered(syncObj))
            {
                paused = false;
                Monitor.Exit(syncObj);
            }

            WatchTest.Start();

            Task task = new Task(() => {
                foreach (var Oneline in ltlTextArea.TextArea.Lines)
                {

                    try
                    {

                        CheckForIllegalCrossThreadCalls = false;

                        string pattern = @"(?:CACHE PEER|cache peer):\s*(\S+)+\s+(\d*)";

                        foreach (Match m in Regex.Matches(Oneline.Text, pattern))
                        {
                            Server = Dns.GetHostAddresses(m.Groups[1].Value)[0];
                            RemotePort = Convert.ToInt32(m.Groups[2].Value);
                            CachePeer = m.Groups[0].Value;
                        }

                        IPEndPoint ipeSender = new IPEndPoint(Server, RemotePort);
                        //The epSender identifies the incoming clients
                        EndPoint epSender = (EndPoint)ipeSender;

                        int ID = 0;
                        byte[] buf = new byte[32];
                        buf[0] = TYPE_PINGREQ;

                        // Self Program Use
                        buf[1] = 0x4D;
                        buf[2] = 0x43;
                        buf[3] = 0; // ping packet number
                        buf[4] = (byte)(Oneline.Index >> 8);
                        buf[5] = (byte)(Oneline.Index & 0xff);
                        // Multics Identification
                        buf[6] = (byte)ID; // unused must be zero (for next use)
                        buf[7] = (byte)('M' ^ buf[1] ^ buf[2] ^ buf[3] ^ buf[4] ^ buf[5] ^ buf[6]); // Multics Checksum
                        buf[8] = (byte)'M'; // Multics ID
                                            //Port
                        buf[9] = 0;
                        buf[10] = 0;
                        buf[11] = (byte)((int)CachePort.Value >> 8);
                        buf[12] = (byte)((int)CachePort.Value & 0xff);
                        //Program
                        buf[13] = 0x01; //ID
                        buf[14] = 7; //LEN
                        buf[15] = (byte)'M';
                        buf[16] = (byte)'u';
                        buf[17] = (byte)'l';
                        buf[18] = (byte)'t';
                        buf[19] = (byte)'i';
                        buf[20] = (byte)'C';
                        buf[21] = (byte)'S';
                        //Version
                        buf[22] = 0x02; //ID
                                        //	if (REVISION<100) {
                        buf[23] = 3; //LEN
                        buf[24] = (byte)'r';
                        int REVISION = 81;
                        buf[25] = (byte)('0' + (REVISION / 10));
                        buf[26] = (byte)('0' + (REVISION % 10));



                        MainCSP CSPPeer = new MainCSP
                        {
                            //CachePort = (int)CachePort.Value,
                            MSec = Oneline.Index,
                            CachePeer = CachePeer
                        };
                        PeerList.Add(CSPPeer);

                        serverSocket.BeginSendTo(buf, 0, buf.Length, SocketFlags.None, epSender, new AsyncCallback(OnSend), null);
                        sendDone.WaitOne();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "SGSServerUDP1",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                }

            });
            task.Start();

            WatchTest.Stop();
            ShowWatch.Stop();
            StopwatchBut.Text = string.Format("{0}D {1}h : {2}m : {3}.{4}s", WatchTest.Elapsed.Days, WatchTest.Elapsed.Hours, WatchTest.Elapsed.Minutes, WatchTest.Elapsed.Seconds, WatchTest.Elapsed.Milliseconds);
            Form1.IsVoice = SpeakerSwitch.Value;
            VoiceButtonItem.PerformClick();
            DesktopAlert.Show();
            DesktopAlert.CaptionText = string.Format("Lines Tester (ID:{0})", Form1.SessionID);
            DesktopAlert.ContentText = string.Format("The test is completed." + Environment.NewLine + "||Working({0})||Syntax({1})||Other({2})||", WorkBtn.Counter.Text, SyntaxBtn.Counter.Text, OtherBtn.Counter.Text);
            ltlStartButton.Enabled = true;
        }

        public void OnSend(IAsyncResult ar)
        {

            try
            {

                serverSocket.EndSend(ar);
                sendDone.Set();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SGSServerUDP2", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

code of recieving:

        void Receive()
        {

            try
            {
                CheckForIllegalCrossThreadCalls = false;

                //We are using UDP sockets
                serverSocket = new Socket(AddressFamily.InterNetwork,
                    SocketType.Dgram, ProtocolType.Udp);

                //Assign the any IP of the machine and listen on port number 1000
                IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, (int)CachePort.Value);

                //Bind this address to the server
                serverSocket.Bind(ipEndPoint);

                IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0);
                //The epSender identifies the incoming clients
                EndPoint epSender = (EndPoint)ipeSender;

                //Start receiving data
                serverSocket.BeginReceiveFrom(byteData, 0, byteData.Length,
                    SocketFlags.None, ref epSender, new AsyncCallback(OnReceive), epSender);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SGSServerUDP3",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0);
                EndPoint epSender = (EndPoint)ipeSender;

                serverSocket.EndReceiveFrom(ar, ref epSender);

                const int TYPE_PINGRPL = 4;
                switch (byteData[0])
                {
                    case TYPE_PINGRPL:
                        int result = PeerList.FindIndex(x => x.MSec == ((byteData[4] << 8) | byteData[5]));
                        if (result != -1)
                        {
                            WorkBtn.AddData(PeerList[result].CachePeer + "(" + ((byteData[4] << 8) | byteData[5]) + ")" + Environment.NewLine);
                            DesktopAlert.ContentText = string.Format("The test is completed." + Environment.NewLine + "||Working({0})||Syntax({1})||Other({2})||", WorkBtn.Counter.Text, SyntaxBtn.Counter.Text, OtherBtn.Counter.Text);
                            PeerList.RemoveAt(result);
                        }
                        break;
                }
                serverSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref epSender, new AsyncCallback(OnReceive), epSender);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SGSServerUDP4", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

Thank you


Two factor authentication with device secret?

$
0
0

Hi,

we use two factor authentication to access Project Online PWA.

We are looking to interrogate/integrate the PWA data with a service call.

Is there a way of creating a 'device secret' and implement it into c# code, callable from a service?

Thanks

Stew

Viewing all 8156 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>