ServiceStack F# sample fails starting - f#

I'm trying to run this Self Hosting example, using latest ServiceStack release (4.0.3) and latest Mono/F# (3.2.5).
It fails with an exception on appHost.Init():
{ System.IO.FileNotFoundException: Virtual file not found File name: '<>.FSharpSignatureData.'
at ServiceStack.VirtualPath.ResourceVirtualDirectory.CreateVirtualFile (System.String resourceName) [0x00033] in <>/ServiceStack/VirtualPath/ResourceVirtualDirectory.cs:99 } System.IO.FileNotFoundException
The same does not happen with the C# sample.
Apparently, it looks for some files added as resources in F# assemblies but not mapped to a physical file.

F# does some 'meta data caching' that puts resources (FSharpSignatureData, FSharpOptimizationData) into the assembly. This causes issues when ServiceStack sets up its virtual file system since it wants to map these resources to actual files (I think).
You can get past this by adding the flag --nointerfacedata to the build/compile steps. (in VS Properties > Build > 'Other flags')
I've been meaning to post this to the GitHub issues page.

Related

dotnetopenauth samples "Attempt by method 'DotNetOpenAuth.OAuth2.WebServerClient ..."

I've just been spending hours on an issue that some others have reported to experience too.
The Sample.Oauth2.OAuthClient projet sample does not work for me.
Let me explain in details:
I got the latest version of dotnetopenauth from github (december 12th)
I ensured to "unblock" the zip before extracting all files.
I opened the solution with VS2012 (under Win7)
When starting the
Sample.Oauth2.OAuthClient project,
the overall build process succeed.
The website is started.
When calling
Sign in with Facebook (OAuth 2.0)
I get
Attempt by method
'DotNetOpenAuth.OAuth2.WebServerClient+d__3.MoveNext()'
to access method
'System.Collections.Generic.List`1..ctor()' failed.
Line 106: // verifiable for the same user/session.
Line 107: // If the host is implementing the authorization tracker
though, they're handling this protection themselves.
Line 108: var cookies = new List();
Line 109: if (this.AuthorizationTracker
== null) {
Line 110: string xsrfKey =
MessagingUtilities.GetNonCryptoRandomDataAsBase64(16, useWeb64: true);
That the provided code is not able to access "System.Collections.Generic.List" bewilders me...
I tried the following :
adding
<system.web>
<securityPolicy>
<trustLevel name="Full" policyFile="internal"/>
</securityPolicy>
to web.config.
Note that checking just before the line the "CurrentTrustLevel" results in "Unrestricted".
I tried to publish to local IIS 7,
tried running the pool under "administrator"
and finally
I tried with VS2013 on another, "clean" installation of Win7,
All attempts lead to the same result ...
It seems that the errors comes from some System.Net Dlls provided with the samples : they cannot be run by asp.net for security reasons (?)
Any idea ?

Recurring problems in Dart polymer project

I am having a problem that seems to be due to caching of dart packages etc.
My work machine runs some dart polymer examples without any problem. I use the same project on my home machine it it consistently gives the exception below:
Exception: Class '_textfieldElementExtension' has no instance method 'createInstance'.
NoSuchMethodError : method not found: 'createInstance'
Receiver: Instance of '_textfieldElementExtension#0x1d7f4e'
Arguments: [Instance of 'MyExample', Instance of 'PolymerExpressions']
PolymerElement.instanceTemplate (package:polymer/src/instance.dart:383:30)
PolymerElement.shadowFromTemplate (package:polymer/src/instance.dart:233:31)
PolymerElement.parseDeclaration (package:polymer/src/instance.dart:202:34)
PolymerElement.parseDeclarations (package:polymer/src/instance.dart:194:23)
PolymerElement.prepareElement (package:polymer/src/instance.dart:170:22)
PolymerElement.created (package:polymer/src/instance.dart:152:21)
_initCustomElement (package:custom_element/custom_element.dart:622:18)
registerCustomElement (package:custom_element/custom_element.dart:62:25)
I know that DartEditor places file .dartium and DartEditor in the users directory. Apart from these directory and the installation directory of the editor itself, where else are DartEditor files placed?
Thanks
There is a directory where the downloaded packages are stored. (~/.pub-cache for linux, don't know Windows).

Compiling jabber-net in Xamarin Studio

I am trying to compile jabber-net in Xamarin Studio so I can use it in a Xamarin.iOS app.
From other searches I have done I am told I need to recompile the source.
From command line I can build the dll, but I have no idea what version of .NET/Mono this is targeting.
This makes a jabber-net.dll and a jabber-net.dll.mdb.
If I add jabber-net.dll to my project, add the reqiured
using jabber.client;
...
...
...
JabberClient client = new JabberClient ();
and try to compile I am told.
/Users/brad/Projects/XMPPChat/XMPPChat/AppDelegate.cs(37,47): error CS0584: Internal compiler error: Could not import type jabber.client.JabberClient' fromjabber-net, Version=2.1.0.702, Culture=neutral, PublicKeyToken=924c5b18328d6f09'
/Users/brad/Projects/XMPPChat/XMPPChat/AppDelegate.cs(37,38): error CS0584: Internal compiler error: Could not import type jabber.client.JabberClient' fromjabber-net, Version=2.1.0.702, Culture=neutral, PublicKeyToken=924c5b18328d6f09'
/Users/brad/Projects/XMPPChat/XMPPChat/AppDelegate.cs(37,38): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
I got no idea what is going on here...
When I try to open any of the .sln's (or include any of the existing projects, even the mono specific project) that came with jabber-net into my solution it will either hang trying to convert the project, or will tell me
The file '/Users/brad/Projects/XMPPChat/JabberNet-2.1.0.710/mono-jabber-net.csproj' could not be loaded.
and will spit out this error.
Any idea where to go from here? :|
Start a new solution from scratch, and add all of the .cs files except those in the test and examples directories. Also make sure you don't have an old version of the .dll around somewhere.

F# compile code at runtime ends in missing assemblies

I have a question related to the code provided in an answer to this question.
The problem I have is that the three referenced assmeblies (System.dll, FSharp.Core.dll, FSharp.Powerpack.dll) that are passed to CompilerParameters are not found at runtime. The error I get is:
unknown-file(0,0) : error 0: error FS0218: Unable to read assembly
'c:\user s\utente\documents\visual studio
2010\Projects\TrashSolution\TrashSolution\bin\D ebug\FSharp.Core.dll'
How do I tell the compiler to search for these assemblies in the GAC, instead of the project's bin directory? If I open a namespace in the code provided as a string, how do I know which assemblies to add? Where can I get this information?
In the code from the answer you linked, there's a line towards the bottom:
let asm = Reflection.Assembly.LoadFrom(fileinfo.Value.FullName)
If you call Reflection.Load instead and pass it the fully-qualified assembly name, it'll try to load the assembly from the GAC (and a few other places, if the assembly isn't in the GAC).
let asm =
Assembly.Load "SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3"
If you don't know the fully-qualified assembly name you have to create an AssemblyName with the simple name of the assembly, then call the Reflection.Load overload which takes an AssemblyName instead of a string.
let asmName = AssemblyName "Your.Assembly.Name"
let asm = Assembly.Load asmName
As far as knowing which assemblies to load -- I don't think there's a simple way to determine that programmatically. The only two solutions I can think of right now:
If you have some knowledge about the code you're being given (as a string), you could parse it with the FSharpCodeProvider and look at which namespaces/modules are opened and which types are used. If you're looking to see if some particular namespace or type is used (i.e., that you would need to include an assembly reference for when compiling the code), you could create a Map (in your .fsx which is doing the compilation) of namespaces and/or type names to assembly names and use it to reference the appropriate assemblies.
You could "brute-force" search the GAC, by using the semi-documented Fusion API to enumerate all of the assemblies installed in the GAC, then using Reflection to examine each assembly and determine if it's one you require. This is likely to be extremely slow, so I'd avoid it at all costs. If you do decide to go this route, you must also use the Assembly.ReflectionOnlyLoad method to load the assemblies! This allows the assemblies to be unloaded after you finish examining them -- if you use normal Reflection the assemblies can't be unloaded and your program will likely crash with an OutOfMemoryException or similar.
EDIT: Turns out that loading the assembly by its simple name succeeds in fsi and not in normal F# code because fsi automatically installs a handler for the AppDomain.AssemblyResolve event. This event is triggered by the CLR when you try to load an assembly and it can't be resolved; the event provides a way for you to "manually" resolve the assembly and/or generate an assembly dynamically and return it.
If you look at the FileNotFoundException raised when you try to run the code in an F# project, you'll see something like this in the Fusion Log property of the exception:
=== Pre-bind state information ===
LOG: User = Jack-Laptop\Jack
LOG: DisplayName = System
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : StackOverflow1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System.DLL.
LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System/System.DLL.
LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System.EXE.
LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System/System.EXE.
Looking towards the bottom of that log, you'll see where the CLR searched for the assembly before it gave up.
Here's a simple handler to give you an idea of how to use the AppDomain.AssemblyResolve handler to manually resolve the assembly. (NOTE: The handler needs to be added before the code that attempts to load the assembly!)
System.AppDomain.CurrentDomain.add_AssemblyResolve (
System.ResolveEventHandler (fun _ args ->
let resolvedAssembly =
System.AppDomain.CurrentDomain.GetAssemblies ()
|> Array.tryFind (fun loadedAssembly ->
// If this assembly has the same name as the one we're looking for,
// assume it's correct and load it. NOTE : It may not be the _exact_
// assembly we're looking for -- then you'll need to adjust the critera below.
args.Name = loadedAssembly.FullName
|| args.Name = loadedAssembly.GetName().Name)
// Return null if the assembly couldn't be resolved.
defaultArg resolvedAssembly null))
If you add that code to a new F# console project, followed by the code which uses AssemblyName with Assembly.Load, you should be able to load the System assembly because it's referenced by default in an F# project and it'll be loaded when you run the project. If you try to resolve System.Drawing, it'll fail because our custom event handler can't find the assembly. Obviously, if you need some more complicated assembly-resolving logic, you should build that into the event handler in whatever way makes sense for your application.
Finally, here's a link to the MSDN whitepaper mentioned in the exception message: Best Practices for Assembly Loading. It's worth a read if you get stuck and can't figure out how to resolve the assemblies you need.

Getting Migrate.exe to work

I have been struggling on executing EF Migrate.exe to work.
My Solution has couple of projects. The migrations and the entities live in the project Data. The controllers and views live in Web.
I tried using the migrate.exe - however I am struggling getting the first argument (assembly) to be accepted. Documentations says:
Assembly: Specifies the name of the assembly that contains the
migrations configuration type.
I have tried:
migrate.exe "MySolution\DataProject\bin\Debug\Data.dll"
ERROR: Could not load file or assembly 'D:\\MySolution\\Data\\bin\\Debug\\Data' or one of its dep
endencies. The given assembly name or codebase was invalid. (Exception from HRES
ULT: 0x80131047)
Any idea what is going wrong?
After reading this, this, and this
I have (I think) what you need :
If you use migrate.exe against a .NET 4 assembly you NEED to rename the Redirect.config available in packages\EntityFramework.5.0.0\tools to migrate.exe.config and copy this to the SAME directory as migrate.exe. For running migrate.exe against a .NET 4.5 assembly you DO NOT NEED this copy, the migrate.exe.config must not exist.
The correct version of entity framework DLL must be in the SAME directory as migrate.exe. Correct version is packages\EntityFramework.5.0.0\lib\net40\ for running migrate.exe against a .NET 4 assembly. Correct version is packages\EntityFramework.5.0.0\lib\net45\ for running migrate.exe against a .NET 4.5 assembly
If you specify /StartUpDirectory= do not specify the path for /assembly example : C:\Tools\migrate.exe some.dll /StartUpDirectory=C:\Project\bin\.
If you don't specify a startup directory, then you need to specify the full path in the /assembly example : C:\Tools\migrate.exe C:\Project\bin\some.dll - In this scenario migrate.exe will not be able to load the some.dll's dependencies, unless you put all some.dll's dependencies and put it in the SAME directory as migrate.exe.
If you put the migrate.exe in the same path as your some.dll, then migrate.exe will be able to use the same EntityFramework.dll which your app uses, and can load all dependencies, and can load the some.dll without any path like C:\Tools\migrate.exe some.dll
If you put the migrate.exe in a separate tools folder like Im doing it needs the correct version of the EntityFramework.dll in the SAME directory as migrate.exe, it will need the /StartUpDirectory=<the path where you target dll is present> clause, and you should specify the name of the assembly without the path like : C:\Tools\migrate.exe some.dll /StartUpDirectory=C:\Project\bin\
Heres the powershell commmand I use :
$SolutionPath = (Resolve-Path '..').Path
$ToolsPath = "$SolutionPath\Build\Lib\"
task db {
$migrator = $ToolsPath + 'Migrations\migrate.exe'
$migrateCommand = "$migrator zasz_me.dll /StartUpDirectory=$SolutionPath\zasz.me\bin\ /connectionStringName:FullContext /startUpConfigurationFile:$SolutionPath\zasz.me\Web.config /verbose"
Write-Host $migrateCommand
Invoke-Expression $migrateCommand
}
I answered a similar question here on how to override connectionstring through parameters to migrate.exe. I have yet to get it working without specifying a web/app.config file.
https://stackoverflow.com/a/14138797/134761

Resources