WebAPI: Unable to load one or more of the requested types - c#

I'm developing an application using Silverlight. I've created WebAPI project in my solution:
BusinessApplication8
BusinessApplication8.Web
BusinessApplication8.WebAPI
First one is Silverlight project, second one contains my EDMX file. In my WebAPI project I'm using my DbContext like this:
public IEnumerable <object> Get()
{
var database = new DABIREntities();
var query = database.noe_nameh.Take(1).Select(item = > new {
Id = item.uid,
Description = item.sharh
}).ToList();
return query;
}
Everything works fine in local host and I get result in the browser. When I publish my WebAPI project and Call that GET method via URL I'm getting this error:
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
</ExceptionMessage>
<ExceptionType>System.Reflection.ReflectionTypeLoadException</ExceptionType>
<StackTrace>
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeModule.GetTypes() at System.Reflection.Assembly.GetTypes() at
System.Data.Metadata.Edm.ObjectItemAttributeAssemblyLoader.LoadTypesFromAssembly() at System.Data.Metadata.Edm.ObjectItemAssemblyLoader.Load() at
System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData) at
System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, KnownAssembliesSet knownAssemblies, EdmItemCollection
edmItemCollection, Action`1 logLoadMessage, Object& loaderCookie, Dictionary`2& typesInLoading, List`1& errors) at
System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies,
EdmItemCollection edmItemCollection, Action`1 logLoadMessage) at System.Data.Metadata.Edm.ObjectItemCollection.ImplicitLoadAssemblyForType(Type type, EdmItemCollection
edmItemCollection) at System.Data.Metadata.Edm.MetadataWorkspace.ImplicitLoadAssemblyForType(Type type, Assembly callingAssembly) at
System.Data.Objects.ObjectContext.GetTypeUsage(Type entityCLRType) at System.Data.Objects.ObjectContext.CreateObjectSet[TEntity](String entitySetName) at
BusinessApplication8.Web.DABIREntities.get_noe_nameh() at BusinessApplication8.WebAPI.Controllers.SearchController.Get() at lambda_method(Closure , Object , Object[] )
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters) at
System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken
cancellationToken) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at
System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at
System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
</StackTrace>
</Error>
Any Idea?

Finally I solved my problem. First of all I changed my API method to this:
public IEnumerable<object> Get()
{
try
{
var database = new DABIREntities();
var query = database.noe_nameh.Take(1).Select(item => new
{
Id = item.uid,
Description = item.sharh
}).ToList();
return query;
}
catch (ReflectionTypeLoadException exception)
{
return exception.LoaderExceptions.Select(item => item.Message).ToList();
}
}
That helped me to figure out my exact exceptions. We should set Copy to Local to below dll:
System.ServiceModel
System.ServiceModel.DomainServices.EntityFramework
System.ServiceModel.DomainServices.Hosting
System.ServiceModel.DomainServices.Server

Related

OpenSolutionAsync - Field not found: 'Microsoft.Build.Utilities.ChangeWaves.Wave16_8' on .NET Framework 4.8 / 4.7.2

