C# SharpSvn'中的NullReferenceException;当提供的DefaultCredentials返回null时,返回SvnClient
我在我的项目中使用SharpSvn与SVN进行通信。对于一些SVN报道,我已经知道用户名和密码,而对于其他人,我不知道。因此,我将C# SharpSvn'中的NullReferenceException;当提供的DefaultCredentials返回null时,返回SvnClient,c#,.net,svn,sharpsvn,C#,.net,Svn,Sharpsvn,我在我的项目中使用SharpSvn与SVN进行通信。对于一些SVN报道,我已经知道用户名和密码,而对于其他人,我不知道。因此,我将SvnClient.Authentication.DefaultCredentials属性设置为我自己实现的System.Net.ICredentials(伪代码)的一个实例: 对于已知凭据,这很好。但是,如果凭据未知,则SharpSvn中会出现NullReferenceException: Object reference not set to an instanc
SvnClient.Authentication.DefaultCredentials
属性设置为我自己实现的System.Net.ICredentials
(伪代码)的一个实例:
对于已知凭据,这很好。但是,如果凭据未知,则SharpSvn中会出现NullReferenceException
:
Object reference not set to an instance of an object.
at System.Net.NetworkCredential.InternalGetUserName()
at System.Net.NetworkCredential.get_UserName()
at SharpSvn.Implementation.SvnCredentialWrapper.OnUserNamePassword(Object sender, SvnUserNamePasswordEventArgs e) in f:\qqn\sharpsvn-dist-1.6\src\sharpsvn\svnauthentication.h:line 619
这显然是因为我从GetCredential方法返回null
。但是,正如以下文件所明确指出的:
GetCredential方法返回一个NetworkCredential实例,该实例包含与指定URI和授权方案关联的凭据。当没有可用凭据时,GetCredential方法返回null
这是SharpSvn中的一个bug吗?否则,当凭据未知时,我应该返回什么
编辑:我刚刚发现我可以返回
新网络凭据()
而不是null
,以向SharpSvn指示凭据未知。尽管如此,我认为这是SharpSvn中的一个bug,因为返回null
应该同样有效。DefaultCredentials只是为Subversion库提供一个显式用户名和密码的替代方法
如果需要更高级的提示机制,则应在SvnClient.Autorization上挂接.UserNamePassword事件。这还允许管理是否应保存密码等
SharpSvn.UI.dll中有一个默认实现,它钩住了一些标准对话框
Object reference not set to an instance of an object.
at System.Net.NetworkCredential.InternalGetUserName()
at System.Net.NetworkCredential.get_UserName()
at SharpSvn.Implementation.SvnCredentialWrapper.OnUserNamePassword(Object sender, SvnUserNamePasswordEventArgs e) in f:\qqn\sharpsvn-dist-1.6\src\sharpsvn\svnauthentication.h:line 619