Mono: CustomAttributeExtensions - c#

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.

Related

Adding managed DLL to unity3d

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.

Mono ASP.Net MVC EntityFramework Exception

I am trying to run my MVC application based on ASP.Net with the MVC 4 technology and the EntityFramework.
public ActionResult Test()
{
DbEntities entities = new DbEntities();
ViewBag.AddressBookList = entities.ADDRESSBOOK.Take(100).ToList();
return View();
}
The problem is that I'm getting this exception when I'm calling /Home/Test. It must be caused by the EntityFramework because the whole application works except to the point when I'm trying to retrieve data of the database with the EntityFramework. When I test it within Visual Studio (IIS) it runs properly without any error.
System Informations
Windows
Net Framework 4.0
ASP .Net MVC 4
EntityFramework 6
Mono 3.2.3 (newest Windows version)
nginx FastCGI with fastcgi-mono-server4
System.UriFormatException
Invalid URI: The format of the URI could not be determined:
System.Data.Resources.SqlClient.SqlProviderServices.ProviderManifest.xml
Stacktrace
at System.Uri..ctor (System.String uriString, Boolean dontEscape) [0x00000] in <filename unknown>:0
at System.Uri..ctor (System.String uriString) [0x00000] in <filename unknown>:0
at Mono.Xml.Schema.XmlSchemaValidatingReader..ctor (System.Xml.XmlReader reader, System.Xml.XmlReaderSettings settings) [0x00000] in <filename unknown>:0
at System.Xml.XmlReader.CreateValidatingXmlReader (System.Xml.XmlReader reader, System.Xml.XmlReaderSettings settings) [0x00000] in <filename unknown>:0
at System.Xml.XmlReader.CreateFilteredXmlReader (System.Xml.XmlReader reader, System.Xml.XmlReaderSettings settings) [0x00000] in <filename unknown>:0
at System.Xml.XmlReader.Create (System.Xml.XmlReader reader, System.Xml.XmlReaderSettings settings) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.SchemaObjectModel.Schema.Parse (System.Xml.XmlReader sourceReader, System.String sourceLocation) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate (IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, System.Data.Entity.Core.SchemaObjectModel.AttributeValueNotification providerNotification, System.Data.Entity.Core.SchemaObjectModel.AttributeValueNotification providerManifestTokenNotification, System.Data.Entity.Core.SchemaObjectModel.ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate (IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, System.Data.Entity.Core.Common.DbProviderManifest providerManifest, IList`1& schemaCollection) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.SchemaObjectModel.SchemaManager.LoadProviderManifest (System.Xml.XmlReader xmlReader, System.String location, Boolean checkForSystemNamespace, System.Data.Entity.Core.SchemaObjectModel.Schema& schema) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest.Load (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest..ctor (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0
at System.Data.Entity.SqlServer.SqlProviderManifest..ctor (System.String manifestToken) [0x00000] in <filename unknown>:0
at System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifest (System.String versionHint) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifest (System.String manifestToken) [0x00000] in <filename unknown>:0
This issue is caused by Entity Framework generating invalid XML. For some reason, Microsoft's implementation of XmlReader doesn't follow the spec while Mono's does. Fortunately for most Mono users, the issue was patched in Mono nearly a year ago. You can view the pull request here:
https://github.com/mono/mono/pull/756
Unfortunately that doesn't help you since the latest version of Mono for Windows is over a year old. You can look at the issue in more depth at:
https://entityframework.codeplex.com/workitem/1632
Which may also help if you want to pull down the Entity Framework source and build from scratch with the patched code. If you can figure out the proper way, you may also be able to manually edit the offending XML so that it is valid and would no longer cause the Mono XML Reader to throw an Exception.
Of course, since you're already running on Windows, you could simply use IIS and avoid the issue completely.

System.Collections.Generic.KeyNotFoundException with Mono, but not Microsoft's .NET

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

NHibernate throws TypeLoadException under mono

I have a .Net based command line app that interacts (CRUD) with PostgreSQL 9.1. Using Nuget, the project currently references NHibernate 3.2.0.4000 and FluentHibenrate 1.3.0.717
Now the code runs fine under .Net environment (meaning Windows Xp/7), but under Mono (Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2)), I am seeing TypeLoadException within NHibernate from the exact same code (I did not re-compile anything for mono.). Can someone help and point the way? Thanks!
Here is the stack trace
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> NHibernate.MappingException: Could not compile the mapping document: (XmlDocument) ---> System.TypeInitializationException: An exception was thrown by the type initializer for NHibernate.Dialect.Dialect ---> System.TypeLoadException: Could not load type 'NHibernate.Dialect.Dialect+NoOpViolatedConstraintNameExtracter' from assembly 'NHibernate, Version=3.2.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4'.
--- End of inner exception stack trace ---
at NHibernate.Cfg.Configuration.AddDeserializedMapping (NHibernate.Cfg.MappingSchema.HbmMapping mappingDocument, System.String documentFileName) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at NHibernate.Cfg.Configuration.LogAndThrow (System.Exception exception) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.AddDeserializedMapping (NHibernate.Cfg.MappingSchema.HbmMapping mappingDocument, System.String documentFileName) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.AddValidatedDocument (NHibernate.Cfg.NamedXmlDocument doc) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.ProcessMappingsQueue () [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.AddDocumentThroughQueue (NHibernate.Cfg.NamedXmlDocument document) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.AddXmlReader (System.Xml.XmlReader hbmReader, System.String name) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.AddInputStream (System.IO.Stream xmlInputStream, System.String name) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration () [0x00000] in <filename unknown>:0
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory () [0x00000] in <filename unknown>:0
at MyProj.Repository.FluentNHibernateHelperPostgreSQL.CreateSessionFactory () [0x00000] in <filename unknown>:0
at MyProj.Repository.FluentNHibernateHelperPostgreSQL.get_SessionFactory () [0x00000] in <filename unknown>:0
at MyProj.Repository.FluentNHibernateHelperPostgreSQL.OpenSession () [0x00000] in <filename unknown>:0
at MyProj.Repository.NHibernateSessionHelper.SmartSessionFactory () [0x00000] in <filename unknown>:0
at MyProj.Repository.NHibernateSessionHelper.DoAnything (MyProj.Repository.TargetMethod target) [0x00000] in <filename unknown>:0
at MyProj.Program+<>c__DisplayClass10.<RetrieveDataDriver>b__a () [0x00000] in <filename unknown>:0
Here is the relevant code for FluentNHibernateHelperPostgreSQL.CreateSessionFactory ()
private static ISessionFactory CreateSessionFactory()
{
FluentConfiguration fluentConfiguration = Fluently.Configure();
PostgreSQLConfiguration standard = PostgreSQLConfiguration.Standard;
FluentConfiguration fluentConfiguration1 = fluentConfiguration.Database(((PersistenceConfiguration<PostgreSQLConfiguration, PostgreSQLConnectionStringBuilder>)standard).ConnectionString((PostgreSQLConnectionStringBuilder c) => c.FromConnectionStringWithKey("ConnectionStringKey")));
ISessionFactory sessionFactory = fluentConfiguration1.Mappings((MappingConfiguration m) => m.AutoMappings.Add(FluentNHibernateHelperPostgreSQL.CreateAutomappings)).ExposeConfiguration(FluentNHibernateHelperPostgreSQL.BuildSchema).BuildSessionFactory();
return sessionFactory;
}
The solution was to manually deploy the latest Mono package from go-mono.com
As suggested by knocte in the comment section, 2.11.4 solved the problem.
I haven't tried 3.x, but so far, I have been happy 2.11.x with no reason to jump into 3.x ship yet.

csproj from VS2008 fail to compile with mono xbuild

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

Categories

Resources