Re: [Mono-dev] Patch 1/2 - System.Diagnostics.Contracts in corlib

2010-06-16 Thread Chris Bacon

Hi,

Attached is a new, improved, patch that keeps existing formatting.
Sorry for the mistake.

Kind regards
Chris

Marek Safar wrote:

Hi Chris,


Attached is a patch to corlib containing updates the 
System.Diagnostics.Contracts as part of the GSoC work I am doing.


I'm sure there will be parts of this I haven't done quite right, so 
please let me know what they are, and I'll sort them out.
Can you keep existing formatting, most of the changes are about 
changing tabs to spaces. Please send a new set of patches without any 
noise (lines you have not changed)


Thanks
Marek
Index: ChangeLog
===
--- ChangeLog   (revision 159003)
+++ ChangeLog   (working copy)
@@ -1,3 +1,7 @@
+2010-06-16  Chris Bacon 
+
+   * corlib.dll.sources: Add files required for Code Contracts.
+
 2010-05-23  Carlos Alberto Cortez 
 
* corlib.dll.sources: Add System.IO.IsolatedStorageSecurityState.cs
Index: corlib.dll.sources
===
--- corlib.dll.sources  (revision 159003)
+++ corlib.dll.sources  (working copy)
@@ -331,14 +331,17 @@
 System.Diagnostics.Contracts/Contract.cs
 System.Diagnostics.Contracts/ContractClassAttribute.cs
 System.Diagnostics.Contracts/ContractClassForAttribute.cs
+System.Diagnostics.Contracts/ContractException.cs
 System.Diagnostics.Contracts/ContractFailedEventArgs.cs
 System.Diagnostics.Contracts/ContractFailureKind.cs
 System.Diagnostics.Contracts/ContractInvariantMethodAttribute.cs
 System.Diagnostics.Contracts/ContractPublicPropertyNameAttribute.cs
 System.Diagnostics.Contracts/ContractReferenceAssemblyAttribute.cs
 System.Diagnostics.Contracts/ContractRuntimeIgnoredAttribute.cs
+System.Diagnostics.Contracts/ContractShouldAssertException.cs
 System.Diagnostics.Contracts/ContractVerificationAttribute.cs
 System.Diagnostics.Contracts/PureAttribute.cs
+System.Diagnostics.Contracts/Internal/ContractHelper.cs
 System.Diagnostics.SymbolStore/ISymbolBinder.cs
 System.Diagnostics.SymbolStore/ISymbolBinder1.cs
 System.Diagnostics.SymbolStore/ISymbolDocument.cs
Index: System.Diagnostics.Contracts/Contract.cs
===
--- System.Diagnostics.Contracts/Contract.cs(revision 159003)
+++ System.Diagnostics.Contracts/Contract.cs(working copy)
@@ -3,8 +3,9 @@
 //
 // Authors:
 //Miguel de Icaza (mig...@gnome.org)
+//Chris Bacon (chrisbaco...@gmail.com)
 //
-// Copyright 2009 Novell (http://www.novell.com)
+// Copyright 2009, 2010 Novell (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -26,30 +27,15 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-//
-// Things left to do:
-// 
-//   * This is a blind implementation from specs, without any testing, so the 
escalation
-// is probably broken, and so are the messages and arguments to the 
eventargs properties
-//
-//   * How to plug the original condition into the Escalate method?   Perhaps 
we need
-// some injection for it?
-//
-//   * The "originalException" in Escalate is nowhere used
-//
-//   * We do not Escalate everything that needs to be, perhaps that is the 
role of the
-// rewriter to call Escalate with the proper values?
-//
-//   * I added a "new()" constraint to methods that took a TException because 
I needed
-// to new the exception, but this is perhaps wrong.
-//
-//   * Result and ValueAtReturn, I need to check what these do in .NET 4, but 
have not
-// installed it yet ;-)
-//
 using System;
 using System.Collections.Generic;
