|
Start by looking at the input and output files: are you using absolute paths? Relative paths? Are they all looking at the same files?
What are the folders like - do they have suitable permissions, if they aren't the same?
Are the debug and release versions running on the same computer? Under the same user?
What happens if you execute the debug version directly in the same way you did with the release?
Do you get any error messages? Are you swallowing any exceptions?
You need to get information on exactly what is happening - we can't run your code in isolation!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi OriginalGriff,
The code for input and output files is
private static readonly string TemplatesFile =
Path.Combine(Directories.CurrentDirectory, "Reports", "ReportsTemplate.xlsx");
private static readonly string MastersFile =
Path.Combine(Directories.CurrentDirectory, "Reports", "Master.xlsx");
private static FileInfo Template = new FileInfo(TemplatesFile);
private static FileInfo Masters;
The folders have suitable permissions.
Yes, Debug and Release version are on the same computer, under same user.
When I run the EXE file I am not getting any output on both Debug and Release versions, but getting nice excel report when I run it from the IDE.
I am getting no errors. But, in the output window of the IDE, I am getting lots of First Chance Exceptions like this:
A first chance exception of type 'System.ObjectDisposedException' occurred in System.Data.SQLite.dll
Even though, I am getting a nice excel report. But not from EXE file.
Regards.
|
|
|
|
|
You are using relative paths - relative to the current directory, which will default to the folder the app is run from - so check that you are looking in the right folder when you run the code.
And I'd look in the debugger at where the exceptions are happening and why - it may be that they are relevant to your problem, and it works because the debugger is trapping the exception and letting you know it occurred. In the "undebugged" version, they may be stopping your code running. If you look on the VS Debug menu, you can tell it to break on all exceptions, caught or not.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I'd recommend that you debug it line by line and check if everything is happening as expected, is line 1 getting the values? how about line 2? 3? and so on. is every object instanced correctly? must of the times something really small is what is causing the problem.
When you execute the code inside visual studio, the application runs from the debug/release folder, are you executing it from the same location? or you copied the exe to a different folder? could it be is the paths you're using to read and write are not returning a valid path?
I want to die like my grandfather- asleep, not like the passengers in his car, screaming!
|
|
|
|
|
This isn't going to help since he states that the program works as intended when run under the IDE, which of course, is what he'd be doing in order to debug.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
Hi Gonzoox,
Thanks for the reply. Yes, I had executed and executing the program from the same folder as it was created by the IDE. Moreover, debugging line by line, I am getting proper watch values on each variables.
Even though, I will debug it once more as you said.
Thanks.
|
|
|
|
|
This is beginning to look like a Heisenbug[^]
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
As others have already said, more info would be needed in order to solve the problem. However, I understand the difficulty since the project works in IDE but not as an executable.
So what I suggest is that you add some kind of 'messaging' into the code. It could be writing a log file or something similar or simply just show message boxes. Add these messages to the code and run the exe. This should give you better understanding about the execution. Try to add relevant info into the messages such as working directory or the full paths of the file names etc.
With the messages you see more easily what happens and what code is reached and what is not.
|
|
|
|
|
Hi Mika,
As you said I designed a logfile stream writer and now I got my log file full of these two errors:
ERROR: Cannot access a disposed object.
Object name: 'SQLiteConnection'. TARGET: Void CheckDisposed() STACK TRACE: at System.Data.SQLite.SQLiteConnection.CheckDisposed()
at System.Data.SQLite.SQLiteConnection.get_State()
at System.Data.SQLite.SQLiteDataReader.CheckClosed()
at System.Data.SQLite.SQLiteDataReader.Read()
at PTMS.Classes.Reports.Reporting.WardWiseTax(Int32 WardNumber) in Reporting.cs:line 209
19/09/2015 12:18:39 PM : ERROR: Cannot access a disposed object.
Object name: 'SQLiteConnection'. TARGET: Void CheckDisposed() STACK TRACE: at System.Data.SQLite.SQLiteConnection.CheckDisposed()
at System.Data.SQLite.SQLiteConnection.get_State()
at System.Data.SQLite.SQLiteDataReader.CheckClosed()
at System.Data.SQLite.SQLiteDataReader.Read()
at PTMS.Classes.Reports.Reporting.WardWiseTax(Int32 WardNumber, Boolean TotalPaid) in Reporting.cs:line 231
And here is the code where I am getting those errors:
private double WardWiseTax(Int32 WardNumber)
{
double TT = 0;
try
{
Engine E = new Engine();
SQLiteCommand CUSTCMD = new SQLiteCommand(E.SelectSQL("CUSTOMERS", "WARDNUMBER"), E.Conn);
CUSTCMD.Parameters.AddWithValue("WARDNUMBER", WardNumber);
SQLiteDataReader CUSTRDR = CUSTCMD.ExecuteReader();
Calculate CT = new Calculate();
while (CUSTRDR.Read())
TT += CT.LedgerBalance(CUSTRDR["DEMAND"].ToString())[1];
CUSTCMD.Dispose();
CUSTRDR.Dispose();
CT.Dispose();
return TT;
}
catch (Exception ex) { LogEvent.WriteErrorLog(ex); return 0; }
}
private double WardWiseTax(Int32 WardNumber, bool TotalPaid)
{
double TT = 0;
try
{
Engine E = new Engine();
SQLiteCommand CUSTCMD = new SQLiteCommand(E.SelectSQL("CUSTOMERS", "WARDNUMBER"), E.Conn);
CUSTCMD.Parameters.AddWithValue("WARDNUMBER", WardNumber);
SQLiteDataReader CUSTRDR = CUSTCMD.ExecuteReader();
Calculate CT = new Calculate();
while (CUSTRDR.Read())
{
TT += CT.LedgerBalance(CUSTRDR["DEMAND"].ToString())[2];
}
CUSTCMD.Dispose();
CUSTRDR.Dispose();
CT.Dispose();
return (TotalPaid) ? TT : 0;
}
catch (Exception ex) { LogEvent.WriteErrorLog(ex); return 0; }
}
Please help...
|
|
|
|
|
As far as I can see the problem is that the connection is stored in another class, perhaps a static one. Based on this any method can dispose the connection and you would see this as a problem in the next call when the disposed connection is trying to be used. So probably the dispose happens elsewhere.
To correct this you would need to do a little bit of a re-design. I've touched this problem in Properly executing database operations[^]. Have a look at the initial version and differences in version 2. I think that clarifies the situation.
|
|
|
|
|
Hi Mika,
Although I am getting the desired result, I know removing all disposed statements is not a perfect solution.
Will you please help me to tell Where actually I should apply dispose statement.
Regards.
|
|
|
|
|
Thanks a lot Mika,
I found a solution. Actually the object SQLiteconnection was disposing and hence not giving the output while running from EXE, but this exception was not being catching while running from the IDE.
I removed all the dispose statements in my project and not its running fine.
And thanks a lot for you log file idea, it helped me a lot to detect the error.
|
|
|
|
|
Glad to be of service
I would recommend not using shared connection objects but having using statements instead as explained in the article. That would make the code much simple and robust in the long run
|
|
|
|
|
Ok dear, I will keep that in mind for my future projects.
|
|
|
|
|
Hello. Please help me to solve a problem.
I use NancyFx and for code optimisation i decided to use only OWIN SelfHost
without usage NancyFx SelfHost.
I create windows service where i place code (OnStart function)
_s7Comm = _container.Resolve<IS7Comm>();
_context = Rhs60Hub.HubContext;
_s7Comm.OnErrorEvent += S7CommOnErrorEvent;
......
var startup = _container.Resolve<Startup>();
Service = WebApp.Start("http://+:8081/", startup.Configuration);
Start service with a help of Windows Service Helper - everythin is working.
Do service stop, code (OnStop function)
_s7Comm.OnErrorEvent -= S7CommOnErrorEvent;
.....
_s7Comm.Dispose();
Service.Dispose();
start again - branch with initialise NancyFX does not start but gives exception NullReferenceException.
my Start Class for Owin
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR("/signalr", new HubConfiguration() { EnableDetailedErrors = true, EnableJSONP = true, EnableJavaScriptProxies = true });
app.UseNancy(options => options.Bootstrapper = new Bootstrapper(UnityHelper.GetConfiguredContainer())); <- error here
For test I determine start of NancyFX with a help of package NancyFx SelfHost - all is good, start, stop and restar.
(OnStart function)
_s7Comm = _container.Resolve<IS7Comm>();
_context = Rhs60Hub.HubContext;
_s7Comm.OnErrorEvent += S7CommOnErrorEvent;
......
_host = new NancyHost(new Uri("http://localhost:8082"), new Bootstrapper(_container));
_host.Start();
var startup = _container.Resolve<Startup>();
Service = WebApp.Start("http://+:8081/", startup.Configuration);
and remove string from Start class with definitions for nancyFx
Where can be a problem with usage host in OWIN?
Code debuf shows that container is initialised and all dependencies are present.
How I can discover with dependence is not present? Show you stack tracing
в Microsoft.Practices.Unity.UnityDefaultBehaviorExtension.SetLifetimeManager(
Type lifetimeType, String name, LifetimeManager lifetimeManager)\r\n
в Microsoft.Practices.Unity.UnityDefaultBehaviorExtension.OnRegisterInstance
(Object sender, RegisterInstanceEventArgs e)\r\n
в System.EventHandler`1.Invoke(Object sender, TEventArgs e)\r\n
в Microsoft.Practices.Unity.UnityContainer.RegisterInstance
(Type t, String name, Object instance, LifetimeManager lifetime)\r\n
в Microsoft.Practices.Unity.UnityContainerExtensions.RegisterInstance[TInterface](IUnityContainer container, TInterface instance, LifetimeManager lifetimeManager)\r\n
в Nancy.Bootstrappers.Unity.UnityNancyBootstrapper.RegisterBootstrapperTypes(IUnityContainer applicationContainer)\r\n
в Nancy.Bootstrapper.NancyBootstrapperBase`1.Initialise()\r\n
в Nancy.Owin.NancyMiddleware.UseNancy(NancyOptions options)\r\n
в Owin.AppBuilderExtensions.UseNancy(IAppBuilder builder, NancyOptions options)\r\n
в Owin.AppBuilderExtensions.UseNancy(IAppBuilder builder, Action`1 configuration)\r\n
в RHS60SystemService.Startup.Configuration(IAppBuilder app)
в c:\\......\\Startup.cs:строка 16" string
string 16 is
app.UseNancy(options => options.Bootstrapper = new Bootstrapper(UnityHelper.GetConfiguredContainer()));
|
|
|
|
|
You need to state the problem more simply so that other people can understand what you're asking. Try stating the problem in ONE sentence.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Can someone please help explain this error I am receiving?
I am attempting to query a REST API Webservice
When I attempt to use Newtonsoft.Json.Linq
It is being called from a button click here is the following code used
private void SearchCmd_Click(object sender, EventArgs e)
{
try
{
myDataGrid.DataSource = GetRESTData("//private//");
}
catch (WebException webex)
{
MessageBox.Show("Exception Error Detected ({0})", webex.Message);
}
}
private JArray GetRESTData(string uri)
{
{
var wRequest = (HttpWebRequest)WebRequest.Create(uri);
var wResponse = (HttpWebResponse)wRequest.GetResponse();
var reader = new StreamReader(wResponse.GetResponseStream());
string s = reader.ReadToEnd();
serviceTagInput.Text = s;
return JsonConvert.DeserializeObject<JArray>(s);
}
}
The error received is
The error throws InvalidCastException in NewtownSoft.Json.Dll
System.InvalidCastException was unhandled
HResult=-2147467262
Message=Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Newtonsoft.Json.Linq.JArray'.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) in c:\Development\Releases\Json\Working\Newtonsoft.Json\Src\Newtonsoft.Json\JsonConvert.cs:line 805
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) in c:\Development\Releases\Json\Working\Newtonsoft.Json\Src\Newtonsoft.Json\JsonConvert.cs:line 742
at DellWFApi.Form1.GetRESTData(String uri) in C:\Users\user\Documents\Visual Studio 2015\Projects\DellWFApi\DellWFApi\Form1.cs:line 55
at DellWFApi.Form1.dellSearchCmd_Click(Object sender, EventArgs e) in C:\Users\user\Documents\Visual Studio 2015\Projects\DellWFApi\DellWFApi\Form1.cs:line 37
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at DellWFApi.Program.Main() in C:\Users\user\Documents\Visual Studio 2015\Projects\DellWFApi\DellWFApi\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
|
|
|
|
|
Message=Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Newtonsoft.Json.Linq.JArray'.
That suggests that the line:
return JsonConvert.DeserializeObject<JArray>(s);
should be
return JsonConvert.DeserializeObject<JObject>(s);
Also, your return value above, s , is a string (i.e. object) rather than an array by the look of the code.
|
|
|
|
|
Thanks Rich! Much Appreciated very new to this. The JObject replacement has allowed the code to actually grab the information which is 'S' and you are correct it is a string.
Do you know of a better process to deserialize that string into the datagridview?
Right now it is still not returning the information to that datagridview.
|
|
|
|
|
Sorry, I don't really know JSON, the error message was the clue. I suggest you go back to the documentation and see if that helps.
|
|
|
|
|
Thanks Rich Ill dig deeper! Much appreciated.
|
|
|
|
|
Hi there,
I have a question, perhaps there is somebody who has done something similar.
I am need to work on something that could be a WYSWIYG (or at least partially WYSIWYG) editor of SVG elements on an xhtml files.
The background is - I've got epub books for which I have a semi-wysiwyg editor. You edit the xhtml file in one window, and the embedded browser reflects the changes live. This is for translation of the text. Now, some of the text is fancy, whirly and bendy and it is not in regular span elements, but rather in SVG:
<svg id="svgRoot" version="1.1" baseProfile="Full" width="783px" height="957px" viewBox="0 0 648 792" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">
<g clip-path="url(#clp1)" transform="matrix(1 0 0 -1 -0 792)" fill="currentColor" style="color: #F37322;">
<text transform="matrix(0.83072216 0.55668724 0.55668724 -0.83072216 165.6 449.35)" font-family="'BurbankBigRegularLight'" font-size="22"><tspan x="0" y="-0" class="ps01 ps22">Sample text bit</tspan>
</text>
</g>
</svg>
What I need to do is to edit the text (simple), but also move/twist the text visually on the page. Any idea if there's a simple and free c# library that would allow such manipulation?
Thanks!
|
|
|
|
|
when I use openssl to generate a cert and a private key which has a password, how can I use c# to use the cert to use the cert to encrypt infomation and use the key to decode information?
|
|
|
|
|
|
|