This code works fine on .NET 6,
but when I want to run it on .NET Framework 4.8, then that's what I receive
System.MissingFieldException: Field not found: 'Microsoft.Build.Utilities.ChangeWaves.Wave16_8'.
at Microsoft.Build.Evaluation.Expander`2.IsTruncationEnabled(ExpanderOptions options)
at Microsoft.Build.Evaluation.Expander`2.PropertyExpander`1.ExpandPropertiesLeaveTypedAndEscaped(String expression, IPropertyProvider`1 properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties, IFileSystem fileSystem)
at Microsoft.Build.Evaluation.Expander`2.PropertyExpander`1.ExpandPropertiesLeaveEscaped(String expression, IPropertyProvider`1 properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties, IFileSystem fileSystem)
at Microsoft.Build.Evaluation.Expander`2.ExpandIntoStringLeaveEscaped(String expression, ExpanderOptions options, IElementLocation elementLocation)
at Microsoft.Build.Evaluation.ToolsetReader.ExpandPropertyUnescaped(ToolsetPropertyDefinition property, Expander`2 expander)
at Microsoft.Build.Evaluation.ToolsetReader.EvaluateAndSetProperty(ToolsetPropertyDefinition property, PropertyDictionary`1 properties, PropertyDictionary`1 globalProperties, PropertyDictionary`1 initialProperties, Boolean accumulateProperties, String& toolsPath, String& binPath, Expander`2& expander)
at Microsoft.Build.Evaluation.ToolsetReader.ReadToolset(ToolsetPropertyDefinition toolsVersion, PropertyDictionary`1 globalProperties, PropertyDictionary`1 initialProperties, Boolean accumulateProperties)
at Microsoft.Build.Evaluation.ToolsetReader.ReadEachToolset(Dictionary`2 toolsets, PropertyDictionary`1 globalProperties, PropertyDictionary`1 initialProperties, Boolean accumulateProperties)
at Microsoft.Build.Evaluation.ToolsetReader.ReadToolsets(Dictionary`2 toolsets, PropertyDictionary`1 globalProperties, PropertyDictionary`1 initialProperties, Boolean accumulateProperties, String& msBuildOverrideTasksPath, String& defaultOverrideToolsVersion)
at Microsoft.Build.Evaluation.ToolsetReader.ReadAllToolsets(Dictionary`2 toolsets, ToolsetRegistryReader registryReader, ToolsetConfigurationReader configurationReader, PropertyDictionary`1 environmentProperties, PropertyDictionary`1 globalProperties, ToolsetDefinitionLocations locations)
at Microsoft.Build.Evaluation.ProjectCollection.InitializeToolsetCollection(ToolsetRegistryReader registryReader, ToolsetConfigurationReader configReader)
at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary`2 globalProperties, IEnumerable`1 loggers, IEnumerable`1 remoteLoggers, ToolsetDefinitionLocations toolsetDefinitionLocations, Int32 maxNodeCount, Boolean onlyLogCriticalEvents, Boolean loadProjectsReadOnly)
at Microsoft.CodeAnalysis.MSBuild.Build.ProjectBuildManager.StartBatchBuild(IDictionary`2 globalProperties) at /_/src/Workspaces/Core/MSBuild/MSBuild/Build/ProjectBuildManager.cs:line 161
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.<LoadAsync>d__19.MoveNext() at /_/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs:line 134
--- End of the stack trace from the previous location where the exception occurred ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.<LoadSolutionInfoAsync>d__22.MoveNext() at /_/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.cs:line 218
--- End of the stack trace from the previous location where the exception occurred ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.<OpenSolutionAsync>d__24.MoveNext() at /_/src/Workspaces/Core/MSBuild/MSBuild/MSBuildWorkspace.cs:line 204
--- End of the stack trace from the previous location where the exception occurred ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
Here's the code
using System;
using System.Linq;
using Microsoft.CodeAnalysis;
using System.Threading.Tasks;
using Microsoft.Build.Locator;
using System.Collections.Generic;
using Microsoft.CodeAnalysis.MSBuild;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.IO;
...
MSBuildLocator.RegisterDefaults();
var msWorkspace = MSBuildWorkspace.Create();
var solution = await msWorkspace.OpenSolutionAsync(pathToSln); <--- fails here
...
Of course I have:
Here are my other nugets:
Does anyone have an idea what I may be missing?
I needed to add Microsoft.Build nuget

Ninject Serilization error when calling new StandardKernel

When I try to call
var ninjectKernel = new StandardKernel();
I get the below error. I can successfully use ninject with constructor injection. I only get this error when I try to grab a service by hand.
{"Message":"An error has occurred.","ExceptionMessage":"Type
'Ninject.Web.WebApi.NinjectDependencyResolver' in assembly
'Ninject.Web.WebApi, Version=3.3.1.0, Culture=neutral,
PublicKeyToken=c7192dc5380945e7' is not marked as
serializable.","ExceptionType":"System.Runtime.Serialization.SerializationException","StackTrace":"
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName,
String typeName)\r\n at
Ninject.Modules.AssemblyNameRetriever.GetAssemblyNames(IEnumerable1 filenames, Predicate1 filter)\r\n at
Ninject.Modules.CompiledModuleLoaderPlugin.LoadModules(IEnumerable1 filenames)\r\n at Ninject.Modules.ModuleLoader.LoadModules(IEnumerable1 patterns)\r\n
at Ninject.KernelBase.Load(IEnumerable1 filePatterns)\r\n at Ninject.KernelBase..ctor(IComponentContainer components, INinjectSettings settings, INinjectModule[] modules)\r\n at Ninject.KernelBase..ctor(INinjectModule[] modules)\r\n at Ninject.StandardKernel..ctor(INinjectModule[] modules)\r\n at Controllers.Controllers.TagController.GetTags(TagEnum tagType) in C:\\Users\\george\\Desktop\\NewScp\\SCP\\UI\\Controllers\\TagController.cs:line 39\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary2 arguments, CancellationToken
cancellationToken)\r\n--- End of stack trace from previous location
where exception was thrown ---\r\n at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)\r\n at
System.Web.Http.Controllers.ApiControllerActionInvoker.d__1.MoveNext()\r\n---
End of stack trace from previous location where exception was thrown
---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)\r\n at
System.Web.Http.Controllers.ActionFilterResult.d__5.MoveNext()\r\n---
End of stack trace from previous location where exception was thrown
---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)\r\n at
System.Web.Http.Dispatcher.HttpControllerDispatcher.d__15.MoveNext()"}

Xamarin Hot Reload not failed to initialize

After the last updates of Visual Studio version 16.9.x and update to Xamarin.Forms 5.0 Hot Reload not working.
This is the Output i get when starting the application:
Hot Reload IDE Extension Loaded
(FinansovoPregledi.Android) XAML Hot Reload is using 'changes only' mode
XAML Hot Reload initializing...
WARN: (FinansovoPregledi.Android) Unknown Breakpoint Hit: Android.Runtime.JNIEnv.RegisterJniNatives( typeName_ptr, int typeName_len, jniClass, methods_ptr, int methods_len)
ERROR: Caught exception in AgentStatusChangedHandler at 268: Xamarin.HotReload.EvaluatorException: Failed to Inject Assembly ---> Mono.Debugging.Evaluation.EvaluatorException: Method `Load' not found in type `System.Reflection.Assembly'.
at Mono.Debugging.Soft.SoftDebuggerAdaptor.OverloadResolveMulti(SoftEvaluationContext ctx, TypeMirror type, String methodName, ArgumentType[] genericTypeArgs, TypeMirror returnType, ArgumentType[] argTypes, List`1 candidates, Boolean throwIfNotFound, Boolean tryCasting) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2619
at Mono.Debugging.Soft.SoftDebuggerAdaptor.OverloadResolveMulti(SoftEvaluationContext ctx, TypeMirror type, String methodName, ArgumentType[] genericTypeArgs, TypeMirror returnType, ArgumentType[] argTypes, Boolean allowInstance, Boolean allowStatic, Boolean throwIfNotFound, Boolean tryCasting) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2511
at Mono.Debugging.Soft.SoftDebuggerAdaptor.RuntimeInvoke(EvaluationContext ctx, Object targetType, Object target, String methodName, Object[] genericTypeArgs, Object[] argTypes, Object[] argValues, Boolean enableOutArgs, Object[]& outArgs) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2304
at Mono.Debugging.Soft.SoftDebuggerAdaptor.RuntimeInvoke(EvaluationContext ctx, Object targetType, Object target, String methodName, Object[] genericTypeArgs, Object[] argTypes, Object[] argValues) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2281
at Xamarin.HotReload.HotReloadSharedBridge.InjectAndLoadAssembly(IProject project, SoftEvaluationContext context, String assemblyPath) in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadSharedBridge.cs:line 359
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
--- End of inner exception stack trace ---
at Xamarin.HotReload.HotReloadSharedBridge.InjectAndLoadAssembly(IProject project, SoftEvaluationContext context, String assemblyPath) in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadSharedBridge.cs:line 374
at Xamarin.HotReload.HotReloadBridge.<InitializeAgent>d__47.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 140
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Xamarin.HotReload.HotReloadBridge.<<Debugger_TargetHitBreakpoint>b__50_0>d.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 242
at Xamarin.HotReload.HotReloadSharedBridge.InjectAndLoadAssembly(IProject project, SoftEvaluationContext context, String assemblyPath) in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadSharedBridge.cs:line 374
at Xamarin.HotReload.HotReloadBridge.<InitializeAgent>d__47.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 140
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Xamarin.HotReload.HotReloadBridge.<<Debugger_TargetHitBreakpoint>b__50_0>d.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 242
XAML Hot Reload encountered a problem and failed to start. Use Help -> Report a Problem if the issues persists.
Stopping All Hot Reload sessions due to Failed ...
(FinansovoPregledi.Android) Stopping a Hot Reload session due to Failed ...
Stopped Hot Reload session.
ERROR: (FinansovoPregledi.Android) Caught exception in Debugger_TargetHitBreakpoint at 246: Xamarin.HotReload.EvaluatorException: Failed to Inject Assembly ---> Mono.Debugging.Evaluation.EvaluatorException: Method `Load' not found in type `System.Reflection.Assembly'.
at Mono.Debugging.Soft.SoftDebuggerAdaptor.OverloadResolveMulti(SoftEvaluationContext ctx, TypeMirror type, String methodName, ArgumentType[] genericTypeArgs, TypeMirror returnType, ArgumentType[] argTypes, List`1 candidates, Boolean throwIfNotFound, Boolean tryCasting) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2619
at Mono.Debugging.Soft.SoftDebuggerAdaptor.OverloadResolveMulti(SoftEvaluationContext ctx, TypeMirror type, String methodName, ArgumentType[] genericTypeArgs, TypeMirror returnType, ArgumentType[] argTypes, Boolean allowInstance, Boolean allowStatic, Boolean throwIfNotFound, Boolean tryCasting) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2511
at Mono.Debugging.Soft.SoftDebuggerAdaptor.RuntimeInvoke(EvaluationContext ctx, Object targetType, Object target, String methodName, Object[] genericTypeArgs, Object[] argTypes, Object[] argValues, Boolean enableOutArgs, Object[]& outArgs) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2304
at Mono.Debugging.Soft.SoftDebuggerAdaptor.RuntimeInvoke(EvaluationContext ctx, Object targetType, Object target, String methodName, Object[] genericTypeArgs, Object[] argTypes, Object[] argValues) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2281
at Xamarin.HotReload.HotReloadSharedBridge.InjectAndLoadAssembly(IProject project, SoftEvaluationContext context, String assemblyPath) in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadSharedBridge.cs:line 359
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
--- End of inner exception stack trace ---
at Xamarin.HotReload.HotReloadSharedBridge.InjectAndLoadAssembly(IProject project, SoftEvaluationContext context, String assemblyPath) in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadSharedBridge.cs:line 374
at Xamarin.HotReload.HotReloadBridge.<InitializeAgent>d__47.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 140
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Xamarin.HotReload.HotReloadBridge.<<Debugger_TargetHitBreakpoint>b__50_0>d.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 242
at Xamarin.HotReload.HotReloadSharedBridge.InjectAndLoadAssembly(IProject project, SoftEvaluationContext context, String assemblyPath) in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadSharedBridge.cs:line 374
at Xamarin.HotReload.HotReloadBridge.<InitializeAgent>d__47.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 140
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Xamarin.HotReload.HotReloadBridge.<<Debugger_TargetHitBreakpoint>b__50_0>d.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 242
Does anyone have a same problem? I tried everything for all platforms, also selecting to refresh the whole page but nothing fixed my problem. It's so hard without Hot Reload.
In your Android and iOS build settings, check that the Linker is set to "Don't Link" or "Link None".
More detailed info about XAML Hot Reload for Xamarin.Forms, you can take a look:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/xaml/hot-reload

ITfoxtec.Identity.Saml2 Invalid URI Issue

When i use <TargetFramework>net462</TargetFramework> for my Okta SAML implementation this throw a Invalid URL when it this new Saml2AuthnRequest(config); but on my first try using this code on netcoreapp3.1` this worked perfectly fine. Please let me know if i miss something thank you.
[HttpGet, AllowAnonymous]
public IActionResult Index(string returnUrl = null)
{
try
{
var config = GetSAMLConfig();
var binding = new Saml2RedirectBinding();
binding.SetRelayStateQuery(new Dictionary<string, string> { { relayStateReturnUrl, returnUrl ?? Url.Content("~/") } });
var request = new Saml2AuthnRequest(config);
return binding.Bind(request).ToActionResult();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
private Saml2Configuration GetSAMLConfig()
{
var config = new Saml2Configuration();
config.AllowedAudienceUris.Add("Okta_SAML_Example");
config.CertificateValidationMode = X509CertificateValidationMode.ChainTrust;
config.RevocationMode = X509RevocationMode.NoCheck;
var entityDescriptor = new EntityDescriptor();
entityDescriptor.ReadIdPSsoDescriptorFromUrl(new Uri("https://---------.okta.com/app/exk2b0b7dibno7rOB5d6/sso/saml/metadata"));
if (entityDescriptor.IdPSsoDescriptor != null)
{
config.SingleSignOnDestination = entityDescriptor.IdPSsoDescriptor.SingleSignOnServices.First().Location;
config.SignatureValidationCertificates.AddRange(entityDescriptor.IdPSsoDescriptor.SigningCertificates);
}
else
{
throw new Exception("IdPSsoDescriptor not loaded from metadata.");
}
return config;
}
Actual exception
System.UriFormatException: Invalid URI: The format of the URI could not be determined.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at ITfoxtec.Identity.Saml2.Configuration.Saml2IdentityConfiguration.GetAudienceRestriction(Boolean audienceRestricted, IEnumerable`1 allowedAudienceUris)
at ITfoxtec.Identity.Saml2.Configuration.Saml2IdentityConfiguration.GetIdentityConfiguration(Saml2Configuration config)
at ITfoxtec.Identity.Saml2.Saml2Request..ctor(Saml2Configuration config)
at ITfoxtec.Identity.Saml2.Saml2AuthnRequest..ctor(Saml2Configuration config)
at SAMLNet461.Controllers.HomeController.Index(String returnUrl) in D:\REPO\PELICAN\LOCAL\SAML.RND - CompanyAcccounts adjustment\SAML.Demo\SAMLNet461\Controllers\HomeController.cs:line 69
at lambda_method(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.<Invoke>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
The code looks correct.
Maybe it is a TLS version issue.
An alternative solution is to download the metadata in your code and add the metadata string to the ITfoxtec Identity SAML 2.0 library:
var idPMetadataXml = "... downloaded metadata ...";
var entityDescriptor = new EntityDescriptor();
entityDescriptorReadIdPSsoDescriptor(idPMetadataXml);
...
Updated:
The error seams to be in relation to Audience Restriction:
config.AllowedAudienceUris.Add("Okta_SAML_Example");
The audience have to be a URI in a .NET Framework application. Plain text strings are only supported in .NET Core and .NET 5.0.
.NET Framework sample: https://github.com/ITfoxtec/ITfoxtec.Identity.Saml2/tree/master/test/TestWebApp
I had the same issue and it was caused by "GetAudienceRestriction() method". Changing issuer name from "application-name" to "https://application-name" helped. Don't forget to change your name on your Identity Provider side (Okta, Ping Identity etc.) consistently. Now exception is not thrown anymore.

ASP.NET Core ViewComponent Invocation: InvalidCastException

Here is what I have
I have a view component as
public class TestViewComponent : ViewComponent
{
public async Task<IViewComponentResult> InvokeAsync(int param1, int param2)
{
return Content(param1.ToString() + param2);
}
}
And a controller as
public class HomeController : Controller
{
private Dictionary<string, object> _dict = new Dictionary<string, object>();
public IActionResult Index()
{
_dict = new Dictionary<string, object>() { ["param1"] = 100, ["param2"] = 200 };
return ViewComponent("Test", _dict)
}
public IActionResult Index1()
{
var obj = new { param1 = 100, param2 = 200 };
var objString = JsonConvert.SerializeObject(obj);
_dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(objString);
return ViewComponent("Test", _dict);
}
}
When I call the first Index action everything is good. It works as expected but when I call the Index1 action I get an error with the following stack trace
System.InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.Int32'.
at lambda_method(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.<InvokeAsyncCore>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.<InvokeAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentHelper.<InvokeCoreAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewComponentResultExecutor.<ExecuteAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeResultAsync>d__30.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResultFilterAsync>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResultExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__6.MoveNext()
It seems there is some issue after the Deserialization. The exception is thrown even before the InvokeAsync method of the view component is called.
I have been stuck on this for a while. Any help will be really appreciated.
Thanks.
The error message is pretty much telling what's happening here. The actual objects in the deserialized dictionary are Int64s, which the arguments expected by the ViewComponent are Int32 (also called int in C#).

Categories