I have a piece of code that gets a JSON response and checks whether there is a .error field
dynamic jsonResponse = JsonConvert.DeserializeObject(responseString);
if (jsonResponse.error != null) { error = jsonResponse.error; }
else
{
success = true;
}
This runs successfully when it is not compiled with .NET Native toolchain but produces an error (on jsonResponse.error) when it's built with it.
What is the reason for this? Any other similar incompatible behavior with native code?
EDIT: It turns out that even if there is an "error" key in the JSON, we still get an error. The exception is:
System.Reflection.MissingMetadataException: ''Microsoft.CSharp.RuntimeBinder.CSharpGetMemberBinder' is missing metadata. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=392859'
The subsystem that powers the dynamic keyword has various corner cases that don't run super well on .NET Native. This particular issue was reported to us in February, you can see some discussion on the CoreFX GitHub here.
The general idea is that the dynamic keyword causes a great deal of machinery to wander through APIs and some pieces of the framework don't have the proper hinting to say "This isn't a thing you need to reflect on." Because our compiler analysis says you won't need this type at runtime but this particular component does, we end up throwing this exception.
The link in the exception is trying to help build a runtime directive (think of it as a hint to the .NET Native compiler) so that we'll know you'll need type information at runtime. For this particular case it would look like:
<Type Name="Microsoft.CSharp.RuntimeBinder.CSharpGetMemberBinder" Dynamic="Required All"/>
If you add that to the the file Properties\Default.rd.xml I would expect this error to disappear. You may hit additional errors of this type but they should be able to be addressed in a similar fashion.
We've logged a bug on our side to get this addressed at some point in the future but you'll need this workaround in the meantime.
I am getting SqlCeException in my WP8 application. The message says only:
An exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in
Microsoft.Phone.Data.Internal.ni.dll but was not handled in user code
As you can see, it is not very specific as to why did it happen. After some googling I found an advice to inspect the exception further by accessing its Errors property (link to discussion). However, I am not able to import the System.Data.SqlServerCe.SqlCeException into my code. Therefore in consequence I am not really able to access any more information about the exception. How can I import this exception to my project so I could work with it? The only idea I got was to add Entity framework, but for some reason NuGet fails to install it.
EDIT:
For further generations, I am still not able to access it, even the Reflections seems to reject messing with it (MethodAccessException thrown when I tried to access the value of Errors property of the SqlCeException). At least the SqlCeException.ToString() method returns quite a meaningful description.
You can't connect to an SQL db from Windows phone, the best way it to create a REST Web Service which connects to your db and start consuming it.
Hi i am using the vb6 code Logic in my application where i need to manage the error handling. In vb6 ADODB.Errors are used for capturing the exception.
I want to know the exception equivalent in vb.net for the Vb6 ADODB.Error codes
2147217885 (0x80040e23) A given HROW referred to a hard- or soft-deleted row.
2147217887 0x80040e21 Errors occurred
Can anyone please help to know the equivalent exception for the above two error codes
Have a look at This,
in particular the section on "Unhandled Errors in Event Handlers". It explains how to use the ADODB Errors collection in a try/catch block.
I don't think you're going to find a way to trap ADODB errors by using equivalent errors thrown in the .Net environment. There aren't one-to-one equivalencies between COM errors and .Net exceptions in general. What happens in this case with ADODB Error objects is that .Net uses interop marshaling to throw the error object into the catch block, wrapping it with the Exception object. You can evaluate the error there. However, the doc doesn't explain how you can iterate the Errors collection to see both of your errors. Perhaps you can post how that's done here once you've figured it out.
I am currently trying to figure out a way on how I can possibly save the compile time and runtime errors (in database tables) that the project/solution/website in my visual studio solution explorer could possibly throw.
Thanks for the help in advance.
Update: For now I would want to log the errors only for C# language.
I am desperately looking for a way or solution to implement this...any help will be deeply appreciated...
NiK.
Compile time errors are saved in a html buildlog, check your output window for the link. Shouldn't be too hard to put in a database. A piece of software that does use this information is CruiseControl.Net, so you could probably learn from looking at their code.
For runtime errors, it's impossible to answer. First of all, it's unclear what you are asking. By "runtime errors", do you mean exception eg divide by zero? Second, this is also very different between different languages supported in VS, eg .NET languages and straight C++.
Update: Since you're on the .NET platform, I suggest you either wrap your main function with a try/catch block that catches all thrown errors, and just log all the information you can get from that error to your database (eg stack trace, Exception kind, perhaps a minidump). This, of course, will not work with errors that are caught or swallowed. In case you would also want to log those (for whatever reason), you would have to do some more clever source transformations, for example by using reflection. An example would be to add logging to the constructor of the base class Exception.
My suggestion would be to look into developing an extension to visual studio, similar to Jetbrain's Resharper. Visual Studio exposes a rich api for interacting with the IDE itself. If you are using command line builds outside of visual studio, you may need to pipe the output to a file and parse it.
Here's a few links to get you started on developing an extension/add-in:
http://msdn.microsoft.com/en-us/library/dd885119.aspx
http://msdn.microsoft.com/en-us/vstudio/bb968855
And here's a link for a video for integrating with the error list:
http://msdn.microsoft.com/en-us/vstudio/cc563922
Runtime errors may be easier since there is an appdomain exception event that you can handle. You can wire up a handler to this event and log the exception.
http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx
For handled exceptions, there are a couple of techniques. Microsoft has an exception handling block that can be used, or you could create a custom exception type that you use throughout the application.
Sound like you want this for a website. You can create a Global class (Global.asax.vb) and then handle the error in the Application_Error event. This is where you deal with any unhandled exceptions (vb example is what I have):
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
Dim appException As System.Exception = Server.GetLastError()
Dim tempException As System.Exception = Nothing
If appException Is Nothing Then
Return
End If
tempException = appException.InnerException
tempException will hold the unhandled exception and you can store it in a database, or email it to someone. Your choice.
You can do something very similar in winform apps by handling the _unhandledException event in the Application events.
Visual Studio Project files are MSBuild files which can contain custom compilation steps. Maybe it's possible to replace the compilation step with a custom step which calls the CSharp compiler and logs the error.
If you give us a bit more information on what you want to use it for, maybe we can provide alternative solutions. For example do you need to log the errors from inside visual studio or is it enough to have an external tool log these errors?
Only the C++ compiler does a buildlog. C# does not. You will have to either go the plugin/extension route (in which case, use Dave Ferguson's suggestions to get started) or you can use the command line to compile (csc.exe) and pipe the output to a file (csc.exe /options >> log.txt), and parse it.
Specifically, we are trying to upgrade our telerik controls to the latest version. Unfortunately, the old DLL's are so old that many of the control properties have changed vastly so we've decided to upgrade only the telerik control that is giving us problems (the RadEditor control).
So the bin looks something like this:
RadChart.Net2.dll
RadEditor.Net2.dll (we want to get rid on only this one)
RadGrid.Net2.dll
RadInput.Net2.dll
RadPanelbar.Net2.d
RadSpell.NET2.dll
RadTabStrip.Net2.d
RadToolbar.Net2.dl
RadTreeView.Net2.d
RadUpload.Net2.dll
RadWindow.Net2.dll
Telerik.Web.UI.dll (this is the new DLL)
The problem is that all the namespaces and classes are the same from the old DLLs to the new one (Telerik.Web.UI).
Here is the specific error I am getting:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0433: The type 'Telerik.Charting.ChartSeries' exists in both 'c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\c6516654\63e1c826\assembly\dl3\9aa96a66\00ba04b3_fd85c701\RadChart.Net2.DLL' and 'c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\c6516654\63e1c826\assembly\dl3\8fdb0e6c\001aa55c_c4f9c901\Telerik.Web.UI.DLL'
I've considered GAC-ing the new DLL but I am uncertain that this will help the situation. Any help would be greatly appreciated.
You can use extern aliases (tutorial and reference) to differentiate between them. It's pretty annoying to have to, admittedly - obviously avoid where you can, but at least C# provides a way round it :)