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

In .net 4.5 System.Uri can't decode %2C ?

$
0
0
String url = new Uri(@"http://test.com/%2c").ToString();

In .net 4.5 and .net 4.5.1, it still output 'http://test.com/%2c'.

But in .net 4 it will output 'http://test.com/,'.


How can I create a System.Diagnostics.Process that uses the LOGON_NETCREDENTIALS_ONLY flag?

$
0
0

I am writing a program that spawns child processes and those child processes need to use a credential that is not local on the machine when accessing network resources I need to spawn those processes with the LOGON_NETCREDENTIALS_ONLY flag. I want to use the System.Diagnostics.Process library since I already have a huge investment into it and it's wired up with intercepted IO. Is there any way I can tell Process internally to use the LOGON_NETCREDENTIALS_ONLY flag when calling CreateProcessWithLogonW when credentials are provided? Since the account does not exist locally on the box I will get access denied without the flag in play. I've looked everywhere and the only solution I've found is to implement CreateProcessWithLogonW which means I have to also interop all of the stream interaction code and everything else already wired to the Process object and I would like to avoid that if it at all possible. Even if there is a way to inherit Process and add the flag that way I could go that route, I just need advise.

Thanks,

Jerry


Dev

Unity Interception

$
0
0

I am using Unity Interception to handle logging.  I would like to use the IMethodInvocation target property, but it causing a stackoverflow exception.  It seems that by referencing this property, it is intercepted again.

How can I prevent this? 

I am able to reference other properties, such as MethodBase without this behavior. 

Any Ideas?

public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
        if (_log_Debug)
       {
           // this line is not intercepted
          var y = input.MethodBase;
   
           // the line below is intercepted again...
            var x = input.Target;
         }
    ...

Bill Behning

System.Security.Cryptography.CryptographicException: Access denied when trying to call System.Security.Cryptography.Pkcs.EnvelopedCms.DecryptContent

$
0
0
I am writing a simple example code to demonstrate how encryption and decryption with the X509 certificates works.

		public static byte[] Encrypt(byte[] content, X509Certificate2Collection encryptingCertificates)
		{
			if (content == null)
			{
				throw new ApplicationException("NullContent");
			}
			if (encryptingCertificates == null || encryptingCertificates.Count == 0)
			{
				throw new ApplicationException("NoCertificates");
			}

			CmsRecipientCollection recipients = new CmsRecipientCollection(SubjectIdentifierType.IssuerAndSerialNumber, encryptingCertificates);
			EnvelopedCms dataEnvelope = new EnvelopedCms(new ContentInfo(new Oid("1.2.840.113549.1.7.1"), content), new AlgorithmIdentifier(new Oid("2.16.840.1.101.3.4.1.2")));
			dataEnvelope.Encrypt(recipients);

			return dataEnvelope.Encode();
		}

		public static byte[] Decrypt(byte[] encryptedContent, X509Certificate2Collection decryptingCertificates)
		{
			if (decryptingCertificates == null || decryptingCertificates.Count == 0)
			{
				throw new ApplicationException("NoCertificates");
			}

			EnvelopedCms dataEnvelope = new EnvelopedCms();

			dataEnvelope.Decode(encryptedContent);
			dataEnvelope.Decrypt(decryptingCertificates);

			ContentInfo contentInfo = dataEnvelope.ContentInfo;

			return contentInfo.Content;
		}



And i have encountered with a problem - the code which have to decrypt (dataEnvelope.Decrypt(decryptingCertificates)) throw CryptographicException: Access denied.

    CryptographicException: Access denied.
       at System.Security.Cryptography.Pkcs.EnvelopedCms.DecryptContent(RecipientInfoCollection recipientInfos, X509Certificate2Collection extraStore)
       at CertificateTestingTool.CertificateResolver.Decrypt(Byte[] encryptedContent, X509Certificate2Collection decryptingCerti
    ficates)
       at CertificateTestingTool.Program.Main(String[] args)

It happens on the windows server 2012 and windows 8.
I have checked this code on the win server 2008 and win 7 it works fine.

