Autofac not finding gtk-sharp assembly for Microsoft .NET

355 views
Skip to first unread message

Ricardo

unread,
Jun 22, 2009, 7:20:01 AM6/22/09
to Autofac
Hi All,

First of all, kudos on Autofac. Of all the .NET based DI APIs I used,
Autofac was the one that seems to work the best with Mono.

I'm successfully using Autofac to compose a gtk-sharp UI in Mono. It
runs successfully on both Linux and Windows Mono:

ContainerBuilder builder = new ContainerBuilder();
builder.RegisterModule(new ConfigurationSettingsReader
("webpuppy-desktop-components"));

IContainer container = builder.Build();
DesktopEngine = container.Resolve<IDesktopEngine>();
Debug.WriteLine("["+assembly.Name+"] Starting Desktop
Application with GUI Engine=["+DesktopEngine+"]");

DesktopApplication = container.Resolve<IDesktopApplication>
();
DesktopEngine.Initialize();

Using the following App.config:

<configSections>
<section name="webpuppy-desktop-components"
type="Autofac.Configuration.SectionHandler, Autofac"/>
</configSections>

<webpuppy-desktop-components
defaultAssembly="WebPuppyDesktopApplication">

<components>
<component
name="GtkDesktopApplication"
type="WebPuppy.Desktop.GtkSharp.GtkDesktopEngine"
service="WebPuppy.Desktop.IDesktopEngine"
scope="singleton"
/>

<component
name="GtkDesktopApplication"
type="WebPuppy.Desktop.GtkSharp.GtkDesktopApplication"
service="WebPuppy.Desktop.IDesktopApplication"
scope="singleton"
/>

<component
name="ApplicationStatusIcon"
type="WebPuppy.Desktop.GtkSharp.ApplicationStatusIcon"
service="Gtk.StatusIcon, gtk-sharp"
scope="singleton"
>
<properties>
<property name="Tooltip" value="WebPuppy" />
<property name="Visible" value="true" />
</properties>
</component>
</components>

</webpuppy-desktop-components>

</configuration>

However, when I attempt to execute the application (compiled using
Mono) on Microsoft .NET I get the following error message:

Unhandled Exception:
System.Configuration.ConfigurationErrorsException: The type
'Gtk.StatusIcon, gtk-sharp' could not be found. It may require
assembly qualification, e.g. "MyType, MyAssembly".

at Autofac.Configuration.ConfigurationSettingsReader.LoadType
(String typeName, Assembly defaultAssembly)

at Autofac.Configuration.ConfigurationSettingsReader.Load
(ContainerBuilder builder)

at Autofac.Builder.Module.Configure(IContainer container)

at Autofac.Builder.ContainerBuilder.Build(IContainer container)

at Autofac.Builder.ContainerBuilder.Build()

at WebPuppy.Desktop.Program.Main() in c:\Documents and Settings
\ricardo\workspace\WebPuppy\WebPuppyDesktopApplication\Program.cs:line
29

If I directly compose the Gtk UI directly, it works fine in
Microsoft .NET, it just doesn't seem to like the Autofac composition.

Please advise...

-- Ricardo Gladwell

Rinat Abdullin

unread,
Jun 22, 2009, 11:08:28 AM6/22/09
to Autofac
Hi Ricardo,

It is nice to hear that Autofac helps you out on Mono!

Including assembly reference to the Gtk dll might help. You can find
full assembly reference to StatusIcon by firing this snippet:

Console.WriteLine(typeof(StatusIcon).AssemblyQualifiedName).

Note: Gtk assemblies generally have to either be in the output folder
(included as project references) or be installed into the GAC.

Does this help?

Thoughts:
1. If type resolution on Mono works without specifying gtk-sharp
version, then it is better to do so
2. Generally it is a better practice to register autofac components in
modules in hard code, as opposed to the XML which is usually left for
high-level configuration tasks.

See http://code.google.com/p/autofac/wiki/StructuringWithModules


Best regards,
Rinat Abdullin

http://abdullin.com

Ricardo Gladwell

unread,
Jun 22, 2009, 11:27:42 AM6/22/09
to aut...@googlegroups.com
Hi Rinat,

Thanks for that, putting the full qualified assembly name into the XML
seemed to work. But won't this make the application cross-platform
unfriendly?

TIA...

-- Ricardo Gladwell

2009/6/22 Rinat Abdullin <rinat.a...@gmail.com>:

Rinat Abdullin

unread,
Jun 23, 2009, 3:53:51 AM6/23/09
to Autofac
Hi Ricardo,

It shouldn't. Full type resolution is too important in .NET in order
to work differently under different platforms.

From my limited experience cross-platform apps tend to break in more
interesting places anyway.

Best regards,
Rinat Abdullin

http://abdullin.com

On Jun 22, 5:27 pm, Ricardo Gladwell <ricardo.gladw...@gmail.com>
wrote:
> Hi Rinat,
>
> Thanks for that, putting the full qualified assembly name into the XML
> seemed to work. But won't this make the application cross-platform
> unfriendly?
>
> TIA...
>
> -- Ricardo Gladwell
>
> 2009/6/22 Rinat Abdullin <rinat.abdul...@gmail.com>:
>
>
>
> > Hi Ricardo,
>
> > It is nice to hear that Autofac helps you out on Mono!
>
> > Including assembly reference to the Gtk dll might help. You can find
> > full assembly reference to StatusIcon by firing this snippet:
>
> > Console.WriteLine(typeof(StatusIcon).AssemblyQualifiedName).
>
> > Note: Gtk assemblies generally have to either be in the output folder
> > (included as project references) or be installed into the GAC.
>
> > Does this help?
>
> > Thoughts:
> > 1. If type resolution on Mono works without specifying gtk-sharp
> > version, then it is better to do so
> > 2. Generally it is a better practice to register autofac components in
> > modules in hard code, as opposed to the XML which is usually left for
> > high-level configuration tasks.
>
> > Seehttp://code.google.com/p/autofac/wiki/StructuringWithModules
Reply all
Reply to author
Forward
0 new messages