When I deploy my MVC 3 (razor) solution to the web server I get the following error when I invoke a view of a controller that needs the context of my model:
Schema specified is not valid. Errors:
error 0194: All artifacts loaded into an ItemCollection must have the same version. Multiple versions were encountered.
[MetadataException: Schema specified is not valid. Errors:
error 0194: All artifacts loaded into an ItemCollection must have the same version. Multiple versions were encountered.]...
[StructureMapException: StructureMap Exception Code: 207
Internal exception while creating Instance 'f7f17c73-9f54-4a2d-8f7c-c2c6200b5cc5' of PluginType SmwMvc.Model.ISmwContext. Check the inner exception for more details.]...
[InvalidOperationException: An error occurred when trying to create a controller of type 'SmwMvc.WebApp.Controllers.WinesController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +181...
I'm using MySql (.Net Connector 6.3.6.0) with Entity Framework 4.1 installed and am using POCO entities. I have another model in my solution for authentication which does not use dependency injection and it works fine on the server. On my PC everything works
fine. Both models target tables in the same database. I saw a post similiar to mine on StackOverflow stating that the solution to the problem was to fully qualify his database domein because his PC could resolve it but the server could not, but thats just not
enough info for me.
Anyone got any ideas on how I can solve this problem?
It is very likely that the problem is one of the ones below:
1) Permissions on the web server are too low for strcuturemap to make reflection. Reflection require an enough hign level of thrust. Such a trhrust level is matched by most of the internet providers, but there are some that doesn't allow reflection.
2) There is somewhere a mismatch of version betwee some .Net libraries...maybe you used an old version of structure map or a the objects created by structure map are taken from an old dll compiled with an old version of .net or similar.
Try to deploy your appl on your local IIS (install it on your machine if necessary). Firsta try with full thrust, then if ok lower the level of thrust to see if the same error you experiment on the deployment server appears.
An error occurred when trying to create a controller of type 'SmwMvc.WebApp.Controllers.WinesController'. Make sure that the controller has a parameterless public constructor.
Does the controller SmwMvc.WebApp.Controllers.WinesController
have a parameterless public constructor ?
My WinesController does not have a parameterless constructor but I think that that error message simply leads you in the wrong direction. My controller actually has a constructor that receives a number of repositories (based on the interface) which get resolved
by StructureMap. The repositories then have a constructor that receives my data context (based on an interface) which also get resolved by StructureMap. The problem lies in the instantiation of a concrete data context object for my repositories. And as I said,
my problem only occurs on the web server, and even on the web server my other entity model, which doesn't use dependency injection, works fine on the web server (it handles my forms authentication and role provider which I couldn't figure out how to get working
with StructureMap seeing as the providers are instantiated before the IOC container is initialized).
I wouldn't think that it has anything to do with reflection on the server because the injection of a concrete data context takes place after the injection of a concrete repository (and that requires reflection too).
I also wouldn't think that the problem has to do with version mismatches seeing as the website functions properly on my local machine, but permissions on the server (or lack of) may be a problem. I haven't configured the webapp to run under IIS on my local
machine, I'll have to try that and see if I can reproduce the problem locally.
My WinesController does not have a parameterless constructor but I think that that error message simply leads you in the wrong direction. My controller actually has a constructor that receives a number of repositories (based on the interface) which get resolved
by StructureMap. The repositories then have a constructor that receives my data context (based on an interface) which also get resolved by StructureMap.
Maybe you miss an argument in the constructor that StructureMap is not able to solve it.
What if you put a parameterless constructor that default to the constructor with default arguments:
I also wouldn't think that the problem has to do with version mismatches seeing as the website functions properly on my local machine, but permissions on the server (or lack of) may be a problem. I haven't configured the webapp to run under IIS on my local
machine, I'll have to try that and see if I can reproduce the problem locally.
Try it the app on your local machine is the only possibility, so you can perform various experiments changing application pool, thrust level and so on. Moreover, maybe the problem is the server itself that has a misconfigured asp.net or simply your application
pool is configured in some strong way.
About version mismatch...don't be so sure. The way .Net deal with different versions is quite complex: problems may arise just when you use structuremap due a some versioning policy or simply to the fact that you mentioned a specific version when putting
an assemply name in the structuremap configuration information...maybe normally a different dll (wkth a coherent version) is taken
I configured my website to run under IIS and that went fine, no problems locally. I also created a parameterless constructor for my WinesController but I kept getting the same error. I then started to gradually remove the dependencies required to initialize
the objects in question. First the data context for the repositories with no success. Then the WinesController for the repositories, still no success. Locally, with all changes made, everything still runs fine.
So I'm pretty sure it's not a permissions issue or a parameterless constructor problem. And seeing as my other entity model works fine on my host web server (without dependency injection) I don't think it's a versioning problem. In fact, I'm thinking that
it also doesn't have anything to do with StructureMap either. I think I must have a difference in my database/table definitions between my local MySql server and the server on my host. I haven't tried running my website locally against my hosted MySql database,
I'm going to give that a shot, hoping that I get the same error.
Well the server database on my web hosting provider is exactly the same as my local MySql database (as far as I can see) and, if I run my website locally under the VS Development server using the connection string pointing to my web server database, then
the website runs properly. When I use the web server database under IIS I get errors trying to run the website (HTTP error 500).
I just don't get it. How can one entity model be accessible and the other one not be accessible. Same database, even 3 mutually used tables. And everything runs fine locally, under VSDS and IIS.
if I run my website locally under the VS Development server using the connection string pointing to my web server database, then the website runs properly. When I use the web server database under IIS I get errors trying to run the website (HTTP error 500).
VS Development server is not the same as IIS.More, it is error prone.Not reccomended
I'm running on Windows 7 Enterprise (SP1) with IIS 7.5. I get the HTTP error 500 when trying to use my web hosted database. When using my local MySql database under IIS I have no problems. I'm by no means an IIS expert so I could be doing something wrong.
I'm running under the standard user in een app pool configured for .NET Framework 4.0 with 32-bit apps enabled. Besides that I just created the virtual directory by clicking the button in Visual Studio 2010.
BarryC
Member
107 Points
56 Posts
StructureMap not able to instantiate data context when deployed to webserver
Oct 05, 2011 03:32 PM|LINK
When I deploy my MVC 3 (razor) solution to the web server I get the following error when I invoke a view of a controller that needs the context of my model:
Schema specified is not valid. Errors:
error 0194: All artifacts loaded into an ItemCollection must have the same version. Multiple versions were encountered.
[MetadataException: Schema specified is not valid. Errors:
error 0194: All artifacts loaded into an ItemCollection must have the same version. Multiple versions were encountered.]...
[StructureMapException: StructureMap Exception Code: 207
Internal exception while creating Instance 'f7f17c73-9f54-4a2d-8f7c-c2c6200b5cc5' of PluginType SmwMvc.Model.ISmwContext. Check the inner exception for more details.]...
[InvalidOperationException: An error occurred when trying to create a controller of type 'SmwMvc.WebApp.Controllers.WinesController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +181...
I'm using MySql (.Net Connector 6.3.6.0) with Entity Framework 4.1 installed and am using POCO entities. I have another model in my solution for authentication which does not use dependency injection and it works fine on the server. On my PC everything works fine. Both models target tables in the same database. I saw a post similiar to mine on StackOverflow stating that the solution to the problem was to fully qualify his database domein because his PC could resolve it but the server could not, but thats just not enough info for me.
Anyone got any ideas on how I can solve this problem?
francesco ab...
All-Star
20888 Points
3277 Posts
Re: StructureMap not able to instantiate data context when deployed to webserver
Oct 05, 2011 03:57 PM|LINK
It is very likely that the problem is one of the ones below:
1) Permissions on the web server are too low for strcuturemap to make reflection. Reflection require an enough hign level of thrust. Such a trhrust level is matched by most of the internet providers, but there are some that doesn't allow reflection.
2) There is somewhere a mismatch of version betwee some .Net libraries...maybe you used an old version of structure map or a the objects created by structure map are taken from an old dll compiled with an old version of .net or similar.
Try to deploy your appl on your local IIS (install it on your machine if necessary). Firsta try with full thrust, then if ok lower the level of thrust to see if the same error you experiment on the deployment server appears.
Mvc Controls Toolkit | Data Moving Plug-in Videos
ignatandrei
All-Star
134521 Points
21576 Posts
Moderator
MVP
Re: StructureMap not able to instantiate data context when deployed to webserver
Oct 05, 2011 08:56 PM|LINK
Does the controller SmwMvc.WebApp.Controllers.WinesController have a parameterless public constructor ?
BarryC
Member
107 Points
56 Posts
Re: StructureMap not able to instantiate data context when deployed to webserver
Oct 06, 2011 06:22 AM|LINK
Thanks Francesco and ignatandrei for the reply.
My WinesController does not have a parameterless constructor but I think that that error message simply leads you in the wrong direction. My controller actually has a constructor that receives a number of repositories (based on the interface) which get resolved by StructureMap. The repositories then have a constructor that receives my data context (based on an interface) which also get resolved by StructureMap. The problem lies in the instantiation of a concrete data context object for my repositories. And as I said, my problem only occurs on the web server, and even on the web server my other entity model, which doesn't use dependency injection, works fine on the web server (it handles my forms authentication and role provider which I couldn't figure out how to get working with StructureMap seeing as the providers are instantiated before the IOC container is initialized).
I wouldn't think that it has anything to do with reflection on the server because the injection of a concrete data context takes place after the injection of a concrete repository (and that requires reflection too).
I also wouldn't think that the problem has to do with version mismatches seeing as the website functions properly on my local machine, but permissions on the server (or lack of) may be a problem. I haven't configured the webapp to run under IIS on my local machine, I'll have to try that and see if I can reproduce the problem locally.
ignatandrei
All-Star
134521 Points
21576 Posts
Moderator
MVP
Re: StructureMap not able to instantiate data context when deployed to webserver
Oct 06, 2011 06:35 AM|LINK
Maybe you miss an argument in the constructor that StructureMap is not able to solve it.
What if you put a parameterless constructor that default to the constructor with default arguments:
public WinesController (): this(....)
francesco ab...
All-Star
20888 Points
3277 Posts
Re: StructureMap not able to instantiate data context when deployed to webserver
Oct 06, 2011 06:58 AM|LINK
Try it the app on your local machine is the only possibility, so you can perform various experiments changing application pool, thrust level and so on. Moreover, maybe the problem is the server itself that has a misconfigured asp.net or simply your application pool is configured in some strong way.
About version mismatch...don't be so sure. The way .Net deal with different versions is quite complex: problems may arise just when you use structuremap due a some versioning policy or simply to the fact that you mentioned a specific version when putting an assemply name in the structuremap configuration information...maybe normally a different dll (wkth a coherent version) is taken
Mvc Controls Toolkit | Data Moving Plug-in Videos
BarryC
Member
107 Points
56 Posts
Re: StructureMap not able to instantiate data context when deployed to webserver
Oct 10, 2011 05:37 AM|LINK
I configured my website to run under IIS and that went fine, no problems locally. I also created a parameterless constructor for my WinesController but I kept getting the same error. I then started to gradually remove the dependencies required to initialize the objects in question. First the data context for the repositories with no success. Then the WinesController for the repositories, still no success. Locally, with all changes made, everything still runs fine.
So I'm pretty sure it's not a permissions issue or a parameterless constructor problem. And seeing as my other entity model works fine on my host web server (without dependency injection) I don't think it's a versioning problem. In fact, I'm thinking that it also doesn't have anything to do with StructureMap either. I think I must have a difference in my database/table definitions between my local MySql server and the server on my host. I haven't tried running my website locally against my hosted MySql database, I'm going to give that a shot, hoping that I get the same error.
BarryC
Member
107 Points
56 Posts
Re: StructureMap not able to instantiate data context when deployed to webserver
Oct 11, 2011 09:06 PM|LINK
Well the server database on my web hosting provider is exactly the same as my local MySql database (as far as I can see) and, if I run my website locally under the VS Development server using the connection string pointing to my web server database, then the website runs properly. When I use the web server database under IIS I get errors trying to run the website (HTTP error 500).
I just don't get it. How can one entity model be accessible and the other one not be accessible. Same database, even 3 mutually used tables. And everything runs fine locally, under VSDS and IIS.
Anymore idea's? Anyone?
ignatandrei
All-Star
134521 Points
21576 Posts
Moderator
MVP
Re: StructureMap not able to instantiate data context when deployed to webserver
Oct 12, 2011 02:40 AM|LINK
VS Development server is not the same as IIS.More, it is error prone.Not reccomended
What IIS do you have ? What Windows version?
BarryC
Member
107 Points
56 Posts
Re: StructureMap not able to instantiate data context when deployed to webserver
Oct 12, 2011 08:26 PM|LINK
I'm running on Windows 7 Enterprise (SP1) with IIS 7.5. I get the HTTP error 500 when trying to use my web hosted database. When using my local MySql database under IIS I have no problems. I'm by no means an IIS expert so I could be doing something wrong. I'm running under the standard user in een app pool configured for .NET Framework 4.0 with 32-bit apps enabled. Besides that I just created the virtual directory by clicking the button in Visual Studio 2010.