I'm creating an ASP.NET MVC application using F# on IIS 7.
When I attempt to run it from the browser, I'm met with a YSOD containing the following:
[ArgumentNullException: Value cannot
be null. Parameter name: dictionary]
System.Collections.Generic.Dictionary2..ctor(IDictionary2
dictionary, IEqualityComparer`1
comparer) +12700827
System.Web.Compilation.CompilationUtil.CreateCodeDomProviderWithPropertyOptions(Type
codeDomProviderType) +84
System.Web.Compilation.CompilationUtil.CreateCodeDomProviderNonPublic(Type
codeDomProviderType) +16
System.Web.Compilation.AssemblyBuilder..ctor(CompilationSection
compConfig, ICollection
referencedAssemblies, CompilerType
compilerType, String
outputAssemblyName) +469
System.Web.Compilation.CompilerType.CreateAssemblyBuilder(CompilationSection
compConfig, ICollection
referencedAssemblies, String
generatedFilesDir, String
outputAssemblyName) +127
System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()
+675 System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
+46 System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean
isPrecompiledApp) +11321455
System.Web.Compilation.BuildManager.CompileGlobalAsax()
+50 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
+872
I looked up the method using Reflector to see if it could give me any more context and found that it was failing on the first line
private static CodeDomProvider CreateCodeDomProviderWithPropertyOptions(Type codeDomProviderType)
{
IDictionary<string, string> providerOptions = new Dictionary<string, string>(GetProviderOptions(codeDomProviderType));
//Snip
}
It leads me to believe that the propertyOptions I've specified in my Web.config for the F# CodeDom are incorrect. However, if I remove them I receive the same error.
<system.codedom>
<compilers>
<compiler language="F#;f#;fs;fsharp" extension=".fs" warningLevel="4"
type="Microsoft.FSharp.Compiler.CodeDom.FSharpAspNetCodeProvider,
FSharp.Compiler.CodeDom">
<providerOption name="CompilerVersion" value="v4.0"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
Any ideas on correcting this error?
It’s a bug in ASP.NET in VS2010 Beta2 (it has since been fixed, so will work in next release). It affects any 3rd party CodeDOM provider, and I don’t believe there is any workaround.
I found the cause to the problem.
The Microsoft.FSharp.Compiler.CodeDom.FSharpAspNetCodeProvider.FileExtension is hardcoded to "fs".
Inside of System.CodeDom.Compiler.CodeDomCompilationConfiguration..ctor() CompilerInfos are created for each of the allowed languages. A CompilerInfo for FSharp is not found within the creation of this.
internal CodeDomCompilationConfiguration()
{
this._compilerLanguages = new Hashtable(StringComparer.OrdinalIgnoreCase);
this._compilerExtensions = new Hashtable(StringComparer.OrdinalIgnoreCase);
this._allCompilerInfo = new ArrayList();
CompilerParameters compilerParams = new CompilerParameters();
compilerParams.WarningLevel = 4;
string codeDomProviderTypeName = "Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
CompilerInfo compilerInfo = new CompilerInfo(compilerParams, codeDomProviderTypeName);
compilerInfo._compilerLanguages = new string[] { "c#", "cs", "csharp" };
compilerInfo._compilerExtensions = new string[] { ".cs", "cs" };
compilerInfo._providerOptions = new Dictionary<string, string>();
compilerInfo._providerOptions["CompilerVersion"] = "v4.0";
this.AddCompilerInfo(compilerInfo);
compilerParams = new CompilerParameters();
compilerParams.WarningLevel = 4;
codeDomProviderTypeName = "Microsoft.VisualBasic.VBCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
compilerInfo = new CompilerInfo(compilerParams, codeDomProviderTypeName);
compilerInfo._compilerLanguages = new string[] { "vb", "vbs", "visualbasic", "vbscript" };
compilerInfo._compilerExtensions = new string[] { ".vb", "vb" };
compilerInfo._providerOptions = new Dictionary<string, string>();
compilerInfo._providerOptions["CompilerVersion"] = "v4.0";
this.AddCompilerInfo(compilerInfo);
//Snip
}
The FileExtension is compared against _compilerExtensions in System.CodeDom.Compiler.CodeDomProvider.GetCompilerInfoForExtensionNoThrow which (in the case of "fs") returns null to System.CodeDom.Compiler.CodeDomProvider.IsDefinedExtension which will then return false to System.Web.Compilation.CompilationUtil.GetProviderOptions that returns the null that was causing the ArgumentNullException.
Thanks for pointing me in the right direction, #Brian
Perhaps the bug Brian noted can be worked around by specifying some more info in web.config:
type="Microsoft.FSharp.Compiler.CodeDom.FSharpAspNetCodeProvider,
FSharp.Compiler.CodeDom,
Version=1.9.7.8,
Culture=neutral,
PublicKeyToken=a19089b1c74d0809"
Related
I am working with hello sign.
could you please figure out where the problem is. I have searched a lot but didn't find same.
[HttpPost]
public ActionResult SendDocument(SendDocumentForm Form)
{
if (!ModelState.IsValid)
{
SendDocumentFormViewModel model = new SendDocumentFormViewModel();
model.Form = Form;
return View(model);
}
var client = new Client(HelloSignAPIKey);
var request = new SignatureRequest();
request.Subject = Form.Subject;
request.Message = Form.Message;
request.AddSigner(Form.SignerEmail, Form.SignerName);
byte[] arreglo = new byte[Form.File.ContentLength];
Form.File.InputStream.Read(arreglo, 0, Form.File.ContentLength);
request.AddFile(arreglo, Form.File.FileName);
request.TestMode = true;
var response = client.CreateEmbeddedSignatureRequest(request, HelloSignClientID);
var urlSign = client.GetSignUrl(response.Signatures[0].SignatureId);
return RedirectToAction("Sign", new { url = urlSign.SignUrl });
}
Here is the error message
It looks like your unable to load the HelloSign C# SDK.
As far as your error:
Could not load type 'HelloSign.Client' from assembly 'HelloSign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
It looks like the SDK is not loading properly.
https://github.com/HelloFax/hellosign-dotnet-sdk
Try to make a direct RestSharp call to the HelloSign API
http://restsharp.org/
I am posting this here after exhausting out every possible solution that could resolve the issue I am facing with my custom implementation of Forms Authentication. To give you a background of what I did so far... I was trying to implement the accepted solution from the following thread.. ASP.NET MVC - Set custom IIdentity or IPrincipal
So, I changed my Web.Config to allow for forms authentication. This redirects the user to the login page when the first request comes in. This is how my Web.Config looks right now.
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="Forms">
<forms loginUrl="Account/login" timeout="30" slidingExpiration="true"></forms>
</authentication>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
In the controller after the user is validated...
Dim serializer = New JavaScriptSerializer()
Dim serializableModel = New With {
.SchoolYearId = _userModel.SchoolYearId,
.AccessLevel = _userModel.AccessLevel,
.UserId = _userModel.UserId,
.FirstName = _userModel.FirstName,
.LastName = _userModel.LastName,
.SchoolYear = _userModel.SchoolYear,
.Role = _userModel.Role
}
'.Identity = _userModel.Identity
Dim userData As String = serializer.Serialize(serializableModel)
Dim authenticationTicket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, _userModel.UserId, DateTime.Now, DateTime.Now.AddMinutes(15), False, userData)
Dim encTicket As String = Security.FormsAuthentication.Encrypt(authenticationTicket)
Dim faCookie As HttpCookie = New HttpCookie(Security.FormsAuthentication.FormsCookieName, encTicket)
Response.Cookies.Add(faCookie)
Return RedirectToAction("Add")
Now in the global.asax file, in the post authenticate section..
Dim authCookie As HttpCookie = Request.Cookies(System.Web.Security.FormsAuthentication.FormsCookieName)
If (Not IsNothing(authCookie)) Then
Dim authTicket As FormsAuthenticationTicket = System.Web.Security.FormsAuthentication.Decrypt(authCookie.Value)
Dim serializer = New JavaScriptSerializer()
Dim deSerializedModel = serializer.Deserialize(Of UserModel)(authTicket.UserData)
Dim userModel As IUserModel = New UserModel
userModel.SchoolYear = deSerializedModel.SchoolYear
userModel.SchoolYearId = deSerializedModel.SchoolYearId
userModel.AccessLevel = deSerializedModel.AccessLevel
userModel.UserId = deSerializedModel.UserId
userModel.FirstName = deSerializedModel.FirstName
userModel.LastName = deSerializedModel.LastName
userModel.SchoolYear = deSerializedModel.SchoolYear
userModel.Role = deSerializedModel.Role
HttpContext.Current.User = userModel
End If
So, once the user the authenticated, the code goes through the postauthenticaterequest block and right after it exits the postauthenticaterequest block, the following error pops up which has been driving me crazy.
http://imgur.com/a/XGMnb
I did go through some of the problems that other users faced but this is something I couldnt find much help on. How do I go about solving this? This happens locally and not the webserver.
I am consuming WCF Data Service as Following:
DataMan.ContextWrapper context = new DataMan.ContextWrapper(new Uri("http://localhost:2060/PCM/DataMan.svc/rest/"));
DataMan.Report newReport = DataMan.Report.CreateReport("123123123123", DateTime.Now, "999.199905171156550187000.25");
newReport.Title = "tt";
newReport.StudyAcDate = Convert.ToDateTime("2016-05-04 12:09:00");
newReport.Body = "asdasd";
newReport.Auther = "ali.h";
newReport.ApproverComment = "cm";
newReport.Approver = "admin";
context.AddToReports(newReport);
DataServiceResponse response = context.SaveChanges();
but after calling SaveChange() I have got the following error:
The server encountered an error processing the request. The exception message is 'Incoming message for operation 'ProcessRequestForMessage' (contract 'IRequestHandler' with namespace 'http://tempuri.org/') contains an unrecognized http body format value 'Xml'. The expected body format value is 'Raw'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.'. See server logs for more details.
and my WCF Data Service is as following:
public class ContextWrapper : DataAccessDbContext
{
public ContextWrapper() : base("connection string")
{
}
}
[JSONPSupportBehavior]
public class DataMan : EntityFrameworkDataService<ContextWrapper>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetEntitySetAccessRule("Studies", EntitySetRights.None);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.UseVerboseErrors = true; // TODO - Remove for production?
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
protected override void HandleException(HandleExceptionArgs args)
{
base.HandleException(args);
}
}
I also implemented and configured WebContentTypeMapper to bypass mentioned Error as following:
public class ContentTypeMapper : WebContentTypeMapper
{
public override WebContentFormat GetMessageFormatForContentType(string contentType)
{
return WebContentFormat.Raw;
}
}
Custom binding:
<binding name="XmlMapper">
<webMessageEncoding webContentTypeMapperType="MARCO.SOA.PCMServiceLib.ContentTypeMapper,MARCO.SOA.PCMServiceLib.Core"/>
<httpTransport manualAddressing="true"/>
</binding>
</customBinding>
Service endpoint:
<service behaviorConfiguration="Commom2.Behavior" name="MARCO.SOA.PCMServiceLib.DataMan">
<endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding"
bindingConfiguration="XmlMapper" contract="System.Data.Services.IRequestHandler">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:2060/PCM/DataMan.svc"/>
</baseAddresses>
</host>
</service>
but it still get exception, I think something went wrong with my configuration.
Any help would be truly appreciated.
Thanks in advance.
okay, after much trouble I finally solved the problem,
so we need to initiate factory property for serviceActivation
So my relative address was:
<serviceHostingEnvironment>
<serviceActivations>
.
.
.
<add relativeAddress="DataMan.svc" service="MARCO.SOA.PCMServiceLib.DataMan"/>
.
.
.
</serviceActivations>
</serviceHostingEnvironment>
and I have changed it to
<serviceHostingEnvironment>
<serviceActivations>
.
.
.
<add relativeAddress="DataMan.svc" service="MARCO.SOA.PCMServiceLib.DataMan" factory="System.Data.Services.DataServiceHostFactory, Microsoft.Data.Services, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
.
.
.
</serviceActivations>
</serviceHostingEnvironment>
now everything is now working nice.
more info about DataServiceHostFactory
Note:
By this we don't need to override GetMessageFormatForContentType of WebContentTypeMapper and force it to return WebContentFormat.Raw or another content format and don't need any customBinding in config file.
Thanks to all.
I am getting this error with SelectSingleNode method:
DNX Core 5.0 error CS1061: 'XmlDocument' does not contain a definition for 'SelectSingleNode' and no extension method 'SelectSingleNode' accepting a first argument of type 'XmlDocument' could be found (are you missing a using directive or an assembly reference?)
Is it not supported yet? What are my alternatives?
In .Net Core 1.0 and .Net Standard 1.3 SelectSingleNode is an extenstion method
https://github.com/dotnet/corefx/issues/17349
Add a reference to make it available again:
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
You need to use XDocument
const string xml = "<Misc><E_Mail>email#domain.xyz</E_Mail><Fax_Number>111-222-3333</Fax_Number></Misc>";
const string tagName = "E_Mail";
XDocument xDocument = XDocument.Parse(xml);
XElement xElement = xDocument.Descendants(tagName).FirstOrDefault();
if (xElement == null)
{
Console.WriteLine($"There is no tag with the given name '{tagName}'.");
}
else
{
Console.WriteLine(xElement.Value);
}
I have this problem too. To solve that, I'm using XDocument and so far so good.
Example:
XDocument xdoc = XDocument.Parse(xmlText);
var singleNode = xdoc.Element("someAttr");
var listOfNodes = singleNode.Elements("someAttrInnerText");
foreach (XElement e in listOfNodes)
{
string someAttr = e.Attribute("code").Value;
string someAttrInnerText = e.Value;
}
Don't forget to include "System.Xml.XDocument" inside your project.json.
I am trying to bind list collection to data-grid but its giving an error.
The type 'System.Data.Objects.ObjectContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Data Layer Code :
public class Employees
{
public List<Employee> LoadEmployees()
{
try
{
EMployeeDB1Entities EE = new EMployeeDB1Entities();
var Employees = EE.Employees.Where(p => p.Name.StartsWith("T"));
return Employees.ToList();
// var myCollection = new ObservableCollection<Employee>(this.LoadEmployees());
}
catch
{
return null;
}
}
UI Layer Code
private void button1_Click(object sender, EventArgs e)
{
Employees E1 = new Employees();
// error gives in below line.
dataGridView1.DataSource = E1.LoadEmployees();
}
Whats the solution ?
Thanks in advance...
The error clearly states that you are missing the reference of System.Data.Entity class in your project, you need to add it by the same simple process. Right click on add reference , then .Net tab and select System.Data.Entity from the list.
and you will be good to go.