[Mono-list] MySql.Data problems
Daniel Lo Nigro
lists at dan.cx
Wed Jan 2 04:14:07 UTC 2013
If you're a beginner it might be worth using an IDE like Visual Studio (on
Windows) or MonoDevelop instead of calling the compiler via the
command-line. The IDE will handle calling the compiler with the correct
flags and it's a lot easier to get started. It might also be worth taking a
look at some books on .NET and C#. Books often cover manually calling the
compilers, and knowledge of Microsoft's compiler and MSBuild generally
apply to Mono as well.
> It turns out, apparently, that the "MySql.Data" and "System.Data" modules
> (each)
> need to be referenced TWICE, (redundantly?), with the CLI compilation.
> You need
> to include the modules on the command line AS WELL AS inside the *.cs
> file, with
> the "-r:" switch:
They have two different purposes:
- The "using" directives in the .cs file pull stuff in a namespace into
scope in the C# file. So instead of fully qualifying your namespaces every
time (ie. doing "System.Text.StringBuilder blah = new
System.Text.StringBuilder()") you can just do "StringBuilder blah = new
StringBuilder()".
- The reference when building says that your code references
MySql.Data.dll and System.Data.dll. This means that when your code runs, it
will also load those two DLL files. It also means that when compiling, the
compiler will also look in these two assemblies for types you're
referencing.
On Wed, Jan 2, 2013 at 3:00 PM, DevLOOP <devloop at flight.us> wrote:
>
> On January 1, 2013 at 4:57 PM Daniel Lo Nigro <lists at dan.cx> wrote:
>
> >
> > As the error mentions, you need to reference System.Data as well as
> > MySql.Data.
> >
>
> I take it you mean reference it in my *.cs file, with "using <blah>"
> statements.
> Remember, I am a complete newbie, so I'm still very unsure where anything
> fits,
> with the variety of contexts (the web-request/config context, command-line
> context (cli arguments), the C-sharp code, etc.,etc.
>
> OK, so, I persisted further with the referencing and got my
> "helloworld.cs" to
> compile...
>
> It turns out, apparently, that the "MySql.Data" and "System.Data" modules
> (each)
> need to be referenced TWICE, (redundantly?), with the CLI compilation.
> You need
> to include the modules on the command line AS WELL AS inside the *.cs
> file, with
> the "-r:" switch:
>
> gmcs -r:MySql.Data.dll -r:System.Data helloworld.cs
>
> So, it compiled to "helloworld.exe". But when I run the executable ...
>
> mono helloworld.exe
>
> ... the executable throws an error:
>
>
> Missing method .ctor in assembly
>
> /opt/mono-3.0.2/lib/mono/gac/MySql.Data/6.6.4.0__c5687fc88969c44d/MySql.Data.dll,
> type System.Security.SecurityRulesAttribute
> Can't find custom attr constructor image:
>
> /opt/mono-3.0.2/lib/mono/gac/MySql.Data/6.6.4.0__c5687fc88969c44d/MySql.Data.dll
> mtoken: 0x0a00002a
>
> Unhandled Exception:
> System.TypeLoadException: Could not load type
> 'System.Security.SecurityRulesAttribute' from assembly 'MySql.Data'.
> at X.Main () [0x00000] in <filename unknown>:0
> [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not
> load type
> 'System.Security.SecurityRulesAttribute' from assembly 'MySql.Data'.
> at X.Main () [0x00000] in <filename unknown>:0
>
>
>
> > ---
> > Regards,
> > Daniel
> >
> > Sent from my phone - please excuse any typos.
> >
> > On 02/01/2013 7:35 AM, "DevLOOP" < devloop at flight.us
> > <mailto:devloop at flight.us> > wrote:
> > > > When I run:
> > >
> > > gmcs -r:MySql.Data.dll helloworld.cs
> > >
> > > I get:
> > >
> > > helloworld.cs(9,8): error CS0246: The type or namespace name
> > > `IDbConnection'
> > > could not be found. Are you missing an assembly reference?
> > > helloworld.cs(10,20): error CS0012: The type
> > > `System.Data.Common.DbConnection'
> > > is defined in an assembly that is not referenced. Consider adding a
> > > reference to
> > > assembly `System.Data, Version=4.0.0.0, Culture=neutral,
> > > PublicKeyToken=b77a5c561934e089'
> > > helloworld.cs(10,8): error CS0841: A local variable `dbcon' cannot
> be
> > > used
> > > before it is declared
> > > helloworld.cs(11,8): error CS0841: A local variable `dbcon' cannot
> be
> > > used
> > > before it is declared
> > > helloworld.cs(13,8): error CS0246: The type or namespace name
> > > `IDbCommand' could
> > > not be found. Are you missing an assembly reference?
> > > helloworld.cs(19,8): error CS0841: A local variable `dbcmd' cannot
> be
> > > used
> > > before it is declared
> > > helloworld.cs(20,8): error CS0246: The type or namespace name
> > > `IDataReader'
> > > could not be found. Are you missing an assembly reference?
> > > helloworld.cs(22,14): error CS0841: A local variable `reader'
> cannot be
> > > used
> > > before it is declared
> > > helloworld.cs(23,13): error CS0103: The name `Console' does not
> exist in
> > > the
> > > current context
> > > Compilation failed: 9 error(s), 0 warnings
> > >
> > > -----------------
> > >
> > > I thought I installed the component: I downloaded the connector
> from
> > > mysql.com <http://mysql.com> ,
> > > and ran:
> > >
> > > gacutil -i -package 4.0 v4/MySql.Data.dll
> > >
> > > (also, with "-package 4.5" and "-package 2.0")
> > >
> > > and I can see the installed files:
> > > /opt/mono-3.0.2/lib/mono/4.0/MySql.Data.dll
> > > (a symlink to
> > >
> > >
> /opt/mono-3.0.2/lib/mono/gac/MySql.Data/6.6.4.0__c5687fc88969c44d/MySql.Data.dll
> > > )
> > >
> > > and I also have:
> > >
> > >
> /opt/mono-3.0.2/lib/mono/gac/MySql.Data/6.6.4.0__c5687fc88969c44d/MySql.Data.dll
> > >
> > > What is missing or incorrect?
> > >
> > > thanks
> > > _______________________________________________
> > > Mono-list maillist - Mono-list at lists.ximian.com
> > > <mailto:Mono-list at lists.ximian.com>
> > > http://lists.ximian.com/mailman/listinfo/mono-list
> > > <http://lists.ximian.com/mailman/listinfo/mono-list>
> > > >
> _______________________________________________
> Mono-list maillist - Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-list/attachments/20130102/bd6fc790/attachment-0001.html>
More information about the Mono-list
mailing list