System.Runtime.InteropServices.SEHException in UnityEngine.dll - c#

I am importing unity3D project for windows phone 8. and adding few lines of code which interact the c# code to the event changing handler of Object(SphereScript) in unity3D.
var sphereScript = UnityEngine.Object.FindObjectOfType<SphereScript>();
sphereScript.SphereStateChanged += sphereScript_SphereStateChanged;
sphereScript_SphereStateChanged(sphereScript.IsSphereMoving);
The project compiled fine with no errors but when it runs on phone it gives an error on line
UnityEngine.Object.FindObjectOfType<SphereScript>();
An exception of type 'System.Runtime.InteropServices.SEHException' occurred in UnityEngine.DLL but was not handled in user code. i don't know why this error occurs. but first time when i started the project it asked me to locate the file name UnityEngineObject.cs. Where can i find this file or how can i solve the problem. Thanks.
Url for complete code http://docs.unity3d.com/Manual/wp8-unity-interaction.html
Exception details:
System.Runtime.InteropServices.SEHException was unhandled by user code
HResult=-2147467259
Message=External component has thrown an exception.
Source=UnityEngine
ErrorCode=-2147467259
StackTrace:
at UnityEngine.Internal.$Calli.Invoke38(Int32 arg0, IntPtr method)
at UnityEngine.Object.FindObjectsOfType(Type type)
at UnityEngine.Object.FindObjectOfType(Type type)
at UnityEngine.Object.FindObjectOfType[T]()
at UnityXamlInteractionExample.MainPage.Unity_Loaded()
InnerException:

in Unity 5x i had equal the problem.
So try this:
In script SphereScript.cs:
re-write this:
public event Action<bool> SphereStateChanged;
to this:
public static event Action<bool> SphereStateChanged = delegate { };
next, in Visual Studio after build project un-comment these parts of code:
UnityApp.SetLoadedCallback(() => { Dispatcher.BeginInvoke(Unity_Loaded); });
private void Unity_Loaded() { }
now insert into private void Unity_Loaded() this:
ShareScript.SphereStateChanged += SphereStateChanged;
and finally add this:
void SphereStateChanged(bool currentSpehreState)
{
Dispatcher.BeginInvoke(() =>
{
SphereStateTextBlock.Text = currentSpehreState ? "Spehre is moving" : "Sphere is stopped";
});
}
Good luck, bye :)

Related

Debugging test c# Entity Framework

I have the following method in a class...
public Boolean isMemberOf(string user, int league) {
Boolean isPlayer = false;
var leaguePlayer = db.GameworldPlayers.Count();
if (leaguePlayer > 0) {
isPlayer = true;
}
return isPlayer;
}
Simply, this method will accept a player and a league and return whether or not this league has this player.
So I am writing test to test this behaviour... I realise that this test is a bit useless since I don't use user or league, but I have powered it down to at least get it to run with a simple count.
[TestFixture]
public class GameWorldTests
{
[Test]
public void logged_in_user_is_a_gameworld_player()
{
GameworldPlayerOperations gwp = new GameworldPlayerOperations();
Assert.IsFalse(gwp.isMemberOf("ewijfeiw", 1));
}
}
My test is failing... which isn't what I expected. So on debugging my test I found that the method was crashing my application with the following message:
An exception of type 'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
Additional information: An error occurred while executing the command definition. See the inner exception for details.
I have never seen a message like this before. Can anyone tell me what I'm doing wrong, please?
Thanks.

IDifferenceBuffer error - (Exception has been thrown by the target of an invocation.)

I'm making an extension in visual studio. But have an error using IElisionBuffer and IDifferenceBuffer.
Below is my code.
public ViewportAdornment1(IWpfTextView view, IProjectionBufferFactoryService projectionBufferFactory, IDifferenceBufferFactoryService differenceBufferFactory)
{
_projectionBufferFactory = projectionBufferFactory;
_differenceBufferFactory = differenceBufferFactory;
_view = view;
NormalizedSnapshotSpanCollection span = new NormalizedSnapshotSpanCollection(_view.TextSnapshot, new Span(5, 10));
_buffer = _projectionBufferFactory.CreateElisionBuffer(null, span, ElisionBufferOptions.FillInMappingMode);
IProjectionSnapshot snapshot = _buffer.ElideSpans(span);
IDifferenceBuffer differenceBuffer = _differenceBufferFactory.CreateDifferenceBuffer(_view.VisualSnapshot.TextBuffer, snapshot.TextBuffer);
differenceBuffer.SnapshotDifferenceChanged += ApplySnapshotDifference;
}
private void ApplySnapshotDifference(object sender, SnapshotDifferenceChangeEventArgs e)
{
ISnapshotDifference snapshotDifference = e.After.DifferenceBuffer.CurrentSnapshotDifference;
var diffs = snapshotDifference.LineDifferences;
ITextEdit edit = _buffer.CreateEdit(EditOptions.DefaultMinimalChange, null, "myedit");
foreach (var diff in diffs)
{
edit.Replace(diff.Left, diff.After.ToString());
}
edit.Apply();
}
Below seems make internal exception but i don't know what's wrong.
IDifferenceBuffer differenceBuffer = _differenceBufferFactory.CreateDifferenceBuffer(_view.VisualSnapshot.TextBuffer, snapshot.TextBuffer);
https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k(Microsoft.VisualStudio.Text.Differencing.IDifferenceBuffer);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(DevLang-csharp)&rd=true
MSDN remarks : "The differences are computed on a background thread in
response to various changes (text change, options changing, etc.),
though all of the events around differencing, like
SnapshotDifferenceChanged, will be raised on the thread that owns the
LeftBuffer and RightBuffer (generally, the UI thread)."
(I can't upload images) error popup says :
An unhandled exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an
invocation.
P.S.
My goal is making an adornment box that is linked to some text, like error popup (but replaces text). Is there any easier way to implement this than using IElisionBuffer?

GeckoDocument.CreateEvent throws an exception

I have a GeckoFX 29 GeckoWebBrowser in my C# application.
I navigate successfully to a webpage and I have an element that doesn't accept a simple "click()" and so I have to forcefully dispatch events.
The problem is that when I try to create the event the GeckoFX core throws an exception.
var eventName = "mouseover";
var domEvent = browser.DomDocument.CreateEvent(eventName);
domEvent.DomEvent.InitEvent(new nsAString(eventName), true, true);
The exception is thrown at CreateEvent(eventName) and the exception is this:
System.Runtime.InteropServices.COMException (0x80530009): Exception from HRESULT : 0x80530009
at Gecko.nsIDOMDocument.CreateEvent(nsAStringBase eventType)
at Gecko.nsString.GenericPass[T,TString](Func`2 func, String value) in c:\Users\micro_000\Documents\Visual Studio 2008\Projects\geckofx-29.0\Geckofx-Core\nsString.cs:line 221
at Gecko.nsString.Pass[T](Func`2 func, String value) in c:\Users\micro_000\Documents\Visual Studio 2008\Projects\geckofx-29.0\Geckofx-Core\nsString.cs:line 476
at Gecko.GeckoDomDocument.CreateEvent(String name) in c:\Users\micro_000\Documents\Visual Studio 2008\Projects\geckofx-29.0\Geckofx-Core\DOM\GeckoDomDocument.cs:line 155
at MyApp.Window.createEvent(GeckoDocument doc, String eventName)
I tried to look into the source code, but nsIDOMDocument is just an interface and there is no other information available for this issue that I can find.
It turns out that CreateEvent accepts only a few strings.
Because it didn't work I was trying to dispatch the events by calling a java script that I was going to insert in the document. Researching that I noticed that CreateEvent was used with the parameter "Events" and then you would init your event with the actual event name.
So far I found out that params that work with CreateEvent are "Events", "MouseEvent", "KeyboardEvent".
This code works:
var eventName = "mouseover";
var domEvent = browser.DomDocument.CreateEvent("MouseEvent");
domEvent.DomEvent.InitEvent(new nsAString(eventName), true, true);

Type initialization exception

I created imageHolder class:
public class ImageHolder : Image<Bgr, Byte>
{
private String imagePath;
public ImageHolder(String path):base(path)
{
this.imagePath = path;
}
public String imgPathProperty
{
get
{ return imagePath; }
set
{ imagePath = value; }
}
}
I create instance of the class and initialize it,like this:
private ImageHolder originalImageHolder;
originalImageHolder = new ImageHolder(openFileDialog.FileName);
In runtime i get this exception:
The type initializer for 'Emgu.CV.CvInvoke' threw an exception.
Here is Solution Explorer window:
Any idea why i get this exception and how can i fix it?
Thank you in advance.
The TypeInitializationException (the exception that you are seeing) is thrown whenever a static constructor throws an exception, or whenever you attempt to access a class where the static constructor threw an exception - its InnerException property is the property that contains the detail of the exception that was actualy thrown - this is the exception that you need to investigate.
In this case from your screenshot the problem appears to be that the DLL "opencv_core240.dll" could not be found. This could be for a number of reasons
The DLL couldn't be found
One of the dependencies of the DLL could not be found
The DLL was in the incorrect image format (32 bit as opposed to 64 bit)
I'd suggest that you take a look at this question to see if any of the suggestions on there help you.
Checking this field did the trick for me. Under Project→ Properties→ Build (Main/Startup project)
I solved the problem by reinstalling MSVCRT 9.0 SP1 x86

RegistryTreeChangeEvent via C# & WMI

I'm getting this error:
Unhandled Exception: System.Runtime.InteropServices.COMException (0x80042001): Exception from HRESULT: 0x80042001
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Management.ManagementEventWatcher.Start()
at MyNamespace.Program.Main(String[] args) in {somedir}\Program.cs:line 16
And here's my C# console app that I'm using to watch the registry:
using System;
using System.Management;
namespace MyNamespace
{
class Program
{
static void Main(string[] args)
{
var watcher = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM RegistryTreeChangeEvent"));
var handler = new MyHandler();
watcher.EventArrived += handler.Arrived;
//Start watching for events
watcher.Start();
while (handler.EventHasntFiredYet)
{
// Nothing.
}
//Stop watching
watcher.Stop();
}
public class MyHandler
{
public bool EventHasntFiredYet;
public MyHandler()
{
EventHasntFiredYet = true;
}
public void Arrived(object sender, EventArrivedEventArgs e)
{
var propertyDataCollection = e.NewEvent.Properties;
foreach (var p in propertyDataCollection)
{
Console.WriteLine("{0} -- {1}",p.Name,p.Value);
}
EventHasntFiredYet = false;
}
}
}
}
I'm trying to simply watch the registry for changes. Does anyone have any suggestions as to why this is failing?
It is an internal WMI error, WBEMESS_E_REGISTRATION_TOO_BROAD, "The provider registration overlaps with the system event domain."
That's about a good an error message as you'd ever get out of COM. Striking how much better the .NET exception messages are. Anyhoo, I'm fairly sure that what it means is "you are asking for WAY too many events". You'll have to be more selective in your query, use the WHERE clause. Like:
SELECT * FROM RegistryTreeChangeEvent
WHERE Hive='HKEY_LOCAL_MACHINE' AND
'RootPath='SOFTWARE\Microsoft'
Prompted by Giorgi, I found the MSDN page that documents the problem:
The following is an example of an incorrect registration.
SELECT * FROM RegistryTreeChangeEvent
WHERE hive = hkey_local_machine" OR
rootpath ="software"
Because there is no way to evaluate the possible values for each of the properties, WMI rejects with the error WBEM_E_TOO_BROAD any query that either does not have a WHERE clause or if the WHERE clause is too broad to be of any use.
As Hans has told you are receiving the error because you haven't specified where clause. According to Creating a Proper WHERE Clause for the Registry Provider you must specify where clause otherwise you will receive WBEM_E_TOO_BROAD error.
To simplify your code and not to reinvent the wheel you can use the following library: Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET

Categories