System.NullReferenceException in System.Data.RBTree`1.Minimum(Int32 x_id) - c#

I am occationally getting a null reference exception when running my bitcoin node (written in C# .NET 4.5). I have been trying various apporaches, but it keeps coming up, sometimes after a few hours, sometimes after the server has been running uninterrupted for days. I am unable to provoke the issue (cannot reproduce), and I cannot see the source of the .NET implementation of the red-black-tree either. It seems it could be an internal .NET bug related to clearing a dataset. I have an exception trace here. I would appreciate any feedback on how to either correct the issue or work around it, in case anyone has had the same odd experience.
HResult: -2146233088, 0x80131500
Exception Source:
Exception Origin:
Exception Stack:
Exception Type: Slf.Cs.SlfInternalErrorException
Exception Message: SelectData with SELECT statement: "SELECT * FROM [dbo].[BlockHeaders] WHERE BlockHash = #EqualToValue" failed.
SlfException Info:
HResult: -2146233088, 0x80131500
Exception Source: Slf.Cs
Exception Origin: Int32 SelectData(System.Data.SqlClient.SqlConnection, Int32, System.Data.DataTable, System.String, System.Data.SqlClient.SqlParameter[])
Exception Stack: at Slf.Cs.SlfSqlUtilities.SelectData(SqlConnection connection, Int32 timeoutSeconds, DataTable dataTable, String selectStatement, SqlParameter[] parameters) in C:\Data Files\Development Projects\iProtus\Frameworks\Slf.Cs\System\Basics\SlfUtilities.cs:line 1231
at Slf.Cs.Data.SlfSqlTable`1.Select(String columnName, Object equalToValue, Int32 maxCount, String orderByStatement) in C:\Data Files\Development Projects\iProtus\Frameworks\Slf.Cs\System\Database\SqlServer\SlfSqlDatabase.cs:line 950
at Slf.Cs.CryptCoin.BlockchainDB.GetDbBlockHeadersByBlockHash(Byte[] headerHash) in C:\Data Files\Development Projects\iProtus\Frameworks\Slf.Cs.CryptCoin\Basics\BlockchainDB.cs:line 212
at Slf.Cs.CryptCoin.BlockchainDB.GetBlockHeight(SlfByte32 blockHash) in C:\Data Files\Development Projects\iProtus\Frameworks\Slf.Cs.CryptCoin\Basics\BlockchainDB.cs:line 856
at Slf.Cs.CryptCoin.BitcoinStore.GetBlockHeight(SlfByte32 hash) in C:\Data Files\Development Projects\iProtus\Frameworks\Slf.Cs.CryptCoin\Basics\BitcoinStore.cs:line 597
at Slf.Cs.CryptCoin.BitcoinPeer.ExecuteGetHeadersCommand(BitcoinMessage message) in C:\Data Files\Development Projects\iProtus\Frameworks\Slf.Cs.CryptCoin\Network\BitcoinPeer.cs:line 829
at Slf.Cs.CryptCoin.BitcoinPeer.ExecuteCommand(BitcoinMessage message) in C:\Data Files\Development Projects\iProtus\Frameworks\Slf.Cs.CryptCoin\Network\BitcoinPeer.cs:line 1223
at Slf.Cs.CryptCoin.BitcoinPeer.ProcessNextCommand() in C:\Data Files\Development Projects\iProtus\Frameworks\Slf.Cs.CryptCoin\Network\BitcoinPeer.cs:line 1591
at Slf.Cs.CryptCoin.BitcoinPeer.Run(Object userContext) in C:\Data Files\Development Projects\iProtus\Frameworks\Slf.Cs.CryptCoin\Network\BitcoinPeer.cs:line 1740
at Slf.Cs.CryptCoin.BitcoinNode.Peer(PeerContext context) in C:\Data Files\Development Projects\iProtus\Frameworks\Slf.Cs.CryptCoin\Network\BitcoinNode.cs:line 857
at Slf.Cs.SlfPeerToPeerNode.InternalPeerThread(PeerContext context) in C:\Data Files\Development Projects\iProtus\Frameworks\Slf.Cs\System\Network\SlfPeerToPeerNode.cs:line 1977
Exception Type: System.NullReferenceException
Exception Message: Object reference not set to an instance of an object.
HResult: -2147467261, 0x80004003
Exception Source: System.Data
Exception Origin: Int32 Minimum(Int32)
Exception Stack: at System.Data.RBTree`1.Minimum(Int32 x_id)
at System.Data.RBTree`1.Successor(Int32& nodeId, Int32& mainTreeNodeId)
at System.Data.RBTree`1.RBTreeEnumerator.MoveNext()
at System.Data.Index.InitRecords(IFilter filter)
at System.Data.Index.Reset()
at System.Data.DataTable.ResetInternalIndexes(DataColumn column)
at System.Data.DataTable.Clear(Boolean clearAll)
at System.Data.DataTable.Clear()
at Slf.Cs.SlfSqlUtilities.FillDataTable(SqlDataAdapter adapter, DataTable dataTable) in C:\Data Files\Development Projects\iProtus\Frameworks\Slf.Cs\System\Basics\SlfUtilities.cs:line 1299
at Slf.Cs.SlfSqlUtilities.SelectData(SqlConnection connection, Int32 timeoutSeconds, DataTable dataTable, String selectStatement, SqlParameter[] parameters) in C:\Data Files\Development Projects\iProtus\Frameworks\Slf.Cs\System\Basics\SlfUtilities.cs:line 1222
--Edit, due to nature of initial comments--
Look at the innermost exception trace. This is a call to the standard DataTable.Clear() method, that is supposed to remove all from a DataTable. The rest doesn't really matter. In hindsight, I should have just posted that innermost exception.
Furthermore, I do not see the need to provide sample code, as one requested, since it obviously is internal to .NET. Most likely it is concurrency related, which I tried circumvent by wrapping all my DataTable.Clear() calls in a lock on a static object, and it still happens. The fact that it happens rarely and with random intervals is another good indication that concurrency is the issue. However, trying everything, I finally gave up and posted here, hoping someone else has this issue solved :)

Related

How to debug SQL Server LINQ expressions? [duplicate]

This question already has answers here:
MSSQL Error 'The underlying provider failed on Open'
(31 answers)
Closed last year.
I have the following piece of code, which works at a customer, but not on my computer:
var result = await db.Configurations.FirstOrDefaultAsync().ConfigureAwait(false);
db is derived from a System.Data.Entity.DbContext, defined in EntityFramework.6.4.0\lib\net45\EntityFramework.dll.
In the corresponding SQL Server database, there is a table "Configurations" and it contains an entry.
When I launch the line of source code, an Exception gets generated (I hereby show the slightly formatted content of the immediate window while asking ? ex):
? ex
{"An exception occurred while initializing the database. See the InnerException for details."}
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233087
HelpLink: null
InnerException: {"The underlying provider failed on Open."}
Message: "An exception occurred while initializing the database. See the InnerException for details."
Source: "EntityFramework"
StackTrace: " bij System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)\r\n bij System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
bij System.Data.Entity.Internal.LazyInternalContext.<>c.<InitializeDatabase>b__58_0(InternalContext c)
bij System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
bij System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
bij System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
bij System.Data.Entity.Internal.InternalContext.Initialize()
bij System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
bij System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
bij System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
bij System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
bij System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
bij System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync[TSource](IQueryable`1 source)
bij Project.<GetConfigAsync>d__56.MoveNext() in C:\\Source_Code_Directory\\Source_Code_File.cs:regel 2149"
TargetSite: {Void PerformInitializationAction(System.Action)}
I know this line of code works at customer's system, and I'm working on a restored backup of customer's DB.
What is going wrong and what can I do to fix it (what is the underlying provider)?
Thanks in advance
In the meantime the problem is analysed:
I had taken the backup of the customer's DB and restored it on my PC, but the username, as indicated in the connectionstring in source code, was wrong, hence my application could simply not open the database connection, so now the problem comes down on a database user management issue.
Thanks for all the support.

SqlConnection throws an exception when running without debugging

I have an exception every time I try to run my program without debugging (Ctrl+F5). The code seems to run fine with debugging. I have tried creating a temp project with just the essentials. I have reinstalled Visual Studio. The problem still occurs. There is already a post about this but not a clear answer.
My Connection String:
"Data Source=(localdb)\\ProjectsV12;Initial Catalog=gatdb;Integrated Security=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Trusted_Connection=False;"
The Exception occurs here:
(SqlConnection connection = new SqlConnection(connectionString))
This is the exception:
System.TypeInitializationException was unhandled
HResult=-2146233036
Message=The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.
Source=System.Data
TypeName=System.Data.SqlClient.SqlConnection
StackTrace:
at System.Data.SqlClient.SqlConnection..ctor()
at System.Data.SqlClient.SqlConnection..ctor(String connectionString, SqlCredential credential)
at System.Data.SqlClient.SqlConnection..ctor(String connectionString)
at GatHunter.Sql.IsServerConnected(String connectionString) in c:\users\kold\documents\visual studio 2015\Projects\ScatteredGats\GatHunter\Sql.cs:line 14
at GatHunter.Program.Main(String[] args) in c:\users\kold\documents\visual studio 2015\Projects\ScatteredGats\GatHunter\Program.cs:line 14
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.Data.SqlClient.SqlConnectionFactory' threw an exception.
Source=System.Data
TypeName=System.Data.SqlClient.SqlConnectionFactory
StackTrace:
at System.Data.SqlClient.SqlConnection..cctor()
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.Data.SqlClient.SqlPerformanceCounters' threw an exception.
Source=System.Data
TypeName=System.Data.SqlClient.SqlPerformanceCounters
StackTrace:
at System.Data.SqlClient.SqlConnectionFactory..ctor()
at System.Data.SqlClient.SqlConnectionFactory..cctor()
InnerException:
BareMessage=Configuration system failed to initialize
HResult=-2146232062
Line=0
Message=Configuration system failed to initialize
Source=System.Configuration
StackTrace:
at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
at System.Configuration.ConfigurationManager.PrepareConfigSystem()
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_SwitchSettings()
at System.Diagnostics.Switch.InitializeConfigSettings()
at System.Diagnostics.Switch.InitializeWithStatus()
at System.Diagnostics.Switch.get_SwitchSetting()
at System.Data.ProviderBase.DbConnectionPoolCounters..ctor(String categoryName, String categoryHelp)
at System.Data.SqlClient.SqlPerformanceCounters..ctor()
at System.Data.SqlClient.SqlPerformanceCounters..cctor()
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.Uri' threw an exception.
Source=System.Configuration
TypeName=System.Uri
StackTrace:
at System.Configuration.ClientConfigurationSystem..ctor()
at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.UriParser' threw an exception.
Source=System
TypeName=System.UriParser
StackTrace:
at System.Uri..cctor()
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.Runtime.Versioning.BinaryCompatibility' threw an exception.
Source=mscorlib
TypeName=System.Runtime.Versioning.BinaryCompatibility
StackTrace:
at System.Runtime.Versioning.BinaryCompatibility.get_TargetsAtLeast_Desktop_V4_5()
at System.UriParser..cctor()
InnerException:
HResult=-2146233033
Message=Input string was not in a correct format.
Source=mscorlib
StackTrace:
at System.Version.VersionResult.SetFailure(ParseFailureKind failure, String argument)
at System.Version.TryParseComponent(String component, String componentName, VersionResult& result, Int32& parsedComponent)
at System.Version.TryParseVersion(String version, VersionResult& result)
at System.Version.Parse(String input)
at System.Version..ctor(String version)
at System.Runtime.Versioning.BinaryCompatibility.ParseFrameworkName(String frameworkName, String& identifier, Int32& version, String& profile)
at System.Runtime.Versioning.BinaryCompatibility.ParseTargetFrameworkMonikerIntoEnum(String targetFrameworkMoniker, TargetFrameworkId& targetFramework, Int32& targetFrameworkVersion)
at System.Runtime.Versioning.BinaryCompatibility.ReadTargetFrameworkId()
at System.Runtime.Versioning.BinaryCompatibility.get_AppWasBuiltForFramework()
at System.Runtime.Versioning.BinaryCompatibility.BinaryCompatibilityMap..ctor()
at System.Runtime.Versioning.BinaryCompatibility..cctor()
InnerException:
In your connection string Integrated Security is set to False.
User ID = ****; Password = **** missing in your connection string.
If you would like to connect using Windows Authentication use
Integrated Security=SSPI; instead of Integrated Security=true;
If you try to use Integrated Security=true/false/yes/no with OleDb provider, you will get an exception during connection.
I want to thank everybody for their advise. I do not know why but what fixed this issue for me (even though I created an entirely new project and didn't touch the app.config) was this.
delete app.config
re-create via add->new item-> app.config
switch the target framework from 4.6.1 to 4.0 then back to 4.6.1
again.
Initially I wanted to see what the reaction was when I switched to the 4.0 framework and to my surprise it suddenly started working. I know this sounds strange and I have no explanation for it.
This mostly due an error in your app.config file, Check for badly formed XML or unexpected elements.
Also double check you connectionstring.
Try simplifying the connection string to;
string str="Data Source=(localdb)\\ProjectsV12;Initial Catalog=gatdb;Integrated Security=False;User ID=sa;Password=sa;";
SqlConnection connection = new SqlConnection(str);
and try again.
Do the following steps.
Create "xyz.udl" file on desktop.
Double click on that file.
Select appropriate provider
Select server
Set user / password and allow to save password
Select database and hit test connection.
Click on Ok button.
Open that "xyz.udl" file in notepad.
Copy your connection string and use that.

AppDomainUnloadedException when TFS is cloning git repos for a build

Suddenly, when queuing builds in TFS based on a git team project, I get the following stack trace.
Exception Message: Attempted to access an unloaded AppDomain. (type
AppDomainUnloadedException) Exception Stack Trace: Server stack
trace: at
LibGit2Sharp.Core.NativeMethods.git_clone(RepositorySafeHandle& repo,
String origin_url, FilePath workdir_path, GitCloneOptions& opts) at
LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir,
GitCloneOptions& opts) at LibGit2Sharp.Repository.Clone(String
sourceUrl, String workdirPath, CloneOptions options) at
Microsoft.TeamFoundation.Build.Activities.Git.GitPull.GitClone.GetRepository(String
repositoryUrl, String workingFolder, Boolean checkoutSubmodules) at
System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr
md, Object[] args, Object server, Object[]& outArgs) at
System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage
msg, IMessageSink replySink)
Exception rethrown at [0]: at
System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message
reqMsg, Boolean bProxyCase) at System.Func4.EndInvoke(IAsyncResult
result) at
Microsoft.TeamFoundation.Build.Activities.Git.GitPull.GitRepositoryBase.EndExecute(AsyncCodeActivityContext
context, IAsyncResult result) at
System.Activities.AsyncCodeActivity1.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext
context, IAsyncResult result) at
System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor
executor, BookmarkManager bookmarkManager)
I changed nothing for this to happend, googling so far I found info about it perhaps being macafee, but we dont use that on our build agent.
Using an on-premises build server
Normal TFS team projects build as expected
Resolved by restarting the server - not sure how I didn't think of that.

An error occurred while connecting to Firefox ---> System.IO.IOException: The directory is not empty

I am working with selenium the last months. I use VS 2013 C#. Most of the time i am using webdriver.dll (2.39.0.0) for firefox (31.0.0.5310), because my testautomation (coded ui tests)
ran pretty stable with it. but now i get randomly this error:
> OpenQA.Selenium.WebDriverException: An error occurred while connecting to Firefox ---> System.IO.IOException: The directory is not empty.
Result StackTrace:
at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound)
at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
at OpenQA.Selenium.Firefox.FirefoxExtension.Install(String profileDir) in c:\Projects\WebDriver\trunk\dotnet\src\webdriver\Firefox\FirefoxExtension.cs:line 106
at OpenQA.Selenium.Firefox.FirefoxProfile.InstallExtensions() in c:\Projects\WebDriver\trunk\dotnet\src\webdriver\Firefox\FirefoxProfile.cs:line 357
at OpenQA.Selenium.Firefox.FirefoxProfile.WriteToDisk() in c:\Projects\WebDriver\trunk\dotnet\src\webdriver\Firefox\FirefoxProfile.cs:line 254
at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Start() in c:\Projects\WebDriver\trunk\dotnet\src\webdriver\Firefox\Internal\ExtensionConnection.cs:line 90
at OpenQA.Selenium.Firefox.FirefoxDriver.StartClient() in c:\Projects\WebDriver\trunk\dotnet\src\webdriver\Firefox\FirefoxDriver.cs:line 225
--- End of inner exception stack trace ---
at OpenQA.Selenium.Firefox.FirefoxDriver.StartClient() in c:\Projects\WebDriver\trunk\dotnet\src\webdriver\Firefox\FirefoxDriver.cs:line 231
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) in c:\Projects\WebDriver\trunk\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 88
at Testcase1.UIMap.BrowserSettingsFF() in c:***************\UIMap.cs:line 609
at Testcase1.UIMap.InitDriver() in c:***************\UIMap.cs:line 678
I run it on 2 devices working with TFS. On one device it happens much more often.
I could not figure out the problem by now. Has anyone the same problem?

