-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The type initializer for 'File' threw an exception. #124
Comments
That's a weird one. It would indicate that BuildManager is referencing an assembly that cannot be added as a Metadata Reference by Roslyn. Just to be sure, which version of ModelsBuilder is this? |
The one that came bundled with Umbraco, let me get you an exact version
|
Uh, you probably want to get rid of Zbu.ModelsBuilder to ensure you are running the latest Umbraco.ModelsBuilder v3.0.5 (no idea what happens when both are installed) - and try again? |
Okay I've started again, clean MVC application installed, Umbraco installed, Umbraco.ModelsBuilder v3.0.5 installed. Same error message :( In the web.config I've got...
Any ideas? |
Any chance you can zip and share the project so I can see if it does the same on my machine? |
I'll backup the database as well for you and send that over with it :) |
thanks |
I've sent that off, let me know what you find out :) |
Reproduced here. Weird issue with Roslyn trying to load 'System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies and failing... trying to understand what's going on. |
OK, turns our Roslyn (used by ModelsBuilder) cannot create metadata reference for assemblies because it is looking for, and not finding, 'System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Fusion Log shows that it does find version 4.0.1.0 in the bin directory of your site. So... it thinks that it should use that version, and fails. I have no idea why you have System.IO.FileSystem in your bin - probably came with the other libs that you added there. One way to fix the situation is to tell .NET to always use version 4.0.1.0. In your web.config file, locate the section that looks like
and add the following redirect:
With that binding in place it now works on my machine. |
Thanks zpqrtbnk! That fixed it, not sure were that .dll came from, apart from stock Mvc, the only nuget packages I installed were Umbraco.Cms and Microsft.CodeAnalysis.CSharp. I'm guessing one of those dropped it in? Anyway, thanks for the assist :) |
Are you 100% sure about this? I see assemblies in Anyways... I tend to think that somehow you installed something that added the .dll. Never mind, glad it works! |
I had this same problem and did not find any of the above solutions to work for me. What did work was removing the reference to System.IO.FileSystem from the project. This would probably not work as well if you are storing media items locally, but my project uses the Azure blob storage provider. What seems to end up happening is that the project uses whatever assembly it can find. |
@zpqrtbnk
Your advice helped me (I removed the |
@zpqrtbnk Do you know why that happens? I have a long life solution that was updated many times before. I installed pure umbraco 7.15.3 solution and there was |
Hi guys
I've just started up a totally empty instance of Umbraco, I've created some simple DocumentTypes with a couple of properties and the model builder keeps throwing an error.
I'll include the stack trace below, any help would be greatly appreciated.
Failed to build models.
The type initializer for 'File' threw an exception.
at Roslyn.Utilities.FileUtilities.OpenFileStream(String path)
at Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationProvider documentation)
at Umbraco.ModelsBuilder.ReferencedAssemblies.<>c.<.cctor>b__2_2(String x) in X:\Projects\Umbraco\ModelsBuilder\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\ReferencedAssemblies.cs:line 24
at System.Linq.Enumerable.WhereSelectListIterator
2.MoveNext() at System.Linq.Buffer
1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable
1 source)at Umbraco.ModelsBuilder.ReferencedAssemblies.<>c.<.cctor>b__2_1() in X:\Projects\Umbraco\ModelsBuilder\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\ReferencedAssemblies.cs:line 23
at System.Lazy
1.CreateValue() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Lazy
1.get_Value()at Umbraco.ModelsBuilder.Umbraco.ModelsBuilderBackOfficeController.GenerateModels(String modelsDirectory, String bin) in X:\Projects\Umbraco\ModelsBuilder\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Umbraco\ModelsBuilderBackOfficeController.cs:line 108
at Umbraco.ModelsBuilder.Umbraco.ModelsBuilderBackOfficeController.BuildModels() in X:\Projects\Umbraco\ModelsBuilder\Zbu.ModelsBuilder\Umbraco.ModelsBuilder\Umbraco\ModelsBuilderBackOfficeController.cs:line 35
The text was updated successfully, but these errors were encountered: