ReportViewer locking up for quite a while on GetDefaultPageSettings() - c#

I recently encountered a very weird problem with report viewer (Windows Forms). Normally the reportviewer behaves very well, loads fast and shows the reports nicely. But, we encountered a certain scenario in which it to takes ages to show the report. I cannot post the whole code as it is not clear what causes the problem.
The problem
The following method call causes the problem (again, only in a very specific scenario):
reportViewer.LocalReport.GetDefaultPageSettings()
It can take up to 10 minutes for the application get past this line and in fact, if this line is commented out then everything starts working perfectly.
The special scenario
The only difference in the special scenario that causes the problem is that right before showing the report some python code gets executed before the report is shown (via IronPython and in the same AppDomain, the python code does not reference anything even close to reporting).
Profiler, anyone?
Ok, so I run this scenario with a profiler (Xte) and noticed that the method IronPython.Runtime.PythonContext.LoadAssemblyFromFile is the one that freezes up. There is no explicit assembly-loads in python code we are running, so this is an automated assembly load.
The weird part
So, the weird part that I cannot get is how are those two things connected? I took a look at the GetDefaultPageSettings() in ILSpy and saw this:
public override ReportPageSettings GetDefaultPageSettings()
{
object syncObject;
Monitor.Enter(syncObject = this.m_syncObject);
ReportPageSettings pageProperties;
try
{
this.EnsureExecutionSession();
pageProperties = this.m_pageProperties;
}
finally
{
Monitor.Exit(syncObject);
}
return pageProperties;
}
And I can only guess that its the lock that is causing this method to hang, but I cannot understand how executing python affects this lock. I mean, it is absolutely clear that if I do not run the python code then this method executes perfectly fine without delays.
And by the way - after approx. 10 minutes the thing shows the report. It just locks up for 10 minutes and then continues normally.
Suggestions on where to go from here?
So, I would really appreciate if anyone can give me any info on there should I go now. At the moment I am trying to isolate the case in a separate clean project and as soon as I succeed I will post it here.
Thanks!
Update 1: Python script example
So far I only got one piece of additional information - this problem occurs even if you run a minimal script. So, even executing script 0 (which just returns 0) the problem will occur.
Update 2: Running in a separate domain
Running python in a separate domain did not help. The issue is still present.
Update 3: CurrentUICulture is involved!
During my debugging sessions I noticed at some point that in the problematic scenario AppDomain tries and fails to resolve the following resource assemblies:
mscorlib.resources, Version=4.0.0.0, Culture=fi, PublicKeyToken=b77a5c561934e089
mscorlib.resources, Version=4.0.0.0, Culture=fi-FI, PublicKeyToken=b77a5c561934e089
This is the reason for the 10-minute delay - it just tries to load that assembly over and over again (both CurrentCulture and CurrentUICulture are set to fi-FI). If, however, I change the CurrentUICulture to en-US then the problem disappears (as it not longer needs that assembly.
But again - the mystery still remains - if the CurrentUICulture is set to fi-FI and I execute any script via IronPython it will desperately try to load this resources file and fail all the time. If anyone is able to explain this to me - please do :)

The text in Update 3 actually contains the resolution. At the moment the only solution I know is to change the CurrentUICulture to en-US for the moment when the report control is loading and rendering. This effectively eliminates the 10 minute delay.

Related

My System.IO.File.WriteAllText coding doesn't create a file after it has once been deleted in Windows Explorer

CONCLUSION AT BOTTOM OF POST
I'm a novice with C# and have only just begun using System.IO, but haven't been able to find information on my issue so wanted to ask the guys here:
I have a program that when run, creates a directory, then writes to a .txt file what the most recent value of a certain variable was, so that if the program is interrupted or the computer loses power, restarting the program will retrieve that stored number from the .txt file.
I've simply done this:
string INSTATR = LastValue.ToString();
System.IO.File.WriteAllText(#"C:\\DotTempFiles\\"+Instrument.Name+"ATR.txt", INSTATR);
My first time running this program, the file was created, and I found that on every cycle the number in the file was being overwritten to the last valid number just as I wanted.
However, once I went to the DotTempFiles directory and deleted the .txt file using Shift+Del, the file has never returned upon running the program as I thought it would. If I delete the entire directory and run the program, the directory is recreated but still not the file.
If I run the program using a different Instrument.Name, that new file is created as expected, but the original one that I once manually deleted is still not showing, even after computer restarts.
I can't find any information leads online, so does anyone have an idea? Thank you!
EDIT (more info): People asked a few questions so I'm adding more information (thank you)
There are no errors being reported. It compiles fine, and when running, there is an output window that usually alerts me to errors like if I reference an object that is null, or try to read from an empty file, etc. No errors like this are occurring.
More background on what the program is. There is a stock trading program called NinjaTrader that has their own API based on C#. They wouldn't support the questions I have because it's outside the normal scope of the script development they intended people to use, and that's ok with me. The program itself is a trading strategy that is run within NinjaTrader, and it exposes default programmer access to these two main methods:
Initialize()
protected override void OnBarUpdate() //this is the main part of the program that gets called every time a change has occurred to one of the bars on the stock chart.
In the variable declaration section I have this:
System.IO.DirectoryInfo di = Directory.CreateDirectory(#"C:\\DotTempFiles");
And in OnStartUp() I have this:
//Set up ReadMe file in the temp directory in case people wonder why it keeps appearing
string README = "This DotTempFiles directory is created by the strategy every time it is run, and temporary text files with the name [instrumentsymbol]ATR.txt are written into it containing the last highest ATRStopValue for the strategy, which if it is stopped and restarted with an open position, it will read from that file to get back the best value instead of recalculating it with possibility of a lower unwanted value.";
System.IO.File.WriteAllText(#"C:\\DotTempFiles\\README.txt", README);
Every time OnBarUpdate() is called, which can be up to a few times per second, it first calculates a double called LastValue which is a number related to the stock price, then it converts it to a string INSTATR, then writes it to a .txt file.
string INSTATR = LastValue.ToString();
System.IO.File.WriteAllText(#"C:\\DotTempFiles\\"+Instrument.Name+"ATR.txt", INSTATR);
And this is every single piece of code I have connected to this issue. As I mentioned above, it created the file the first time, but since I've deleted the file in windows explorer, it isn't able to recreate it. However, deleting the directory and restarting the strategy program does recreate that directory.
OnTermination() is not being used to close or delete the file in any way (just in case people wanted to ask) -- I am not using any other code to interact with the file than the ones already shown. Thanks!
EDIT 2 (Update after reading comments): Thank you guys for your comments and help. What I'll do when I get back to my home is try recreating the minimal version of this with an empty program containing just these lines of code and see what the outcome is, and I'll post updates in either way.
EDIT 3: Thank you Steve, that is a very good idea that I should use from now on for these kinds of things.
EDIT 4 (Conclusion): Well, I found out that I overlooked something simple about my own code logic. I was setting the File.WriteAllText to trigger any time the Double variable increased in value, not on every call of the OnBarUpdate method. Because of this, the file would not be written except once every few hours or so and now I see that everything is working properly. I am sorry that I made all these people read this post since it was based on another issue of my own fault. However, I am very thankful to everyone for their comments that helped me get to this point, and to Steve and Mark Lakata for their tips that I learned some new good things from.
I found out there is nothing wrong with the file creation, it was the fact that my coding logic was just calling for it far less frequently than I assumed it was (once every few hours vs several times per second)

Tapi3Lib Adding a new line at runtime

I am having some trouble with the interop.tapi3lib.dll (which can be DL here:dllLink)
For a reporting program i'm writing, i want to monitor all of the devices available by the tapi for their calls. Now this is working nicely when i fire up the program, although i suspect the dll is written with the purpose of modifying calls on a single extension, with very little code i can see all of the activity perfectly.
The problem arrises when a user logs out (or in) a phone (I'm using this for a cisco Callmanager). At that time i am able to capture the tapi_object which in turn can be used to determine which line is removed and added (old number and new number) but i can't register the new address for sending events.
The exception when i try:
Value does not fall within the expected range.
because the tapiclass was created before this address was available i suspect.
At the moment i have done a test which creates a single tapiclass for each line individual and 1 tapiclass for monitoring the tapiobject event, but this is eating 10 times the memory for our company's configuration (20 phones) so i dont even want to test this at the target site (+300 phones). The other option (for i can think of) is to dispose the 'old' tapiclass and create a new one after, however i'm a bit concerned with either loosing events between, getting double events between and pingpong when multiple users log in/out (creating the class takes a couple of seconds with my program)
So, what i would really like is the option to
tapi.RegisterCallNotifications(ad, true, true, TAPI3Lib.TapiConstants.TAPIMEDIATYPE_AUDIO, 2);
for newly available lines.
Bit of background for answers :)
-I am fairly new to C#, completly new to COM-interop and i know the principles of C++, but ive never written anything in it.
Any help would greatly be appriciated. (also any comments about interop and such)
Hmm, turns out I was wrong. Adding the line for notification is possible and does not throw the exception. I think i didn't remove the old line before adding the new in my old sample.

Very strange C# RemotingException

When I compile and run my program in Debug mode, everything works as intended. However, when I compile and run in Release mode, things get a little... strange. I receive the following exception if I run the Release mode executable
RemotingException occurred: The async result object is null or of an
unexpected type.
We do use .NET remoting in our application, however, I can confirm this is not a problem with any of my remote calls. This is happening right when I open the program, before I can even step into the Main() method. I have not really been able to find any help on the internet regarding this particular exception/message combination, other than a suggestion about the path being too long (but neither my working copy or the installed copy should have paths long enough to trigger this). Any assistance on this is greatly appreciated, as I'm not entirely sure how to proceed with this error.
Check here: mystery RemotingException raised when changing Platform Target to Any CPU
It seems to change the paths to the DLL's you want to access. Take a look at the paths in the linked question. They are well over 127 chars, and there is nothing you can do about it.
Example:
'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll
EDIT: Try changing to "x86" and see if the error goes away.

Invalid parameter when setting an image

I'm running a .NET 2.0 program on many computers. On one I had this error occurring repeatedly until I reset the application.
//line below was throwing the exception
this.myButton.BackgroundImage = global::myNamespace.Properties.Resources.myImage;
Exception:
ExceptionType: ArgumentException
Message: Parameter is not valid.
Source: System.Drawing
StackTrace: at System.Drawing.Image.get_Flags()
at System.Windows.Forms.ControlPaint.IsImageTransparent(Image backgroundImage)
at System.Windows.Forms.Control.set_BackgroundImageLayout(ImageLayout value)
The resource exists and it works fine once reset. Can anyone provide any insight as to might be happening?
I suggest you use Process Monitor to examine real-time activity on the file, and which processes might be locking it. Add a Filter where the Path is the name of the image/resource file; this should quickly show if anything is monkeying around with the file behind your back.
Yes, this is a 6 year old post! Ran into the same error today, and it took me far longer to fix than it should have. I was actually disposing my image control on startup, so I obviously couldn't adjust its background image on run-time. Might as well double check for that if you're here.

Crystal Report's report loading forever

I've some Crystal reports in a VS2010 application. They all work fine, but sometimes (happened at least twice), they will stay on the hourglass without ever loading. If I launch another instance of the application and generate the report (while the other instance still loads), it works fine. If the non-working instance generates another report, it works fine. If the form is closed and reopened, it works fine.
So what may go wrong? There should be a timeout if there's an issue accessing the datasource.
Is this a bug or a known issue? I haven't found any info on that.
Is there a way to catch this "error" so the user doesn't waste his time for half an hour and then call me?
Cheers
To catch problems like this you may need to add logging code to your app.
Make sure the Log function includes a time stamp, Pseudo code:
Log("pre-DB connect)
...DB connection
Log("post-DB connect)
Log("pre-Load Report...")
...load the report
Log("post-Load Report")
Once you narrow it down to a section of code, you can add more logging code to that section until hopefully, you zero in on the line that is hanging.

Categories

Resources