|
Log the entire exception, not just the stacktrace. There are six lines on which "an" exception might occur. Can you point out to us which line it is?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
It seems that it complains about the Extension class not having the right constructor. But I do have it. Please see the original post and you will see the constructor that the exception is saying I don't have.
Here is the entire trace:
2012-11-02 10:24:41,921 [10] DEBUG App.Classes.Utils.MyHelper - DoesUserExist: Exception: System.NotSupportedException: Extension class must define a constructor that accepts a PrincipalContext argument.
at System.DirectoryServices.AccountManagement.Principal.MakePrincipal(PrincipalContext ctx, Type principalType)
at System.DirectoryServices.AccountManagement.SDSUtils.SearchResultToPrincipal(SearchResult sr, PrincipalContext owningContext, Type principalType)
at System.DirectoryServices.AccountManagement.ADStoreCtx.GetAsPrincipal(Object storeObject, Object discriminant)
at System.DirectoryServices.AccountManagement.ADStoreCtx.FindPrincipalByIdentRefHelper(Type principalType, String urnScheme, String urnValue, DateTime referenceDate, Boolean useSidHistory)
at System.DirectoryServices.AccountManagement.ADStoreCtx.FindPrincipalByIdentRef(Type principalType, String urnScheme, String urnValue, DateTime referenceDate)
at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate)
at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, String identityValue)
at App.Classes.Utils.UserPrincipalExtension.FindByIdentity(PrincipalContext context, String identityValue) in C:\visual studio 2010\Projects\App\Classes\Utils\UserPrincipalExtension.cs:line 61
at App.Classes.Utils.MyHelper.DoesUserExist(String usr) in C:\visual studio 2010\Projects\App\Classes\Utils\MyHelper.cs:line 70
Code where exception happened(Line 61 in the Extention class):
public static new UserPrincipalExtension FindByIdentity(PrincipalContext context,
string identityValue)
{
return (UserPrincipalExtension)FindByIdentityWithType(context,
typeof(UserPrincipalExtension),
identityValue);
}
Problem happens in the return line of that code.
|
|
|
|
|
I see one constructor, where your base-class defines two of them; is there an implementation for this[^] signature?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy,
Thanks a lot for the observation. I am glad I posted here to have other eyes look at it. I cannot believe I had such a small issue. hehe. The problem was that I had an extra parameter sent in to my basic constructor and that was not good. I am not even sure why I was sending in the userName.
Here is what I had:
Faulty Constructor:
public UserPrincipalExtension(PrincipalContext context, string userName) : base(context) { }
Fixed Constructor:
public UserPrincipalExtension(PrincipalContext context) : base(context) { }
Thanks so much for all of your help.
|
|
|
|
|
The law states that "given enough eyeballs, all bugs are shallow"
You'd have found it in the morning 
|
|
|
|
|
public interface IMyInterface
{
string myInterfaceProp{ get; }
}
public class MyClass :IMyInterface
{
public string myInterfaceProp
{
get { return "some value"; }
}
}
public class UserClass
{
MyClass objMyClass =new MyClass ();
objMyClass.
}
How to hide the myInterfaceProp in the userclass when the "MyClass " instance is accessed? .
modified 4-Nov-12 22:00pm.
|
|
|
|
|
Your question is not clear, what exactly are you trying to achieve here? If you make it private or protected then it will be inaccessible.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
You cant hide an interface method.
An interface method has no implementation so you need not worry about hiding it.
|
|
|
|
|
The whole point of an interface is that it defines, well, an interface: a public contract for your class, or for third party classes, and the methods and properties that it will expose. It doesn't define any content, it simply states 'if a class says it implements me, you must be able to do these operations on it'.
Therefore it doesn't make sense to put protected methods or properties on an interface. If you don't want a property to be visible to the outside world, then don't add it to the interface!
|
|
|
|
|
Your question is a bit vague, but I'll have a go.
If you mean that you don't want to list myInterfaceProp as a member of the MyClass class (i.e. in Intellisense), implement the interface explicitly (What you're doing in your snippet is called implicit interface implementation).
Try this:
public class MyClass : IMyInterface
{
string IMyInterface.myInterfaceProp
{
get { return "some value"; }
}
}
That way you want have access to this member if you try to access it directly from MyClass , but you'll need a cast to IMyInterface .
2A
|
|
|
|
|
Explicit interface implemntation solved my problem. Thank u so much for the suggestion.
|
|
|
|
|
Why is this code hanging:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int Test()
{
System.Diagnostics.Debug.WriteLine("IN");
System.Threading.Thread.Sleep(5000);
System.Diagnostics.Debug.WriteLine("OUT");
return 17;
}
private async Task<int> TestAsync()
{
return await Task.Run(() =>
{
return Test();
});
}
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("BEFORE");
int a = TestAsync().Result;
System.Diagnostics.Debug.WriteLine("AFTER");
}
}
}
If I don't return a value from the async function, this code works as I expect. BEFORE, IN, AFTER, <5 sec pause>, OUT.
Kind of trying to make an async function that returns a value without blocking the UI thread.
|
|
|
|
|
You can't.
If you return a value, then the execution of the calling thread cannot continue until the value is available.
It can't just decide to "remember where it was and come back to it later" because it doesn't know what it may be doing when the value does become available.
If you want this kind of handling, then look at setting up a BackgroundWorker, and handling the RunWorkerCompleted event to get the returned value.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Seems like to make it work I need to make the 2nd function async as well and await on the result instead of using the .Result.
|
|
|
|
|
SledgeHammer01 wrote: Kind of trying to make an async function that returns a value without blocking the UI thread.
Try something like below;
private int Test()
{
System.Diagnostics.Debug.WriteLine("IN");
System.Threading.Thread.Sleep(5000);
System.Diagnostics.Debug.WriteLine("OUT");
return 17;
}
private void TestAsync()
{
Task.Factory.StartNew(delegate
{
OnTestFinished(Test());
});
}
private void OnTestFinished(int result)
{
if (InvokeRequired)
{
Invoke(new Action<int>(OnTestFinished), new object[] { result });
return;
}
this.Text = result.ToString();
}
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I'm trying to get a ASP.net application to talk to a WCF Windows Service. Both are on the same internal network and belong to the same domain, but are on different machines.
When connecting I see on the tracing log on my WCF Windows Service:
System.IdentityModel.Tokens.SecurityTokenValidationException: The service does not allow you to log on anonymously.
From what I understand WCF will use windows authentication by default. How do I pass credentials to the WCF service? This is how i'm connecting from the ASP.net client:
public static string Authenticate(string username, string password)
{
DomainControllerClient dc = null;
try
{
dc = new DomainControllerClient();
dc.Open();
bool success = dc.Authenticate(username, password);
if (success)
return "OK";
else
return "FAIL";
}
catch (Exception ex)
{
return ex.ToString();
}
finally
{
if (dc.State == CommunicationState.Opened)
dc.Close();
else if (dc.State == CommunicationState.Faulted)
dc.Abort();
dc = null;
}
}
** BTW I'm using netTcpBinding
|
|
|
|
|
|
I'm having a little trouble. I'm playing with WCF and trying to install it via a service. I'm following these two articles that I found: http://msdn.microsoft.com/en-us/library/ms733069.aspx[^] and http://a1ashiish-csharp.blogspot.com/2012/02/cnet-how-to-host-wcf-web-service-in.html#.UJGjIMXA_08[^]
Now what is happening is I created my WCF DLL Library and I added the WindowsService file and the ProjectInstaller to it. I then created a Windows Setup and added the primary output to the setup project.
When it installs it creates the service and links it to my DLL file instead of the windows service created a EXE and linking it to that. So what I end up with is a service that is unable to start because it can't use the DLL file.
Here is my ProjectInstaller class:
[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
public ProjectInstaller()
{
this.AfterInstall += new System.Configuration.Install.InstallEventHandler(ProjectInstaller_AfterInstall);
InitializeComponent();
}
void ProjectInstaller_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
{
using (ServiceController sc = new ServiceController("HostingPanelDC"))
{
try
{
sc.Start();
}
catch (Exception ex)
{
EventLog.WriteEntry("HostingPanel", "Unable to start service. Error: " + ex.Message, EventLogEntryType.Error);
}
}
}
}
I set the service name and all the service info by clicking serviceInstaller1 and serviceProcessInstaller1 and editing the fields in the properties page.
Here is my windows service class:
partial class WindowsService : ServiceBase
{
public ServiceHost serviceHost = null;
public WindowsService()
{
InitializeComponent();
ServiceName = "HostingPanelDC";
}
public static void Main()
{
ServiceBase.Run(new WindowsService());
}
protected override void OnStart(string[] args)
{
if (serviceHost != null)
serviceHost.Close();
serviceHost = new ServiceHost(typeof(DC.DomainController));
serviceHost.Open();
}
protected override void OnStop()
{
if (serviceHost != null)
{
serviceHost.Close();
serviceHost = null;
}
}
}
What exactly am I missing that is causing this not to generate the exe file? Thank in advanced!
|
|
|
|
|
Duh. Forgot to change the output to windows application and set the startup object. Thanks!
|
|
|
|
|
Suggestion,I was only able to install my service using the command line once I ran my installer, if you google the command line function and use it for your service to show up in the actual list of services.
|
|
|
|
|
Thanks for the suggestion! Once I made the changes listed above I was able to install and start the service automatically with the windows installer once I changed my WCF DLL Library that had the windows service and installer to a Windows Application and set the startup object
|
|
|
|
|
Hi Guys,
I'm not English so I'll try to explain my problems as simple as possible
I've been trying to backup/restore SQLce database for one of my latest applications.
This is how my code looks like:
This button opens location in which user can save .sdf (backup):
private void button2_Click(object sender, EventArgs e)
{
DialogResult ofd = folderBrowserDialog1.ShowDialog();
if (ofd == DialogResult.OK)
{
string backupPath = folderBrowserDialog1.SelectedPath;
textBox4.Text = backupPath;
}
}
... then file is being saved in chosen location (backup):
private void button4_Click(object sender, EventArgs e)
{
string fileName = "Database.sdf";
string sourcePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string backupPath = textBox4.Text;
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(backupPath, fileName);
System.IO.File.Copy(sourceFile, destFile, true);
}
To restore database user opens location with .sdf file:
DialogResult ofd = folderBrowserDialog1.ShowDialog();
if (ofd == DialogResult.OK)
{
string backupPath = folderBrowserDialog1.SelectedPath;
textBox5.Text = backupPath;
}
}
...and restore file using this code:
try
{
string fileName = "Database.sdf";
string sourcePath = textBox5.Text;
string restorePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(restorePath, fileName);
System.IO.File.Copy(sourceFile, destFile, true);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
I've checked all of this locally I mean after debugging and works perfectly.
When my application is published and than installed this code doesn't work. Throws an error 'Could not find file C:\Users\Lion\AppData\Local\Apps\2.0\J98YQDCL.P3L\3TX9ONZ9.XO3D\Database.sdf'
So its working before application is being published. Once is published and installed doesn't work.
Any ideas why? Could anyone please help me with this problem?
Thank you in advance for your help.
|
|
|
|
|
saturnuk wrote: 'Could not find file C:\Users\Lion\AppData\Local\Apps\2.0\J98YQDCL.P3L\3TX9ONZ9.XO3D\Database.sdf'
That message should give you a clue as to the problem.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Is the file in the actual location?
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
No this file doesn't exist in this location. And I know this. The question is how I can get this file? Where is the file?
System.IO.FileNotFoundException: Could not find file 'C:\Users\Lion\AppData\Local\Apps\2.0\J98YQDCL.P3L\3TX9ONZ9.XO3\cali..tion_b66fbc81589c75c7_0001.0000_012e4219e7fd7afb\Database.sdf'.
File name: 'C:\Users\Lion\AppData\Local\Apps\2.0\J98YQDCL.P3L\3TX9ONZ9.XO3\cali..tion_b66fbc81589c75c7_0001.0000_012e4219e7fd7afb\Database.sdf'
Thanks
|
|
|
|