+using System.Diagnostics.Contracts.Internal;
 
 namespace System.Diagnostics.Contracts {
+
+   /// 
+   /// Contains methods that allow various contracts to be specified in 
code.
+   /// 
 #if NET_2_1 || NET_4_0
public
 #else
@@ -58,38 +44,90 @@
 
static class Contract {
 
+   /// 
+   /// Called on any contract failure.
+   /// 
public static event EventHandler 
ContractFailed;
 
-   static void Escalate (ContractFailureKind kind, Exception e, 
string text, params object [] args)
+   // Used in test
+   internal static EventHandler 
InternalContractFailedEvent
{
-   if (ContractFailed != null){
-   var ea = new ContractFailedEventArgs (kind, 
text, "", e ?? new Exception ());
-   ContractFailed (null, ea);
-   if (!ea.Unwind)
-   return;
+   get { return ContractFailed; }
+   }
+
+   // Used in test
+   internal static Type GetContractExceptionType ()
+   {
+   return typeof (ContractException);
+

Re: [Mono-dev] Patch 2/2 - Tests for System.Diagnostics.Contracts in corlib

2010-06-16 Thread Chris Bacon

Hi,
I've attached a new patch with slightly better formatting - it uses tabs 
rather than spaces.

Kind regards
Chris

Chris Bacon wrote:

Hi,

Here are the tests to add to corlib for System.Diagnostics.Contracts.

Please let me know what changes are required.

Kind regards
Chris


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list
Index: corlib_test.dll.sources
===
--- corlib_test.dll.sources (revision 159003)
+++ corlib_test.dll.sources (working copy)
@@ -60,6 +60,14 @@
 System.Diagnostics/StackFrameTest.cs
 System.Diagnostics/StackTraceTest.cs
 System.Diagnostics/TextWriterTraceListenerTest.cs
+System.Diagnostics.Contracts/ContractAssertTest.cs
+System.Diagnostics.Contracts/ContractAssumeTest.cs
+System.Diagnostics.Contracts/ContractCollectionMethodsTest.cs
+System.Diagnostics.Contracts/ContractHelperTest.cs
+System.Diagnostics.Contracts/ContractMarkerMethodsTest.cs
+System.Diagnostics.Contracts/ContractMustUseRewriterTest.cs
+System.Diagnostics.Contracts/Helpers/RunAgainstReferenceAttribute.cs
+System.Diagnostics.Contracts/Helpers/TestContractBase.cs
 System/DoubleFormatterTest.cs
 System/DoubleTest.cs
 System/EnumTest.cs
Index: Test/System.Diagnostics.Contracts/ContractAssumeTest.cs
===
--- Test/System.Diagnostics.Contracts/ContractAssumeTest.cs (revision 0)
+++ Test/System.Diagnostics.Contracts/ContractAssumeTest.cs (revision 0)
@@ -0,0 +1,45 @@
+#define CONTRACTS_FULL
+#define DEBUG
+
+#if NET_4_0
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using System.Diagnostics.Contracts;
+using MonoTests.System.Diagnostics.Contracts.Helpers;
+
+namespace MonoTests.System.Diagnostics.Contracts {
+
+   [TestFixture]
+   public class ContractAssumeTest : TestContractBase {
+
+   /// 
+   /// At runtime Contract.Assume() acts just like a 
Contract.Assert(), except the exact message in the assert
+   /// or exception is slightly different.
+   /// 
+   [Test]
+   public void TestAssumeMessage ()
+   {
+   try {
+   Contract.Assume (false);
+   Assert.Fail ("TestAssumeMessage() exception not 
thrown #1");
+   } catch (Exception ex) {
+   Assert.IsInstanceOfType 
(typeof(NotImplementedException), ex, "TestAssumeMessage() wrong exception type 
#1");
+   }
+
+   try {
+   Contract.Assume (false, "Message");
+   Assert.Fail ("TestAssumeMessage() exception not 
thrown #1");
+   } catch (Exception ex) {
+   Assert.IsInstanceOfType 
(typeof(NotImplementedException), ex, "TestAssumeMessage() wrong exception type 
#1");
+   }
+   }
+
+   // Identical to Contract.Assert, so no more testing required.
+
+   }
+
+}
+#endif

Property changes on: Test/System.Diagnostics.Contracts/ContractAssumeTest.cs
___
Added: svn:eol-style
   + native

Index: Test/System.Diagnostics.Contracts/ContractCollectionMethodsTest.cs
===
--- Test/System.Diagnostics.Contracts/ContractCollectionMethodsTest.cs  
(revision 0)
+++ Test/System.Diagnostics.Contracts/ContractCollectionMethodsTest.cs  
(revision 0)
@@ -0,0 +1,127 @@
+#define CONTRACTS_FULL
+#define DEBUG
+
+#if NET_4_0
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using MonoTests.System.Diagnostics.Contracts.Helpers;
+using System.Diagnostics.Contracts;
+
+namespace MonoTests.System.Diagnostics.Contracts {
+
+   [TestFixture]
+   public class ContractCollectionMethodsTest {
+
+   /// 
+   /// Contract.Exists() determines that at least one element in 
the collection satisfies the predicate.
+   /// 
+   [Test, RunAgainstReference]
+   public void TestExistsInt ()
+   {
+   try {
+   Contract.Exists (0, 10, null);
+   Assert.Fail ("TestExistsInt() no exception #1");
+   } catch (Exception ex) {
+   Assert.IsInstanceOfType (typeof 
(ArgumentNullException), ex, "TestExistsInt() wrong exception #1");
+   }
+
+   try {
+   Contract.Exists (10, 0,

[Mono-dev] c# compiler problem with generics and derived interfaces

2010-06-16 Thread matteo tesser
Hello,
I cannot compile the code reported below with mono 2.6.4 (which
compiles fine using visual studio 2008).

By executing  gmcs MatrixArray.cs (see below or attached file)  I
obtain the following errors:

MatrixArray.cs(40,24): error CS0021: Cannot apply indexing with [] to
an expression of type `T'
MatrixArray.cs(44,17): error CS0021: Cannot apply indexing with [] to
an expression of type `T'


The problem seems related to the generics' constraints and derived interfaces.

The current class definition is the following:

public class MatrixArray : List where T : IMatrix

Please Note that if I change the constraint which says that T must
implement interface IMatrix to saying T must implement  the parent of
IMatrix, IMatrixBase, everything works.


Should I file a bug, or the problem is already known?
Thanks,
Matteo


// MatrixArray.cs
using System;
using System.Collections.Generic;

namespace test
{

public class program
{
  static void Main(string[] args)
  {

  }
}


 public interface IMatrixBase
 {
double this[int r, int c]
{
get;
set;
}
 }

 public interface IMatrix: IMatrixBase
 {
 }




public class MatrixArray : List where T : IMatrix
{
   public double this[int i1,int i2,int i3]
{
get
{
return this[i1][i2, i3];
}
set
{
this[i1][i2, i3] = value;
}
}
}

}


MatrixArray.cs
Description: Binary data
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] c# compiler problem with generics and derived interfaces

2010-06-16 Thread Marek Safar
Hello,
> I cannot compile the code reported below with mono 2.6.4 (which
> compiles fine using visual studio 2008).
>
> By executing  gmcs MatrixArray.cs (see below or attached file)  I
> obtain the following errors:
>
> MatrixArray.cs(40,24): error CS0021: Cannot apply indexing with [] to
> an expression of type `T'
> MatrixArray.cs(44,17): error CS0021: Cannot apply indexing with [] to
> an expression of type `T'
>   
This issue has been already fixed in trunk

Regards,
Marek
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Patch 1/2 - System.Diagnostics.Contracts in corlib

2010-06-16 Thread Andreas Nahr
Hi Chris,

I have no knowledge about your GSoC project, but usually mono doesn't use C#
inline documentation style.

Happy hacking
Andreas

> -Ursprüngliche Nachricht-
> Von: mono-devel-list-boun...@lists.ximian.com [mailto:mono-devel-list-
> boun...@lists.ximian.com] Im Auftrag von Chris Bacon
> Gesendet: Mittwoch, 16. Juni 2010 12:03
> An: Marek Safar
> Cc: mono-devel-list@lists.ximian.com
> Betreff: Re: [Mono-dev] Patch 1/2 - System.Diagnostics.Contracts in
> corlib
> 
> Hi,
> 
> Attached is a new, improved, patch that keeps existing formatting.
> Sorry for the mistake.
> 
> Kind regards
> Chris
> 
> Marek Safar wrote:
> > Hi Chris,
> >>
> >> Attached is a patch to corlib containing updates the
> >> System.Diagnostics.Contracts as part of the GSoC work I am doing.
> >>
> >> I'm sure there will be parts of this I haven't done quite right, so
> >> please let me know what they are, and I'll sort them out.
> > Can you keep existing formatting, most of the changes are about
> > changing tabs to spaces. Please send a new set of patches without any
> > noise (lines you have not changed)
> >
> > Thanks
> > Marek

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] MonoCharge on Windows

2010-06-16 Thread SuperCiccio

Update: I tried to upgrade manually copying files, but without luck.
-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/MonoCharge-on-Windows-tp2256440p2257334.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] MonoCharge on Windows

2010-06-16 Thread Robert Jordan
On 16.06.2010 15:24, SuperCiccio wrote:
>
> Update: I tried to upgrade manually copying files, but without luck.

Which Mono version do you want to update?

Robert

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Patch 1/2 - System.Diagnostics.Contracts in corlib

2010-06-16 Thread Chris Bacon

Hi,

Thank you for letting me know, attached is a patch with the 
documentation removed.


Kind regards
Chris

Andreas Nahr wrote:

Hi Chris,

I have no knowledge about your GSoC project, but usually mono doesn't use C#
inline documentation style.

Happy hacking
Andreas

  

-Ursprüngliche Nachricht-
Von: mono-devel-list-boun...@lists.ximian.com [mailto:mono-devel-list-
boun...@lists.ximian.com] Im Auftrag von Chris Bacon
Gesendet: Mittwoch, 16. Juni 2010 12:03
An: Marek Safar
Cc: mono-devel-list@lists.ximian.com
Betreff: Re: [Mono-dev] Patch 1/2 - System.Diagnostics.Contracts in
corlib

Hi,

Attached is a new, improved, patch that keeps existing formatting.
Sorry for the mistake.

Kind regards
Chris

Marek Safar wrote:


Hi Chris,
  

Attached is a patch to corlib containing updates the
System.Diagnostics.Contracts as part of the GSoC work I am doing.

I'm sure there will be parts of this I haven't done quite right, so
please let me know what they are, and I'll sort them out.


Can you keep existing formatting, most of the changes are about
changing tabs to spaces. Please send a new set of patches without any
noise (lines you have not changed)

Thanks
Marek
  


  
Index: ChangeLog
===
--- ChangeLog   (revision 159003)
+++ ChangeLog   (working copy)
@@ -1,3 +1,7 @@
+2010-06-16  Chris Bacon 
+
+   * corlib.dll.sources: Add files required for Code Contracts.
+
 2010-05-23  Carlos Alberto Cortez 
 
* corlib.dll.sources: Add System.IO.IsolatedStorageSecurityState.cs
Index: corlib.dll.sources
===
--- corlib.dll.sources  (revision 159003)
+++ corlib.dll.sources  (working copy)
@@ -331,14 +331,17 @@
 System.Diagnostics.Contracts/Contract.cs
 System.Diagnostics.Contracts/ContractClassAttribute.cs
 System.Diagnostics.Contracts/ContractClassForAttribute.cs
+System.Diagnostics.Contracts/ContractException.cs
 System.Diagnostics.Contracts/ContractFailedEventArgs.cs
 System.Diagnostics.Contracts/ContractFailureKind.cs
 System.Diagnostics.Contracts/ContractInvariantMethodAttribute.cs
 System.Diagnostics.Contracts/ContractPublicPropertyNameAttribute.cs
 System.Diagnostics.Contracts/ContractReferenceAssemblyAttribute.cs
 System.Diagnostics.Contracts/ContractRuntimeIgnoredAttribute.cs
+System.Diagnostics.Contracts/ContractShouldAssertException.cs
 System.Diagnostics.Contracts/ContractVerificationAttribute.cs
 System.Diagnostics.Contracts/PureAttribute.cs
+System.Diagnostics.Contracts/Internal/ContractHelper.cs
 System.Diagnostics.SymbolStore/ISymbolBinder.cs
 System.Diagnostics.SymbolStore/ISymbolBinder1.cs
 System.Diagnostics.SymbolStore/ISymbolDocument.cs
Index: System.Diagnostics.Contracts/Contract.cs
===
--- System.Diagnostics.Contracts/Contract.cs(revision 159003)
+++ System.Diagnostics.Contracts/Contract.cs(working copy)
@@ -3,8 +3,9 @@
 //
 // Authors:
 //Miguel de Icaza (mig...@gnome.org)
+//Chris Bacon (chrisbaco...@gmail.com)
 //
-// Copyright 2009 Novell (http://www.novell.com)
+// Copyright 2009, 2010 Novell (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -26,30 +27,12 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-//
-// Things left to do:
-// 
-//   * This is a blind implementation from specs, without any testing, so the 
escalation
-// is probably broken, and so are the messages and arguments to the 
eventargs properties
-//
-//   * How to plug the original condition into the Escalate method?   Perhaps 
we need
-// some injection for it?
-//
-//   * The "originalException" in Escalate is nowhere used
-//
-//   * We do not Escalate everything that needs to be, perhaps that is the 
role of the
-// rewriter to call Escalate with the proper values?
-//
-//   * I added a "new()" constraint to methods that took a TException because 
I needed
-// to new the exception, but this is perhaps wrong.
-//
-//   * Result and ValueAtReturn, I need to check what these do in .NET 4, but 
have not
-// installed it yet ;-)
-//
 using System;
 using System.Collections.Generic;
+using System.Diagnostics.Contracts.Internal;
 
 namespace System.Diagnostics.Contracts {
+
 #if NET_2_1 || NET_4_0
public
 #else
@@ -60,24 +43,57 @@
 
public static event EventHandler 
ContractFailed;
 
-   static void Escalate (ContractFailureKind kind, Exception e, 
string text, params object [] args)
+   // Used in test
+   internal static EventHandler 
InternalContractFailedEvent
{
-   if (ContractFailed != null){
-   var ea = new ContractFailedEventArgs (kind, 
text, "", e ?? new Exception ());
-

Re: [Mono-dev] MonoCharge on Windows

2010-06-16 Thread SuperCiccio

Latest (2.6.4) to Daily Packages (http://mono.ximian.com/daily)
-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/MonoCharge-on-Windows-tp2256440p2257354.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] MonoCharge on Windows

2010-06-16 Thread Robert Jordan
On 16.06.2010 15:41, SuperCiccio wrote:
>
> Latest (2.6.4) to Daily Packages (http://mono.ximian.com/daily)

You're not supposed to update a stable Mono from daily packages
because there are interdependencies between the runtime
and the class libraries that are not resolved by those dailies.

It's only safe to update single non-core assemblies (e.g. System.
Windows.Form, a rather seldom updated assembly), but even then,
there is absolutely no warranty that your Mono is still working
after an update.

Robert


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] Newbie at app planning stage requires basic pointers

2010-06-16 Thread WingYip

Hi 

Am being asked to create a Windows / Mac cross platform app that will need: 

Integrated help system that will run on all versions of Windows and Mac 
Backend database (which db to use)(Will I be able to use Linq2Sql to
connect) 
Encryption of certain items will be required 

Does anybody have any advice for the above requirements - these are the main
areas that I instinctively feel that there will be issues. 

Wing 

-- 
View this message in context: 
http://mono.1490590.n4.nabble.com/Newbie-at-app-planning-stage-requires-basic-pointers-tp2257435p2257435.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] Create a 'MonoImage' from a byte array.

2010-06-16 Thread Thiago Padilha
  I'm trying to create a MonoImage/MonoAssembly from a byte array like this :


//body omited, this is a simple function that return contents of a
binary file and returns the file size in bytes as an out parameter
static char *read_file_contents(char *fullpath, int *outfilesize);

static MonoImage *get_image(char *data, char *name, char *size)
{
return  mono_image_open_from_data_with_name (data, size, 0,
MONO_IMAGE_OK, 0, name);
}

MonoAssembly *get_assembly_from_file(char *name)
{   
int size = 0;



MonoAssembly *ret = NULL;
MonoImage *image = get_image_from_file(fullpath);

if(image != NULL)
ret = mono_assembly_load_from_full(image, fullpath, 
MONO_IMAGE_OK, 0);


free(fullpath);
return ret;
}
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] Create a 'MonoImage' from a byte array. (corrected)

2010-06-16 Thread Thiago Padilha
 I'm trying to create a MonoImage/MonoAssembly from a byte array like this :


//body omited, this is a simple function that return contents of a
binary file and returns the file size in bytes as an out parameter
static char *read_file_contents(char *fullpath, int *outfilesize);

static char *getfullpath(char *name); //returns the full path of a file

static MonoImage *get_image(char *data, char *name, char *size)
{
       return  mono_image_open_from_data_with_name (data, size, 0,
MONO_IMAGE_OK, 0, name);
}

MonoAssembly *get_assembly_from_file(char *name)
{
       int size = 0;
   char *fullpath =  getfullpath(name);
   char *data = read_file_contents(fullpath, &size);


       MonoAssembly *ret = NULL;
       MonoImage *image = get_image(data, name, size);

       if(image != NULL)
               ret = mono_assembly_load_from_full(image, fullpath,
MONO_IMAGE_OK, 0);

       return ret;
}

I get some assertion errors in glib when creating the image trough
'mono_image_open_from_data_with_name' :

(process:24477): GLib-CRITICAL **: g_hash_table_lookup: assertion
`hash_table != NULL' failed

(process:24477): GLib-CRITICAL **: g_hash_table_insert_internal:
assertion `hash_table != NULL' failed

(process:24477): GLib-CRITICAL **: g_hash_table_lookup: assertion
`hash_table != NULL' failed

(process:24477): GLib-CRITICAL **: g_hash_table_insert_internal:
assertion `hash_table != NULL' failed
f

  Am I missing something? if so, how can I create a 'MonoAssembly'
from a byte array?(instead of using the  'mono_assembly_open' which
accepts a filename).
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Create a 'MonoImage' from a byte array.

2010-06-16 Thread Tom Spink
Hi, I don't think you've told us the problem!

Tom.

On 6/16/10, Thiago Padilha  wrote:
>   I'm trying to create a MonoImage/MonoAssembly from a byte array like this
> :
>
>
> //body omited, this is a simple function that return contents of a
> binary file and returns the file size in bytes as an out parameter
> static char *read_file_contents(char *fullpath, int *outfilesize);
>
> static MonoImage *get_image(char *data, char *name, char *size)
> {
>   return  mono_image_open_from_data_with_name (data, size, 0,
> MONO_IMAGE_OK, 0, name);
> }
>
> MonoAssembly *get_assembly_from_file(char *name)
> { 
>   int size = 0;
>
>
>   
>   MonoAssembly *ret = NULL;
>   MonoImage *image = get_image_from_file(fullpath);
>   
>   if(image != NULL)
>   ret = mono_assembly_load_from_full(image, fullpath, 
> MONO_IMAGE_OK, 0);
>
>   
>   free(fullpath);
>   return ret;
> }
> ___
> Mono-devel-list mailing list
> Mono-devel-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>

-- 
Sent from my mobile device

Tom Spink
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Create a 'MonoImage' from a byte array. (corrected)

2010-06-16 Thread Robert Jordan
On 16.06.2010 17:49, Thiago Padilha wrote:
>   I'm trying to create a MonoImage/MonoAssembly from a byte array like this :
>
>
> //body omited, this is a simple function that return contents of a
> binary file and returns the file size in bytes as an out parameter
> static char *read_file_contents(char *fullpath, int *outfilesize);
>
> static char *getfullpath(char *name); //returns the full path of a file
>
> static MonoImage *get_image(char *data, char *name, char *size)
> {
> return  mono_image_open_from_data_with_name (data, size, 0,
> MONO_IMAGE_OK, 0, name);

Please check the prototype of mono_image_open_from_data_with_name():
instead of MONO_IMAGE_OK you're supposed to pass a ptr to
a MonoImageOpenStatus enum.

You should really consider increasing the warning level of
your compiler or at least pay attention to the warnings.

Robert

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] Installing pre-load hooks on windows(bug?)

2010-06-16 Thread Thiago Padilha
  I use a callback function to control assembly loading with this code :


MonoAssembly *pre_hook(MonoAssemblyName *aname, gchar
**assemblies_path, gpointer user_data)
{   
char *name = aname->name;
printf("\nTRYING TO LOAD ASSEMBLY : %s\n", name);   
return get_assembly_from_name(name, assemblydir,
&lastloadstatus);//custom logic for finding an assembly
}

int main(int argc, char** argv)
{   
//installing the pre-load hook  
mono_install_assembly_preload_hook(pre_hook, "some data");

//starting the domain
MonoDomain *domain = mono_jit_init_version("Host", "v2.0.50727");   

MonoAssemblyName *aname = malloc(sizeof(MonoAssemblyName));
aname->name = "App.exe";
MonoAssembly *mainassembly = mono_assembly_load(aname, "/", 
&lastloadstatus);

return mono_jit_exec(domain, mainassembly, argc, argv);
}

  All works correctly, except that when I run this program on
Windows(I have tested on both Seven and XP) get the following 'extra'
output

TRYING TO LOAD ASSEMBLY : I18N

  I have no idea where this 'I18N' comes from. This is not stopping
the program to run, all I had is to validade my custom logic against
this 'I18N' assembly, but I wonder where does this comes from(the
runtime tried to load this assembly two times).
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Installing pre-load hooks on windows(bug?)

2010-06-16 Thread Robert Jordan
On 17.06.2010 01:13, Thiago Padilha wrote:
>I use a callback function to control assembly loading with this code :
>All works correctly, except that when I run this program on
> Windows(I have tested on both Seven and XP) get the following 'extra'
> output
>
> TRYING TO LOAD ASSEMBLY : I18N
>
>I have no idea where this 'I18N' comes from. This is not stopping
> the program to run, all I had is to validade my custom logic against
> this 'I18N' assembly, but I wonder where does this comes from(the
> runtime tried to load this assembly two times).

The i18n assemblies contain culture infos and it looks like you have
different cultures between linux and windows. That's why you're
seeing a difference.

Robert

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list