GVKun编程网logo

c# – MVC将Base64 String转换为Image,但是…… System.FormatException

15

想了解c#–MVC将Base64String转换为Image,但是……System.FormatException的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于"xceptionin

想了解c# – MVC将Base64 String转换为Image,但是…… System.FormatException的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于"xception in thread "main" java.lang.NumberFormatException: For input string: "20、.Net 5 中的 ObjectDataProvider 抛出 System.BadImageFormatException、.net – CorFlags.exe,System.Data.SQLite.dll和BadImageFormatException、.net – 什么原因导致System.BadImageFormatException时构造System.Data.SQLite.SQLiteConnection的新知识。

本文目录一览:

c# – MVC将Base64 String转换为Image,但是…… System.FormatException

c# – MVC将Base64 String转换为Image,但是…… System.FormatException

我的控制器在此代码中的请求对象中获取上传的图像:
[HttpPost]
public string Upload()
{
    string fileName = Request.Form["FileName"];
    string description = Request.Form["Description"];
    string image = Request.Form["Image"];

    return fileName;
}

image的值(至少在它的开头)看起来很像这样:

data:image/jpeg;base64,/9j/4AAQSkZJRgABAgEAYABgAAD/7gAOQWRvYmUAZAAAAAAB/...

我尝试使用以下内容进行转换:

byte[] bImage = Convert.FromBase64String(image);

但是,这会产生System.FormatException:“输入不是有效的Base-64字符串,因为它包含非基本64个字符,两个以上的填充字符或填充字符中的非法字符.”

我觉得问题是至少字符串的开头不是base64,但对于我所知道的一切都不是.在解码之前我需要解析字符串吗?我错过了完全不同的东西吗?

解决方法

看起来你可能只能从头开始删除“data:image / jpeg; base64”部分.例如:
const string ExpectedImagePrefix = "data:image/jpeg;base64,";
...
if (image.StartsWith(ExpectedImagePrefix))
{
    string base64 = image.Substring(ExpectedImagePrefix.Length);
    byte[] data = Convert.FromBase64String(base64);
    // Use the data
}
else
{
    // Not in the expected format
}

当然你可能想要使这个特定于JPEG特定,但我会尝试这是第一次通过.

"xception in thread "main" java.lang.NumberFormatException: For input string: "20

spark.SparkContext: Registered listener com.cloudera.spark.lineage.ClouderaNavigatorListener
"xception in thread "main" java.lang.NumberFormatException: For input string: "20
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:492)
    at java.lang.Integer.valueOf(Integer.java:582)
    at com.xiaodao.spark.examples.ml.AdaoKMeanService.main(AdaoKMeanService.java:166)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:730)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
17/10/12 17:42:02 INFO spark.SparkContext: Invoking stop() from shutdown hook
17/10/12 17:42:02 INFO ui.SparkUI: Stopped Spark web UI at http://192.168.1.30:4041
17/10/12 17:42:02 INFO spark.MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped!
17/10/12 17:42:02 INFO storage.MemoryStore: MemoryStore cleared
 

.Net 5 中的 ObjectDataProvider 抛出 System.BadImageFormatException

.Net 5 中的 ObjectDataProvider 抛出 System.BadImageFormatException

如何解决.Net 5 中的 ObjectDataProvider 抛出 System.BadImageFormatException?

我正在尝试在 ObjectDataProvider 网络应用程序中使用 .Net-5。因此我需要使用 System.Windows.Data,它可以与 PresentationFramework.dll 一起使用。我将程序集包含在 NuGet (<packagereference Include="PresentationFramework" Version="4.6.0" />) 中。当我构建我的应用程序时,我已经收到以下警告:

warning NU1701: Package ''PresentationFramework 4.6.0'' was restored using ''.NETFramework,Version=v4.6.1,.NETFramework,Version=v4.6.2,Version=v4.7,Version=v4.7.1,Version=v4.7.2,Version=v4.8'' instead of the project target framework ''net5.0''. This package may not be fully compatible with your project.

然后,当我尝试使用 ObjectDataProvider 创建一个 ObjectDataProvider myODP = new ObjectDataProvider(); 对象时,我的应用程序崩溃了:

System.BadImageFormatException: Could not load file or assembly ''PresentationFramework,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35''. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (0x80131058)
      File name: ''PresentationFramework,PublicKeyToken=31bf3856ad364e35'' ---> System.BadImageFormatException: Cannot load a reference assembly for execution.

如果感兴趣,我正在 x64 系统上的 Linux docker 容器 (mcr.microsoft.com/dotnet/sdk:5.0-focal) 中运行我的应用程序。

从我的 Google 搜索中,我已经尝试删除 bin 文件夹并重新构建,但没有成功。
其他答案似乎表明 System.BadImageFormatException 表示引用了 x86 程序集,而我正在为 x64 构建。除了来自 NuGet 的版本,我似乎找不到任何其他版本的 PresentationFramework.dll
还是 ObjectDataProvider 只是 deprecated?

我的问题是:如何解决此问题并使 ObjectDataProvider.Net-5 中工作?
甚至可以在 PresentationFramework.dll 中使用 .Net-5 吗?
顺便说一句,我也尝试让它在 .Net-3.1 中工作,但也出现了同样的问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

.net – CorFlags.exe,System.Data.SQLite.dll和BadImageFormatException

.net – CorFlags.exe,System.Data.SQLite.dll和BadImageFormatException

从 http://sqlite.phxsoftware.com/对System.Data.sqlite.dll运行 CorFlags.exe会产生以下输出.

Version   : v2.0.50727
CLR Header: 2.5
PE        : PE32
CorFlags  : 24
ILONLY    : 0
32BIT     : 0
Signed    : 1

如您所见,未指定32BIT且PE等于PE32.根据Moving from 32-bit to 64-bit application development on .NET Framework,这意味着该组件是任何cpu.但是,使用64位应用程序中的程序集会导致错误:

System.BadImageFormatException: Could
not load file or assembly
‘System.Data.sqlite’ or one of its
dependencies. An attempt was made to
load a program with an incorrect
format. File name:
‘System.Data.sqlite’

如果CorFlags.exe报告任何cpu,为什么会发生异常?组件是否错误标记为32BIT:0?

我知道有一个64位版本也可用,我只是想知道导致错误的原因.

解决方法

您使用的System.Data.sqlite.dll文件是 mixed-mode assembly,这意味着它不是纯.NET代码(另请参阅“ILONLY:0”标志),它还包含非托管机器代码,不能是“任何”中央处理器”.因此,由于DLL包含32位本机代码,因此只能将其加载到32位进程中,否则会发生BadImageFormatException.

.net – 什么原因导致System.BadImageFormatException时构造System.Data.SQLite.SQLiteConnection

.net – 什么原因导致System.BadImageFormatException时构造System.Data.SQLite.SQLiteConnection

我已经破碎代码到尽可能小的语句:
Dim cn As System.Data.sqlite.sqliteConnection

当从WinForm应用程序调用代码时,我得到以下错误:

System.BadImageFormatException: Could
not load file or assembly
‘System.Data.sqlite,Version=1.0.65.0,
Culture=neutral,
PublicKeyToken=db937bc2d44ff139’ or
one of its dependencies. An attempt
was made to load a program with an
incorrect format. File name:
‘System.Data.sqlite,
PublicKeyToken=db937bc2d44ff139’

然而从MS单元测试I调用同一段代码没有得到错误,加上完整的代码集工作原理。

sqlLite包含非托管代码,您不能在64位操作系统上运行它,除非部署64位版本。快速修复:项目属性,构建选项卡,平台目标= x86。

关于c# – MVC将Base64 String转换为Image,但是…… System.FormatException的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于"xception in thread "main" java.lang.NumberFormatException: For input string: "20、.Net 5 中的 ObjectDataProvider 抛出 System.BadImageFormatException、.net – CorFlags.exe,System.Data.SQLite.dll和BadImageFormatException、.net – 什么原因导致System.BadImageFormatException时构造System.Data.SQLite.SQLiteConnection等相关知识的信息别忘了在本站进行查找喔。

本文标签: