Just started getting this compiler error:
Internal compiler error. See the console log for more information. output
was:
Unhandled Exception: System.InvalidCastException: Cannot cast from source type to destination type.
at Mono.CSharp.PendingImplementation.BaseImplements (System.Type iface_type, System.Reflection.MethodInfo mi, System.Reflection.MethodInfo& base_method) [0x00000] in <filename unknown>:0
at Mono.CSharp.PendingImplementation.VerifyPendingMethods (Mono.CSharp.Report Report) [0x00000] in <filename unknown>:0
at Mono.CSharp.TypeContainer.EmitType () [0x00000] in <filename unknown>:0
at Mono.CSharp.RootContext.EmitCode () [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
I was casting a component to an interface type, which was working fine (compiling and working right at runtime). I did the same in another method and this started, I quickly reverted my changes to the method and this error continues. I am honestly not sure how to resolve it, and google was not bringing up a whole lot of useful information.
Unity 4.6.3
Let me know if you need more information. Or if this is the wrong place to ask for assistance. Any ideas?
Edit: Going through and systematically removing my casts from Component to IPlayerObject (which is an interface).
Related
I use the method GetCustomAttributes from the extension class CustomAttributeExtensions:
var serviceInterface = service.GetInterfaces().FirstOrDefault(i => i.GetCustomAttributes().Contains(new ServiceContractAttribute()));
When I run my application under mono 4.0 on debian I get the following exception:
Missing method GetCustomAttributes in assembly /root/mkmServer/MKMWatcher.Services.exe, type System.Reflection.CustomAttributeExtensions
Unhandled Exception: System.TypeLoadException: Could not load type 'System.Reflection.CustomAttributeExtensions' from assembly 'MKMWatcher.Services'.
at System.Linq.Enumerable.First[Type] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.FirstOrDefault[Type] (IEnumerable`1 source, System.Func`2 predicate) [0x00000] in <filename unknown>:0
at MKMWatcher.Services.ServiceManager.CreateService (System.Type service, System.String serviceAddress) [0x00000] in <filename unknown>:0
at MKMWatcher.Services.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'System.Reflection.CustomAttributeExtensions' from assembly 'MKMWatcher.Services'.
at System.Linq.Enumerable.First[Type] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.FirstOrDefault[Type] (IEnumerable`1 source, System.Func`2 predicate) [0x00000] in <filename unknown>:0
at MKMWatcher.Services.ServiceManager.CreateService (System.Type service, System.String serviceAddress) [0x00000] in <filename unknown>:0
at MKMWatcher.Services.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
When I decompile the mscorlib.dll from mono which should contain the class I don't find it in his namespace:
But when I take a look at the mono github repository, the class is present: https://github.com/mono/mono/blob/master/mcs/class/referencesource/mscorlib/system/reflection/CustomAttributeExtensions.cs
Do you know what's happening ? Are the assemblies deployed in the latest version of mono not reflecting... their source code ? The file haven't been touched for a while and it's not like it was a new feature... Any ideas ? Any solution that does not involve for me to get the latest mono source and compile them by hand ?
Thank you in advance for you answers.
I'm trying to implement the $p library to recognize gestures for spell casting in a game but I'm getting a Unhandled Exception. I'm using the precompile dll I got from their website and its compiled in the .Net 4 framework, so I'm guessing this is where the problem is coming from. Here is the error:
Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0
at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0
at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0
at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
Missing method .ctor in assembly C:\Users\Uri\Desktop\GestureSpell\GestureSpell\Assets\PDollarGestureRecognizer.dll, type System.Runtime.Versioning.TargetFrameworkAttribute
The class System.Runtime.Versioning.TargetFrameworkAttribute could not be loaded, used in PDollarGestureRecognizer
Can't find custom attr constructor image: C:\Users\Uri\Desktop\GestureSpell\GestureSpell\Assets\PDollarGestureRecognizer.dll mtoken: 0x0a00000d
You can try changing true to false in your .csproj file. That helps in some cases.
We're creating a game for iOS and android using Unity3d (version 5.0.1p1), and since we are using Parse.com data services we naturally went with it to implement the remote push notifications.
The problem is that after building the game and running it on a test device (iPhone 4s iOS8.1.2) we get at game start an execution engine exception that we cant figure out. Here is the exception :
ExecutionEngineException: Attempting to call method
'System.Reflection.MonoProperty::StaticGetterAdapterFrame' for which no ahead of time (AOT) code was
generated.
at System.Reflection.EventInfo+AddEventAdapter.Invoke (System.Object
_this, System.Delegate dele)
[0x00000] in <filename unknown>:0
at System.Reflection.MonoProperty+GetterAdapter.Invoke (System.Object
_this) [0x00000] in <filename
unknown>:0
at AOGenerator.BlurBuffer () [0x00000] in <filename unknown>:0
at System.Reflection.MonoProperty.GetValue (System.Object obj, System.Object[] index) [0x00000] in
<filename unknown>:0
at Newtonsoft.Json.Bson.BsonRegex.get_Type () [0x00000] in <filename unknown>:0
at Parse.ParseInstallation.get_Badge () [0x00000] in <filename unknown>:0
at Parse.ParseInstallation.SetPlatformAutomaticValue () [0x00000] in <filename unknown>:0
at Parse.ParseInstallation.SetAutomaticValues () [0x00000] in <filename unknown>:0
at Parse.ParseInstallation.SaveAsync (System.Threading.Tasks.Task toAwait, CancellationToken
cancellationToken) [0x00000] in <filename unknown>:0
at Parse.PlatformHooks+<>c__DisplayClass38.<RequestAsync>b__33 (System.Threading.Tasks.Task`1 _)
[0x00000] in <filename unknown>:0
at Parse.ParseObject+<>c__DisplayClass18.<SaveAsync>b__17 (System.Threading.Tasks.Task toAwait)
[0x00000] in <filename unknown>:0
at FlurryAnalyticsIOS.SetSessionTimeout (Int32 seconds) [0x00000] in <filename unknown>:0
at
System.Collections.Generic.Dictionary`2[System.Int64,System.Boolean].Do_ICollectionCopyTo[KeyValuePair`2]
(System.Array array, Int32 index, System.Collections.Generic.Transform`1 transform) [0x00000] in <filename
unknown>:0
at Parse.Internal.TaskQueue.Enqueue[Task] (System.Func`2 taskStart, CancellationToken cancellationToken)
[0x00000] in <filename unknown>:0
at Parse.ParseObject.SaveAsync (CancellationToken cancellationToken) [0x00000] in <filename unknown>:0
at Parse.ParseObject.SaveAsync () [0x00000] in <filename unknown>:0
at Parse.ParseInitializeBehaviour.<Awake>b__0 (System.Byte[] deviceToken) [0x00000] in <filename
unknown>:0
at FlurryAnalyticsIOS.SetSessionTimeout (Int32 seconds) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Bson.BsonRegex.get_Type () [0x00000] in <filename unknown>:0
at Parse.PlatformHooks+<>c__DisplayClass24.<RegisterDeviceTokenRequest>b__22 () [0x00000] in
<filename unknown>:0
at System.Action.Invoke () [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Bson.BsonRegex.get_Type () [0x00000] in <filename unknown>:0
at Parse.PlatformHooks+<RunDispatcher>d__44.MoveNext () [0x00000] in <filename unknown>:0
at System.Nullable`1[System.DateTimeOffset].ToString () [0x00000] in <filename unknown>:0
System.Nullable`1:ToString()
UnityEngine.Debug:Internal_LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
Parse.<RunDispatcher>d__44:MoveNext()
System.Nullable`1:ToString()
The problem just appeared with the new Unity Parse SDK 1.5 (which contains the PNS feature). What we know is that running an empty project with just the parse sdk goes fine and the notifications work just fine, but in our actual project, because of the exception, devices dont register for the notifications in parse, so we are assuming there is a kind of a conflict between parse and one of the other tools we are using.
FYI : We are building the game using IL2CPP for a universal architecture (we re also building with .Net 2.0 subset, but I dont think that this has something to do with the problem).
Thank you for your time and for your answers.
UPDATE ::
We tried to build using Mono(2.x) this time and we have pretty much the same exception that turned into this :
ExecutionEngineException: Attempting to JIT compile method
'System.Reflection.MonoProperty:StaticGetterAdapterFrame
(System.Reflection.MonoProperty/StaticGetter`1,object)' while
running with aotonly.
at System.Reflection.MonoProperty.GetValue (System.Object obj,
System.Object[] index)
[0x00000] in :0
at Parse.ParseInstallation.get_Badge () [0x00000] in :0
at Parse.ParseInstallation.SetPlatformAutomaticValue () [0x00000] in
unknown>:0
at Parse.ParseInstallation.SetAutomaticValues () [0x00000] in
:0
at Parse.ParseInstallation.SaveAsync (System.Threading.Tasks.Task
toAwait,
CancellationToken cancellationToken) [0x00000] in :0
at Parse.ParseObject+<>c__DisplayClass18.b__17
(System.Threading.Tasks.Task toAwait) [0x00000] in :0
at Parse.Internal.TaskQueue.Enqueue[Task] (System.Func`2 taskStart,
CancellationToken
cancellationToken) [0x00000] in :0
at Parse.ParseObject.SaveAsync (CancellationToken cancellationToken)
[0x00000] in
:0
at Parse.ParseObject.SaveAsync () [0x00000] in :0
at Parse.ParseInitializeBehaviour.b__0 (System.Byte[]
deviceToken) [0x00000] in
:0
at
Parse.PlatformHooks+<>c__DisplayClass24.b__22
()
[0x00000] in :0
at Parse.PlatformHooks+d__44.MoveNext () [0x00000] in
unknown>:0
UnityEngine.Debug:Internal_LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
Parse.d__44:MoveNext()
Hopes it bring you guys more details about the problem.
Update 2 ::
We know exactly what causes the exception to happen and unfortunately we have no control over it, its when we register for notification, we do it this way :
using NotificationServices = UnityEngine.iOS.NotificationServices;
using NotificationType = UnityEngine.iOS.NotificationType;
/*
.
.
.
*/
void ACalledFunction ()
{
// Ask for permission for push notifications (Can Receive deviceToken)
#if UNITY_IPHONE
NotificationServices.RegisterForNotifications(
NotificationType.Alert |
NotificationType.Badge |
NotificationType.Sound);
#endif
}
}
UPDATE 15/06/2015 : Parse Unity SDK 1.5.1 (il2cpp scripting backend)
We re still having the same error when trying to register for parse PNs :
ExecutionEngineException: Attempting to call method
'System.Reflection.MonoProperty::StaticGetterAdapterFrame' for which
no ahead of time (AOT) code was generated.
System.Reflection.MonoProperty+GetterAdapter.Invoke (System.Object
_this) System.Reflection.MonoProperty+GetterAdapter.Invoke (System.Object _this) CurvedText.OnRectTransformDimensionsChange ()
System.Reflection.MonoProperty.GetValue (System.Object obj,
System.Object[] index)
Newtonsoft.Json.Bson.BsonString.set_IncludeLength (Boolean value)
Parse.ParseInstallation.get_Badge ()
Parse.ParseInstallation.SetPlatformAutomaticValue ()
Parse.ParseInstallation.SetAutomaticValues ()
Parse.ParseInstallation.SaveAsync (System.Threading.Tasks.Task
toAwait, CancellationToken cancellationToken)
Parse.PlatformHooks+<>c__DisplayClass42.b__36 (System.Object _)
Parse.ParseObject+<>c__DisplayClass18.b__17
(System.Threading.Tasks.Task toAwait)
FlurryAnalyticsIOS.SetSessionTimeout (Int32 seconds)
Parse.ParseObject.SetProperty[ParseACL] (Parse.ParseACL value,
System.String propertyName) Parse.Internal.TaskQueue.Enqueue[Task]
(System.Func2 taskStart, CancellationToken cancellationToken)
Parse.ParseObject.SaveAsync (CancellationToken cancellationToken)
Parse.ParseObject.SaveAsync () Parse.ParseInitializeBehaviour.b__0
(System.Byte[] deviceToken) FlurryAnalyticsIOS.SetSessionTimeout
(Int32 seconds) Newtonsoft.Json.Bson.BsonString.set_IncludeLength
(Boolean value) Parse.PlatformHooks+<>c__DisplayClass24.b__22 ()
System.Action.Invoke ()
Newtonsoft.Json.Bson.BsonString.set_IncludeLength (Boolean value)
Parse.PlatformHooks+d__44.MoveNext ()
System.Array+InternalEnumerator1[System.UInt64].get_Current ()
UnityEngine.Debug:LogException(Exception) Parse.d__44:MoveNext()
System.InternalEnumerator`1:get_Current()
It is possible to use reflection with AOT builds (both using the Mono scripting backend and the IL2CPP scripting backend). The restriction is really on using anything in the System.Reflection.Emit namespace.
Some parts of the mscorlib.dll assembly that ship with the Unity version of Mono are not friendly to AOT code paths, and System.Reflection.MonoProperty::StaticGetterAdapterFrame is one of them. This code won't work with an AOT build, but unfortunately it is not something that Unity can determine at compile time, so the error will only happen at runtime.
This is probably an issue to bring up on the Parse SDK forums. It may be that the SDK can be used differently to avoid this issue.
I found a really strange problem while creating unit tests that only occurs with the Mono runtime (Xamarin on Mac included), but runs fine within Visual Studio. I isolated it as far as I could, and I reached a point that I can't tell if it is a bug with Mono, Moq or Castle DinamicProxy, although it only crashes when using the Mono runtime.
This is the code:
using System;
using System.Collections.Generic;
using Moq;
namespace ConsoleApplication1
{
public interface ISomething<T>
{
List<T> DoSomething<U>(/*Func<T, U> expression*/);
}
public class Foo { }
public class Program
{
public static void Main(string[] args) {
var mock = new Mock<ISomething<Foo>>();
Console.WriteLine(mock.Object);
}
}
}
Here's that I know:
It compiles and run with within Visual Studio 2012. The output is "Castle.Proxies.ISomething`1Proxy"
It does not work when running with the Mono runtime. An exception is thrown (see below)
If I change the declaration from an interface to an abstract class, it works with Mono
If I change the return type from List<T> to anything else, it works with Mono
If I remove the generic type <U>, it works with mono
Got the same results under Windows, Mac and Linux using the command line build from http://mono-project.com
In Windows it fails with Mono 2.10.9, but works within Xamarin.Studio (4.0.10)
In Mac, it fails within Xamarin.Studio (4.0.10)
I recompiled Moq linking agains the latest DynamicProxy release (Castle.Core.3.2.0), with no changed to the behaviour.
Although I've found this problem when using Moq, but I can't tell if it's related to it or even DynamicProxy. The partial exception is below, complete can be found at http://pastie.org/8203093
mono ConsoleApplication1.exe
[ERROR] FATAL UNHANDLED EXCEPTION: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2[System.String,System.Reflection.Emit.GenericTypeParameterBuilder].get_Item (System.String key) [0x00000] in <filename unknown>:0
at Castle.DynamicProxy.Internal.TypeUtil.CloseGenericParametersIfAny (Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter emitter, System.Type[] arguments) [0x00000] in <filename unknown>:0
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget (System.Type interfaceToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.IInterceptor[] interceptors) [0x00000] in <filename unknown>:0
at Moq.Proxy.CastleProxyFactory.CreateProxy[ISomething`1] (ICallInterceptor interceptor, System.Type[] interfaces, System.Object[] arguments) [0x00000] in <filename unknown>:0
[....]
at Moq.Mock`1[ConsoleApplication1.ISomething`1[ConsoleApplication1.Foo]].<InitializeInstance>b__0 () [0x00000] in <filename unknown>:0
at Moq.PexProtector.Invoke (System.Action action) [0x00000] in <filename unknown>:0
at Moq.Mock`1[ConsoleApplication1.ISomething`1[ConsoleApplication1.Foo]].InitializeInstance () [0x00000] in <filename unknown>:0
at Moq.Mock`1[ConsoleApplication1.ISomething`1[ConsoleApplication1.Foo]].OnGetObject () [0x00000] in <filename unknown>:0
at Moq.Mock.GetObject () [0x00000] in <filename unknown>:0
at Moq.Mock.get_Object () [0x00000] in <filename unknown>:0
at Moq.Mock`1[ConsoleApplication1.ISomething`1[ConsoleApplication1.Foo]].get_Object () [0x00000] in <filename unknown>:0
at ConsoleApplication1.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
I use Mono 2.6.4 compiled from source on CentOS to compile a VS2008 project in C#.
Some csproj compile, but this one doesn't, here is the output of xbuild /t:detailed :
/opt/mono-2.6.4/lib/mono/2.0/Microsoft.CSharp.targets: error : Error executing task Csc: Input string was not in the correct format
Error executing task Csc: System.FormatException: Input string was not in the correct format
at System.Int32.Parse (System.String s) [0x00000] in <filename unknown>:0
at Microsoft.Build.Utilities.ToolTask.ParseOrigin (System.String origin, System.String& filename, System.Int32& lineNumber, System.Int32& columnNumber, System.Int32& endLineNumber, System.Int32& endColumnNumber) [0x00000] in <filename unknown>:0
at Microsoft.Build.Utilities.ToolTask.LogEventsFromTextOutput (System.String singleLine, MessageImportance importance) [0x00000] in <filename unknown>:0
at Microsoft.Build.Utilities.ToolTask.ProcessOutputFile (System.String filename, MessageImportance importance) [0x00000] in <filename unknown>:0
at Microsoft.Build.Utilities.ToolTask.ExecuteTool (System.String pathToTool, System.String responseFileCommands, System.String commandLineCommands) [0x00000] in <filename unknown>:0
at Microsoft.Build.Utilities.ToolTask.Execute () [0x00000] in <filename unknown>:0
at Microsoft.Build.BuildEngine.TaskEngine.Execute () [0x00000] in <filename unknown>:0
at Microsoft.Build.BuildEngine.BuildTask.Execute () [0x00000] in <filename unknown>:0
Task "Csc" execution -- FAILED
Done building target "CoreCompile" in project "/mnt/virtualbox/Project/(API)/Base/Base.csproj".-- FAILED
OnError for target CoreBuild skipped due to false condition: '$(RunPostBuildEvent)' == 'Always' or '$(RunPostBuildEvent)' == 'OnOutputUpdated'
Target _GetCompileOutputsForClean:
Done building target "_GetCompileOutputsForClean" in project "/mnt/virtualbox/Project/(API)/Base/Base.csproj".
Target _RecordCleanFile:
Done building target "_RecordCleanFile" in project "/mnt/virtualbox/Project/(API)/Base/Base.csproj".
Done building project "/mnt/virtualbox/Project/(API)/Base/Base.csproj".-- FAILED
Anyone has an idea ? Thanks ?
This might already be fixed in svn. I changed that code to use regex some time back. Could you try this with a mono daily build [1]? Or just file a bug with the project file and i'll check it.
http://mono.ximian.com/daily/
It's probably a bug in xbuild. File a bug with a test case to get it fixed:
http://www.mono-project.com/Bugs