Additional information: I don’t use PKI, I import *.pfx file with the private key from a folder (X509Certificate2Collection.Import(…)) and it have imported successfully.

		public static X509Certificate2Collection GetCertificates(string certPath, string password)
		{
			X509Certificate2Collection certs = null;
			var logger = Log.Logger;
			certs = new X509Certificate2Collection();
			certs.Clear();
			var flags = X509KeyStorageFlags.DefaultKeySet;
			certs.Import(certPath, password, flags);

			return certs;
		}


Could anybody help me with this? As I understand some permission rules were introduced at the new OS version.



OracleDataReader returns more rows than the same query in SQL Plus

$
0
0

We've run into a weird problem where a query executed using OracleCommand returns more (duplicate) rows than the exact same query executed in SQL Plus.

More specifically the query in SQL Plus returns 9 rows while the query using OracleCommand.ExecuteReader() returns 12 rows. The additional rows are duplicates of 3 of the 9 previous rows. The result set is the same each time.

It's a simple select on one table with filtering on three of the columns. This problem has occured with two of our customers and we've not been able to replicate them in our testing environment.

Anyone experienced this problem?

Kind regards,

Christoffer


sporadic error security token could not be authenticated or authorized for webservvice call

$
0
0

We are getting sporadic errors  saying below stack trace from app logs, the same web service are used by many vendors and  It gives proper responses for most of the times, but when some client  call the WS repeatedly It gives below error after some time and after within seconds the next call get successfull results

Pleas let me know what would be the exact cause

MESSAGE1: The security token could not be authenticated or authorized
STACKTRACE1:    at Microsoft.Web.Services3.Security.Tokens.SecurityTokenManager.LoadXmlSecurityToken(XmlElement element)
   at Microsoft.Web.Services3.Security.Tokens.SecurityTokenManager.GetTokenFromXml(XmlElement element)
   at Microsoft.Web.Services3.Security.Security.LoadToken(XmlElement element, SecurityConfiguration configuration, Int32& tokenCount)
   at Microsoft.Web.Services3.Security.Security.LoadXml(XmlElement element)
   at Microsoft.Web.Services3.Security.Security.CreateFrom(SoapEnvelope envelope, String localActor, String serviceActor)
   at Microsoft.Web.Services3.Security.ReceiveSecurityFilter.ProcessMessage(SoapEnvelope envelope)
   at Microsoft.Web.Services3.Pipeline.ProcessInputMessage(SoapEnvelope envelope)
   at Microsoft.Web.Services3.WseProtocol.FilterRequest(SoapEnvelope requestEnvelope)
   at Microsoft.Web.Services3.WseProtocol.RouteRequest(SoapServerMessage message)
   at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

"ASN1 bad tag value met" when using SignedCms Decode method

$
0
0
I get an "ASN1 bad tag value met" exception when trying to read a file containing the following PKCS7 message. I can open the file in windows fine. It is basically a chain of certificates.

Anybody know why this happens.


Thanks,

-Jalil

Here is my code:

               SignedCms cms = new SignedCms();
               
                TextReader tr = new StreamReader("./certs.p7b");
                string certs = tr.ReadToEnd();
                tr.Close();
                System.Text.ASCIIEncoding  encoding=new System.Text.ASCIIEncoding();
                byte[] b = encoding.GetBytes (certs);
              
               
                cms.Decode(b);


Here is the content of the file:


-----BEGIN PKCS #7 SIGNED DATA-----
MIIG1wYJKoZIhvcNAQcCoIIGyDCCBsQCAQExADALBgkqhkiG9w0BBwGgggasMIID
fTCCAuagAwIBAgIQM/bzB5+tBYdQytfmiJgEEzANBgkqhkiG9w0BAQUFADCBzjEL
MAkGA1UEBhMCWkExFTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2Fw
ZSBUb3duMR0wGwYDVQQKExRUaGF3dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UECxMf
Q2VydGlmaWNhdGlvbiBTZXJ2aWNlcyBEaXZpc2lvbjEhMB8GA1UEAxMYVGhhd3Rl
IFByZW1pdW0gU2VydmVyIENBMSgwJgYJKoZIhvcNAQkBFhlwcmVtaXVtLXNlcnZl
ckB0aGF3dGUuY29tMB4XDTA4MTExMTIyNDYxM1oXDTA5MTExMTIyNDYxM1owgYEx
CzAJBgNVBAYTAlVTMRcwFQYDVQQIEw5Ob3J0aCBDYXJvbGluYTEQMA4GA1UEBxMH
UmFsZWlnaDEgMB4GA1UEChMXQUNNRSBJbnRlcm5hdGlvbmFsIEluYy4xDTALBgNV
BAsTBFRlc3QxFjAUBgNVBAMTDTEyNDguYWNtZS5jb20wgZ8wDQYJKoZIhvcNAQEB
BQADgY0AMIGJAoGBAM4iIeAvl0Na0CuLq8bAipbL2pP1uNwDxuOVaKUuG+bcVrmk
o2AhqddPP5KAIZl9ctUZDI9Zxs4TVt3GYl2nojiy7pYLyiGtclG7MWPm1iASJhsM
rSMZi1sThpZTd2rSQoRx5oBJsZ779yHkcn9wngnO82b3uc0zn8YxRQPKv+nzAgMB
AAGjgaYwgaMwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMEAGA1UdHwQ5
MDcwNaAzoDGGL2h0dHA6Ly9jcmwudGhhd3RlLmNvbS9UaGF3dGVQcmVt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46+GjZ4X9560ZXUCTe/LCaIhUdib0GfQug2SBhRz1JPLlyoAnFxODLz6
FVL88kRu2hFKbgifLy3j+ao6hnO2RlNYyIkFvYMRuHM/qgeN9EJN50CdHDcCAwEA
AaMTMBEwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQQFAAOBgQAmSCwWwlj6
6BZ0DKqqX1Q/8tfJeGBeXm43YyJ3Nn6yF8Q0ufUIhfzJATj/Tb7yFkJD57taRvvB
xhEf8UqwKEbJw8RCfbz6q1lu1bdRiBHjpIUZa4JMpAwSremkrj/xw0llmozFyD4l
t5SZu5IycQfwhl7tUCemDaYj+bvLpgcUQjEA
-----END PKCS #7 SIGNED DATA-----

Decommisioning a .Net application

$
0
0
Has anyone decommisioned a .Net application? What else do I need to look for in the app other than any external interfaces, dependencies, shared libraries etc while I'm decommisioning a .Net application? Are there any tools available to do such analysis?

when does a datacontext instance close?

$
0
0

Hi,


Im using .Net Framework 3.0.

I have a SupplierApproveDataContext that inherits from System.Data.DLinq.DataContext.

I have this class:

public sealed class SupplierApproveDI
    {
        //private static readonly SupplierApproveDataContext instance;

        static SupplierApproveDI() { }

        private SupplierApproveDI() { }

        public static SupplierApproveDataContext Instance
        {
            get
            {
                    return new SupplierApproveDataContext();
            }
        }
    }


I use the datacontext like:

result = SupplierApproveDI.Instance.Supplier_ChangeStatus(obj.OrgID, newSupplierStatusId, uId);

where Supplier_ChangeStatus executes a stored procedure like:

StoredProcedureResult result = this.ExecuteStoredProcedure(((MethodInfo)(MethodInfo.GetCurrentMethod()))
                , orgId, supplierStatusId, createdBy);

I want to know when my data context instance close or is it not closing and leaving all the instance open and hanging?

Any suggestion would be appreciated.

Thanks and Regards,

Christian


is it possible to lock an user's account for just some time with .NET?

$
0
0

Hello,

I have a vb.NET 4.0 Web application that allows my Institute's teachers to select their classroom number then, if their students are playing games or surfing on the internet during the teaching time, to force theirs computers to switch off and to inactivate theirs accounts so they can’t log (by setting userAccountControl to 514).

Then, once the teacher as finished his talking, he can log on on my application, choose their classroom number then click on a button to unlock the students’ accounts (by setting userAccountControl to 512).

This app works just fine; however, as you can imagine, it happens that the teacher leaves the classroom without thinking of unlocking the student’s accounts….And every time it is me who has to do that. Just crazy.

I’m trying to find a way to lock the students accounts just for something like 1 or 2 hours and then automatically unlocking these accounts. I found what I thought to be a nice Active Directory attribute called lockoutDuration which is said to set the amount of time a count has to be locked before unlocking it. But I can’t find it amongst my AD attributes.

I tried looking for a WMI class to let me do this kind of thing. I didn’t find one. However, the Active Directory user properties dialog box has on the Account tab a check case to tell the system the Account is locked out…So this attribute must exist somewhere on the WMI Classes?

I tried Looking for a PowerShell 3 script but nothing.

I thought about creating a SQL server trigger but I need this trigger to execute some .net code not immediately but after 1h or 2, and I don’t know whether a trigger can do that (wait for a long time after it’s called before execute a code).

Could anyone have an idea about what can be done?

Thanks a lot,

Have a nice day,

Susana


susana

MemoryCache custom ChangeMonitor

$
0
0

I couldn't find any good examples of how to use ChangeMonitor classes.

Here's my problem: I'm caching a few method of my Repository, building a key to uniquely identify the cached data. The cached data has a expiration time, but the data can change before the expiration takes place.

Take a look:

 public class CachedUserRepository : CachedRepositoryBase, IUserRepository
    {
        private readonly CacheKeyBuilder keyBuilder;
        private readonly IUserRepository repository;
        private readonly CacheManager cacheManager;

        public CachedUserRepository(IUserRepository repository)
        {
            this.repository = repository;
            keyBuilder = new CacheKeyBuilder();
            cacheManager = CacheManager.Instance;
        }

        public IEnumerable<Content> GetWatchList(User user, Size cover = null, Pagination pagination = null)
        {
            var key = keyBuilder.Create(GetType()).With(user, cover, pagination).Build();
            var entry = cacheManager.Get(key);
            if (entry != null)
                return (IEnumerable<Content>)entry;

            var result = repository.GetWatchList(user, cover, pagination);
            cacheManager.Add(user, key, result, Duration(CacheType.VeryLow));

            return result;
        }

I'm caching the WatchList of the users. It's a web app and there could be several users, so I'm building a key for each one of them. That's fine. However, my repository has the following method as well:

public void AddBookmark(User user, Identifier contentId)
        {
            repository.AddBookmark(user, contentId);
        }

When the following method is called, I need to clear any cached data of the given user (method's parameter). How to accomplish that? ChangeMonitor is the way? And if it is, how can I write the code for it?


Take a look at WPF FlashMessage
About.me

sc.exe takes 2 minutes to create a service on Windows 8.1

$
0
0

Hi,

    On Windows 8.1, using .net 3.5 SP1, sc.exe create command takes 2 minutes to install a service. On a Windows 7 system, the service installs immediately. Are there any thoughts on what might be happening on win 8.1 causing this delay.

A little background, I ran the sc command from Administrator command window. The machine is connected to domain and logged in with a domain user.

thanks!

 

Use Linear Programming using the Solver Foundation Services

$
0
0

Firstly I apologize about my poor English language.

please give me the solution to solve the problem related to the example link mentioned below.

what is the solution to give results in that program codes (in link) to give result even it difficult to match some constraints.

it gives result when all constraints match only. otherwise it do not display any result.

http://msdn.microsoft.com/en-us/library/ff628587%28v=vs.93%29.aspx

Thank you for your supporting

Assembly.LoadFrom only locking file when Server on a Domain

$
0
0

I am running into the dreaded Assembly.loadfrom file locking error.  But only when our server is added to our test domain.  If we remove it and put in just in a workgroup, we do not find this behavior.

Please help.?

Read/write Excel files

$
0
0
From poking around in the Object Browser and the DataGridView documentation I get the impression that there is more than one way of interoperating with Excel.  I don't need continuous or interactive connection, but I do need to read and write .xls files.  I can operate in a model of Open, Read a bunch of cells, Close and Open, Write a bunch of cells, Close.

What is the simplest and best way to accomplish this?  It would be really nice if I could find a method that could be coded once to interoperate with all different versions of Excel.

Base to Derived is possible(Boxing), But Derived to base gives run time exception, however that is equivalent to Unboxing

$
0
0

class SampleClass
{
   public int i = 10;
}
class MainClass
{
   static void Main()
   {
      object a;
      a = 1;   // an example of boxing
      Console.WriteLine(a);
      Console.WriteLine(a.GetType());
      Console.WriteLine(a.ToString());
      a = new SampleClass();
      SampleClass classRef;
      classRef = (SampleClass)a; //Example of Unboxing
      Console.WriteLine(classRef.i);
   }
}

All classes in .net implicitly inherited from Object Class.In above code

classRef = (SampleClass)a; //Example of Unboxing is possible.

 class BaseSample
    {
        public int ii = 10;
    }
    class SampleClass:BaseSample
    {
        public int i = 10;
    }

    class MainClass
    {
        static void Main()
        {

  SampleClass classRef;

    BaseSample b = new BaseSample();
            b.ii = 90;

   classRef = (SampleClass)b; //Getting Run time Exception

}

Why I am gettting run time exception,

Boxing and UnBoxing is possible

 public int ConvertToINT(object obj)
        {
            int i = (int)obj;
            return Convert.ToInt32(obj);
        }
        public string CovertToString(object obj)
        {
            string s = (string)obj;
            //return Convert.ToString(s);
            return s;
        }

Convert.ToInt32(obj); This is Base to derived and possible,

Butwhen

Base b=new Base();

Child c=(Child)b;//Gives run time exception

Why is it So.

Please help

DotSpatial.Positioning With ublox GPS device

$
0
0

Hi all,

I know this thread doesn't relate to any MS products but I really don't know other forum that can help me to resolve a development issue (I posted one on Dotspatial's codeplex forum but still no one reply, seehttps://dotspatial.codeplex.com/discussions/468994). Therefore I will repost this issue in .NET category because I also would like to know is there a .NET Sensor API for Windows 7 that can replace Dotspatial? I know there is a Location class in .NET but it only provide basic information such as latitude, longitude, altitude, HDOP, and VDOP, however our application also need to display extra information to user like number of fixed satellites, gps fixed status which can be handle by Dotspatial.

Here is the original post on Dotspatial forum:

"I ran DemoGPS on Windows 7 Pro Tablet PC that has a built-in ublox GPS device, but the app can't detect the device. I try ublox's own software and GPS Utility and they can detect GPS device as well as receive Nmea data from gps. 

Does DotSpatial support ublox devices? "

Hopefully someone can answer this :D!!

Thanks alot

Sam

Controller Scaffolding in MVC 5

$
0
0

Hi,

I am developing an application using mvc 5 in Visual Studio 2012. I have successfully build my model class.

My Model class:

using System;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;

namespace NewMvcDemo.Models
{
    public class User
    {
        [Key]
        public int ID { get; set; }
        public string  Name { get; set; }
        public string City { get; set; }
        public string Company { get; set; }
    }

    public class UserDbContext : DbContext
    {
        public DbSet<User> NewUser { get; set; }
    }
}


When i want to add a New Scaffolded item in controller , the following error occur:

 

Microsoft monitoring agent recording for web requests and responses

$
0
0

Hi,

As per my findings Microsoft monitoring agent records only errors related information for a web application.Is there any way by which it can record all web requests, Responses and CPU Usage , Memory related information.

Looking forward for your reply.URGENTLY!!!!

Thanks

DirectoryVirtualListView not working correctly

$
0
0

Hi Folks,

I am having a similar issue as mentioned Here in that a query for users name beginning with 'G' just brings back a set of random results (actually I get 10 records sorted into alphabetical order starting from 'A').

DirectorySearcher search = new DirectorySearcher(directoryEntry);
                        search.SearchRoot = null;
                        search.Asynchronous = false;
                        search.Filter = String.Format("(objectClass=User)");

                        SortOption sortOption = new SortOption() { Direction = SortDirection.Ascending, PropertyName = "displayName" };
                        search.Sort = sortOption;

                        DirectoryVirtualListView dvlv = new DirectoryVirtualListView();
                        dvlv.Target = searchCriteria.Trim();
                        dvlv.BeforeCount = 0;
                        dvlv.AfterCount = 10;
                        search.VirtualListView = dvlv;

SearchResultCollection collection = search.FindAll()

Just wondering if anyone knows what the issue would be?

Also, while 'collection' will contain 10 results, if I then make a call to search.VirtualListView.ApproximateTotal;  I get a COM exception as this property is not defined. If I breakpoint on the line, count 10 seconds and then check the value it will contain value  (the entire number set of the users in A/D - rather than the 5 users I expect to get back).

This is indicating to me that the search is running asynchronously rather than blocking until it has a valid result set.  Is there some way I can force it to wait until the search has completed so it does not throw an exception?

Regards

Andy

Viewing all 8156 articles
Browse latest View live


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