PermissionSet - Request Failed error

I have few projects communicating using ChannelSink, ServerSink and ClientSink.
I've upgraded the projects from .NET 2.0 to .NET 4.0. Before the upgrade everything worked fine.
Now, when I try to communicate , - for a specific message - my OnReceiveMessage isn't called and throwing the following exception:
System.Security.SecurityException: Request failed
Server stack trace:
at System.Array.InternalCreate(Void* elementType, Int32 rank, Int32* pLengths, Int32*
pLowerBounds)
at System.Array.CreateInstance(Type elementType, Int32 Length)
at System.Runtime.Serialization.Formatters.Soap.ObjectReader.ParseArray(ParseRecord
pr)
at System.Runtime.Serialization.Formatters.Soap.ObjectReader.ParseObject(ParseRecord
pr)
at System.Runtime.Serialization.Formatters.Soap.ObjectReader.Parse(ParseRecord
pr)
System.Runtime.Serialization.Formatters.Soap.SoapHandler.StartChildren()
at System.Runtime.Serialization.Formatters.Soap.SoapParser.ParseXML()
System.Runtime.Serialization.Formatters.Soap.ObjectReader.Run()
System.Runtime.Serialization.Formatters.Soap.ObjectReader.Deserialize(HeaderHandler,
ISerParser
serParser)
System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream
serializationStream,
HeaderHandler handler)
at System.Runtime.Remoting.Channels.CoreChannel.DeserializeSoapRequestMessage(Stream
inputStream, Header[] h, Boolean bStrictBinding)
at System.Runtime.Remoting.Chanels.SoapServerFormatterSink.ProcessMessage
(IServerChannelSinkStack sinkStack, IMessage requestMsg,
ITransportHeaders requestHeaders, Stream
requestStream, IMessage& responseMsg, ITransportHeaders&
responseHeaders, Stream& responseStream)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage (IMessage reqMsg, IMessage
retMSg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
.
. (some of my files)
. The action that failed was: Demand The type of the first permission that failed was: System.Security.PermissionSet The demand
was for:
The only permitted permissions were:
The method that caused that failure was:
System.Runtime.Remoting.Channels.ServerProcessing
ProcessMessage(System.Runtime.Remoting.Channels.IServerChannelSinkStack,
System.Runtime.Remoting.Messaging.IMessage,
System.Runtime.Remoting.Channels.ITransportHeaders, System.IO.Stream,
System.Runtime.Remoting.Messaging.IMessage ByRef,
System.Runtime.Remoting.Channels.ITransportHeaders ByRef,
System.IO.Stream ByRef)
The thing is, if I create a dummy method and add it to the sinkstack - it calls it. even if I use the same proxy which denies the message.
Other thing is, The other messages are working just fine. only one type of messages isnt working from all the types iv'e created.
I haven't requested PermissionSet at my app at all, Any help?
Pah - should have guess that 5 minutes after posting on stack exchange I would find it. I simply had to replace:
<formatter ref="soap" />
by
<formatter ref="soap" typeFilterLevel="Full" />
The MSDN documentation for typeFilterLevel explains what's happening, although I'm not entirely sure why an array isn't considered a "basic" type

Categories

Resources